locationtech / proj4j

Java port of the Proj.4 library for coordinate reprojection
Other
184 stars 73 forks source link

Support for constructing CRS from an OGC URN #23

Open securedimensions opened 5 years ago

securedimensions commented 5 years ago

The recognition of CRS identifiers starting with "urn:" fail. What do I need to do to get support for URN based CRS identifiers?

This example program - using proj4j from maven (org.locationtech.proj4j / proj4j / 1.0.0) - illustrates the problem for use of CRS = urn:ogc:def:crs:EPSG::4326:

import org.locationtech.proj4j.CRSFactory;
import org.locationtech.proj4j.CoordinateReferenceSystem;
import org.locationtech.proj4j.CoordinateTransform;
import org.locationtech.proj4j.CoordinateTransformFactory;
import org.locationtech.proj4j.ProjCoordinate;

public class Test {

    public static void main(String[] args) {

        testExplicitTransform();

    }

       public static void testExplicitTransform() {
            String csName1 = "EPSG:32636";
            String csName2 = "urn:ogc:def:crs:EPSG::4326";

            CoordinateTransformFactory ctFactory = new CoordinateTransformFactory();
            CRSFactory csFactory = new CRSFactory();

            CoordinateReferenceSystem crs1 = csFactory.createFromName(csName1);
            CoordinateReferenceSystem crs2 = csFactory.createFromName(csName2);

            System.out.println(csName1 + " unit: " + crs1.getProjection().getUnits());
            System.out.println(csName2 + " unit: " + crs2.getProjection().getUnits());

            CoordinateTransform trans = ctFactory.createTransform(crs1, crs2);

            ProjCoordinate p1 = new ProjCoordinate();
            ProjCoordinate p2 = new ProjCoordinate();
            p1.x = 500000;
            p1.y = 4649776.22482;

            /*
             * Transform point
             */
            ProjCoordinate px = trans.transform(p1, p2);
            System.out.println(px.toString());
    }

}

The program ends with this exception:

Exception in thread "main" java.lang.IllegalStateException: Unable to access CRS file: proj4/nad/urn
    at org.locationtech.proj4j.io.Proj4FileReader.readParametersFromFile(Proj4FileReader.java:41)
    at org.locationtech.proj4j.io.Proj4FileReader.getParameters(Proj4FileReader.java:151)
    at org.locationtech.proj4j.CRSFactory.createFromName(CRSFactory.java:82)
    at de.securedimensions.crs.Test.testExplicitTransform(Test.java:25)
    at de.securedimensions.crs.Test.main(Test.java:13)
echeipesh commented 5 years ago

This project is not able to parse OGC URNs for projections, this would have to be a feature that is added. Indeed only a single version of EPSG database is available at a time.

It looks like the source PROJ project now supports this feature though and it would be a good idea to consider this as part of other upstream ports.

Renaming the issue to better reflect the fact this is a feature request and not a bug.