1

Let's say I want to convert the following WGS84 (EPSG:4326) coordinate to UTM32N (EPSG:25832):

54.321, 9.876

Is there any tool to reproject x,y coordinates, apart from Proj4? links to the CTS wiki. The CTS wiki has a rough outline at https://github.com/orbisgis/cts/wiki

So, according to the wiki it would be something like this:

double[] coord = new double[2];
coord[0] = 54.321;
coord[1] = 9.876;

CRSFactory cRSFactory = new CRSFactory();
CoordinateReferenceSystem crs1 = cRSFactory.getCRS("EPSG:4326");
CoordinateReferenceSystem crs2 = cRSFactory.getCRS("EPSG:25832");
GeodeticCRS sourceGCRS = (GeodeticCRS) sourceCRS;
GeodeticCRS targetGCRS = (GeodeticCRS) targetCRS;
List<CoordinateOperation> coordOps = CoordinateOperationFactory.createCoordinateOperations(sourceGCRS, targetGCRS);

if (coordOps.size() != 0) {
    for (CoordinateOperation op : coordOps) {
        double[] dd  = op.transform(coord);
        for (int i = 0; i < dd.length; i++) {
            System.out.println(dd[i]); // for debugging
        }
    }
}

But this leaves me with

Exception in thread "main" org.cts.crs.CRSException: Cannot create the CRS
    at org.cts.CRSFactory.getCRS(CRSFactory.java:109)
    at my.package.CTSCoordinateTransformation.main(CTSCoordinateTransformation.java:34)
Caused by: org.cts.registry.RegistryException: This registry EPSG is not supported
    at org.cts.CRSFactory.isRegistrySupported(CRSFactory.java:149)
    at org.cts.CRSFactory.getCRS(CRSFactory.java:97)
    ... 1 more

Trying to find valid codes I used

CRSFactory crsFactory = new CRSFactory();
System.out.println(crsFactory.getSupportedCodes("EPSG"));

but that gave me

Exception in thread "main" java.lang.NullPointerException
    at org.cts.CRSFactory.getSupportedCodes(CRSFactory.java:227)
    at my.package.CTSCoordinateTransformation.main(CTSCoordinateTransformation.java:33)

org/cts/registry/epsg exists within the jar.

I also filed this as issue at https://github.com/orbisgis/cts/issues/65

PS: I can transform if I create the CRS from PRJ strings first but that is not an option for me, I want to be able to use EPSG codes.

  • I think this is still being developed, possibly? I tried to check in on the project, but there's a lot of French going on. There are definitely some empty methods, so I wouldn't count on this fully working. – Mintx Jun 19 '15 at 13:43
  • OpenJUMP Plus snapshots come with CTS plugin. Perhaps that and the source code could help you. – user30184 Jun 19 '15 at 13:45
  • I grabbed the jars from the Maven repository. It seems like they renamed CoordinateTransformationFactory to CoordinateOperationFactory. I will update my question in a moment, as it is now erroring on "This registry EPSG is not supported". – bugmenot123 Jun 19 '15 at 13:57
  • It works pretty well in OpenJUMP so it must be doable. – user30184 Jun 19 '15 at 14:04
  • There is also a Java port of Proj4: Proj4J – Wernfried Domscheit Jun 19 '15 at 15:10
1

The CTS wiki https://github.com/orbisgis/cts/wiki/Create-a-new-CoordinateReferenceSystem-from-a-reference-code has been updated to include a full example now. The adding of the appropriate registry was missing from it previously.

After creating the CRSFactory instance, the appropriate registry has to be added to its registry manager. In this case I wanted to use EPSG codes, so I need to add the EPSGRegistry. Full example:

CRSFactory cRSFactory = new CRSFactory();
RegistryManager registryManager = cRSFactory.getRegistryManager();
registryManager.addRegistry(new EPSGRegistry());
CoordinateReferenceSystem crs1 = cRSFactory.getCRS("EPSG:4326");

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.