Coordinate transform

大兔子大兔子 提交于 2019-12-06 12:21:57

问题


Do any open source or 'free' libraries exist for Java where i can perform coordinate transforms from one spatial system to another?

I found Opengeo http://opengeo.org/ but it's a huge and comprehensive library for all sorts of spatial things.

Does anything smaller exist? I need to convert from MGA56 to WGS84.


回答1:


A simple solution is PROJ.4, but it doesn't have Java bindings, so working with it might be a bit tricky. A more complete (but probably bigger than you want) solution would be GeoTools. But a quick search found the Java Map Projection Library, which appears to be a Java port of PROJ.4. I would give that a try.

Since it appears you need to do a datum shift, not only a projection, you will need to have some kind of coordinate system database. The easiest to get a hold of is the EPSG database -- PROJ.4 comes with an EPSG mapping file, which should be good enough for most purposes.

It looks like MGA56 is EPSG:28356, and of course WGS84 is EPSG:4326.




回答2:


There is a lightweight library written fully in Java.

Coordinate Transformation Suite (abridged CTS) is a library developed to perform coordinate transformations using well known geodetic algorithms and parameter sets.

CTS handles 4257 coordinate reference systems (3910 EPSG).

The source code of this project is located at:

https://github.com/irstv/CTS




回答3:


I've needed to convert back and forwards between WGS84 (the GPS projection) and EPSG 27700 (UK National Grid) and I've found the geotrellis library most accurate and usable. It's written in Scala but obviously you can use the library in Java. Here's the maven dependency I've used:

        <dependency>
            <groupId>org.locationtech.geotrellis</groupId>
            <artifactId>geotrellis-proj4_2.12</artifactId>
            <version>2.3.1</version>
        </dependency>

and this is some example code:

       CRS epsg27700 = CRS.fromEpsgCode(27700);
        CRS wgs84 = CRS.fromEpsgCode(4326);

        var toWgs84 = Transform.apply(epsg27700, wgs84);
        var fromWgs84 = Transform.apply(wgs84, epsg27700);

        Tuple2<Object, Object> southWestInWgs84 = toWgs84.apply(-90_619.29, 10_097.13);
        System.out.println("South-West corner in WGS 84: " + southWestInWgs84._1() + "," + southWestInWgs84._2());
        Tuple2<Object, Object> southWestBackToEpsg27700 = fromWgs84.apply(southWestInWgs84._1(), southWestInWgs84._2());
        System.out.println("South-West corner back to EPSG 27700: " + southWestBackToEpsg27700._1() + "," + southWestBackToEpsg27700._2());

which produces this output:

South-West corner in WGS 84: -8.820000046234389,49.7899999643445

South-West corner back to EPSG 27700: -90619.2888566542,10097.128186725415



来源:https://stackoverflow.com/questions/1676958/coordinate-transform

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!