proj4j icon indicating copy to clipboard operation
proj4j copied to clipboard

Support for constructing CRS from an OGC URN

Open securedimensions opened this issue 5 years ago • 1 comments

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)

securedimensions avatar Mar 16 '19 10:03 securedimensions

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.

echeipesh avatar Aug 22 '19 20:08 echeipesh