orbisgis / cts

Projection library in Java
GNU Lesser General Public License v3.0
50 stars 16 forks source link

How to actually use the CRS registry? #65

Closed fnorf closed 9 years ago

fnorf commented 9 years ago

I use 1.3.3 from the Maven repository. I tried creating a CoordinateReferenceSystem with CRSFactory#getCRS:

CoordinateReferenceSystem sourceCRS = crsFactory.getCRS("EPSG:4326");

which gave me

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

So I tried to debug

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)

CRSFactory#createFromPrj works fine.

nicolas-f commented 9 years ago

Hi,

You need to feed the RegistryManager with registry:

        CRSFactory cRSFactory = new CRSFactory();
        RegistryManager registryManager = cRSFactory.getRegistryManager();
        registryManager.addRegistry(new IGNFRegistry());
        registryManager.addRegistry(new EPSGRegistry());
        registryManager.addRegistry(new ESRIRegistry());
        registryManager.addRegistry(new Nad27Registry());
        registryManager.addRegistry(new Nad83Registry());
        registryManager.addRegistry(new worldRegistry());

This part is missing in first wiki sample.

fnorf commented 9 years ago

Thanks! I added it to the wiki page.