Conversion between different Map projections in Java
Asked Answered
B

3

7

In my GIS application the data are sometimes stored in "Google Mercator" (in meters), sometimes in WGS84 LatLon. I'd like a reliable library to convert this data easily and in a "scientific" way, rather than messing with it manually, risking big errors.

I've come across Proj4, which apparently is able to do this: http://trac.osgeo.org/proj

but I can't find a similar library for Java (or Groovy). Such a project would be highly beneficial, given that those projections are increasingly common in online applications. A little jar would be amazing :-)

There is a Java port, but there aren't any files to download: http://www.jhlabs.com/java/maps/proj/

Basically I need to do this type of conversion: http://proj4js.org

Any idea about how to do this in Java?

Thanks, Mulone

Bitty answered 21/1, 2011 at 13:6 Comment(1)
on the same page the author mentions the new location of the Java port: sourceforge.net/projects/jmapprojlibMetatarsal
K
5

Have a look at GeoTools. The bad thing is you don't get a little jar, but about a hundred.

This Tutorial might show something similiar to what you want to accomplish.

Kingly answered 21/1, 2011 at 13:12 Comment(3)
thanks, i was looking at GeoTools, but as you said it looks too big for what I need.Bitty
GeoTools is very modular, so you can just use the jars needed for the job.Kingly
Exactly. You should be able to import only that which you need.Auroora
V
0

Java port by JH Labs, now maintained by the Cartography and Geovisualization Group, Oregon State University is now on GitHub: https://github.com/OSUCartography/JMapProjLib

Vinegarroon answered 20/2, 2012 at 7:44 Comment(0)
C
0

I would also recommend GeoTools: look at the CRS class:

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

Using Maven:

    <dependency>
      <groupId>org.geotools</groupId>
      <artifactId>gt-api</artifactId>
      <version>8-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-referencing</artifactId>
        <version>8-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-epsg-hsql</artifactId>
        <version>8-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-epsg-extension</artifactId>
        <version>${version.geotools}</version>
    </dependency>

The gt-epsg-hsql basically included a HSQL database with a load of CRS definitions already loaded. However, you can also manually load definitions using WKT:

CRS.parseWKT( txt )

This means you can pop on over to http://spatialreference.org/, grab an OGC WKT definition and plumb it in.

Also, Proj4 does have JNI bindings if you fancy going that route.

Chinook answered 14/8, 2012 at 13:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.