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
}
  • Does this help? gis.stackexchange.com/questions/7608/… – John Powell Feb 10 '15 at 9: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: opengis.net/def/crs/EPSG/0/27700 – nmtoken Mar 14 '16 at 19:56
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"));

    }
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.

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.