开发者

Coordinate transform

Do any open source or 'free' libraries exist for Java where i can perform coord开发者_如何学JAVAinate 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.


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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜