GeoTools:从LAT / LNG转换为Albers

时间:2015-01-16 11:55:37

标签: java coordinate-systems geotools

我需要将GPS坐标(纬度和经度)转换为Albers等面积投影。有人可以帮我使用GeoTools Java Library进行转换吗?

我找不到任何帮助我这样做的示例或文档。我正在尝试做类似的事情:

    // set a global hint to force GeoTools to use x/y order (longitute first)
    System.setProperty("org.geotools.referencing.forceXY", "true");

    double lat = 43.96499314;
    double lng = 2.33656753;

    // FACTORIES
    Hints hints = new Hints(Hints.CRS, DefaultGeographicCRS.WGS84);
    PositionFactory positionFactory = GeometryFactoryFinder.getPositionFactory(hints);
    GeometryFactory geometryFactory = GeometryFactoryFinder.getGeometryFactory(hints);
    PrimitiveFactory primitiveFactory = GeometryFactoryFinder.getPrimitiveFactory(hints);
    AggregateFactory aggregateFactory = GeometryFactoryFinder.getAggregateFactory(hints);

    // POINTS
    WKTParser parser = new WKTParser(geometryFactory, primitiveFactory, positionFactory, aggregateFactory);
    Point point = (Point) parser.parse("POINT(" + lng + " " + lat + ")");

    CRSAuthorityFactory factory = CRS.getAuthorityFactory(true);
    CoordinateReferenceSystem latLngCRS = DefaultGeographicCRS.WGS84;
    CoordinateReferenceSystem albersCRS = factory.createCoordinateReferenceSystem("EPSG:3005");

    MathTransform transform = CRS.findMathTransform(latLngCRS, albersCRS, false);
    DirectPosition latLngDirectPosition = point.getDirectPosition();
    DirectPosition albersDirectPosition = transform.transform(latLngDirectPosition, null);

    System.out.println("latLngDirectPosition: " + Arrays.toString(latLngDirectPosition.getCoordinate()));
    System.out.println("albersDirectPosition: " + Arrays.toString(albersDirectPosition.getCoordinate()));

我得到了改造,但不知道它是否正确。

获得的值是: Lng / Lat [-124.453125,54.140625] => Albers [1100811.6154403698,1016407.2018336256]

任何人都可以帮助我吗? 谢谢!

1 个答案:

答案 0 :(得分:1)

查看:http://docs.geotools.org/latest/userguide/library/referencing/crs.html

在"查找数学变换"部分中,有一个涉及Albers_Conic_Equal_Area投影的示例。

您可以使用外部工具的其他输出来检查您的计算是否正确。您可以通过移动地图在线使用以下内容: http://spatialreference.org/ref/epsg/nad83-bc-albers/