3

I need a way to find out the unit of an EPSG-Code (e.g: meter) from java (ogr, gdal, osgeo?) but any other approach would be fine as well. I want to do something like:

if(epsg.unit==meter){
   do this
} else {
   do that
}
Selphiron
  • 775
  • 2
  • 11
  • 29
  • Does this help? http://gis.stackexchange.com/questions/7608/shapefile-prj-to-postgis-srid-lookup-table – John Powell Feb 10 '15 at 09:34
  • how you do this is pretty dependent on the software package you are using, OGR will be different to GeoTools which is different to OpenJump etc. – Ian Turton Feb 10 '15 at 10:15
  • @JohnBarça thanks but there were a lot of things that I did not understand (since I am new to GIS) but I managed to solve my problem. – Selphiron Feb 10 '15 at 10:57
  • or you could try parsing the definition file for the EPSG code directly: http://www.opengis.net/def/crs/EPSG/0/27700 – nmtoken Mar 14 '16 at 19:56

2 Answers2

3

I used the ogr java bindings:

public static void unitOfCRS(){
        SpatialReference poSourceSRS = new SpatialReference();
        // output: metre
        poSourceSRS.ImportFromEPSG(3068);
        System.out.println(poSourceSRS.GetAttrValue("UNIT"));
        // output: degree
        poSourceSRS.ImportFromEPSG(4326);
        System.out.println(poSourceSRS.GetAttrValue("UNIT"));

    }
Selphiron
  • 775
  • 2
  • 11
  • 29
1

You could perhaps look into the PROJ4 library. There seems to be a Java binding, which you could use.

I am almost confident that I have done a similar task before, although with Python, but I cannot find my code to double check.

Either way, there should be a way to get a string which includes all the parameters of a specific coordinate system. You would then use that string to extract your units.

BritishSteel
  • 6,637
  • 4
  • 38
  • 64
  • thanks for the answer, that looks promising but the installation of the java binding together with the proj4 library was a little bit too much, I found out that I can solve my problem with the ogr java bindings (which I already have installed). – Selphiron Feb 10 '15 at 10:56