1

I'm trying to define a custom projection by parsing a Wkt string. I mistakenly developed my test app against gt2-referencing, gt2-main and gt2-geometry from Maven and it worked. I believe the latest versions for these dependencies are from 2008(!).

When I switched to using version 17.0 of gt-referencing, gt-main and gt-geometry from Maven instead, I get an exception when I run my test app. The full exception text is:

    Apr 20, 2017 2:33:43 PM org.geotools.factory.FactoryRegistry scanForPlugins
WARNING: Can't load a service for category "MathTransformProvider". Cause is "ServiceConfigurationError: org.geotools.referencing.operation.MathTransformProvider: Provider org.geotools.referencing.operation.projection.AzimuthalEquidistant$Provider could not be instantiated".
java.util.ServiceConfigurationError: org.geotools.referencing.operation.MathTransformProvider: Provider org.geotools.referencing.operation.projection.AzimuthalEquidistant$Provider could not be instantiated
    at java.util.ServiceLoader.fail(ServiceLoader.java:232)
    at java.util.ServiceLoader.access$100(ServiceLoader.java:185)
    at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384)
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
    at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
    at org.geotools.factory.FactoryRegistry.register(FactoryRegistry.java:826)
    at org.geotools.factory.FactoryRegistry.scanForPlugins(FactoryRegistry.java:772)
    at org.geotools.factory.FactoryRegistry.scanForPluginsIfNeeded(FactoryRegistry.java:805)
    at org.geotools.factory.FactoryRegistry.getServiceProviders(FactoryRegistry.java:196)
    at org.geotools.referencing.operation.DefaultMathTransformFactory.getProvider(DefaultMathTransformFactory.java:282)
    at org.geotools.referencing.operation.DefaultMathTransformFactory.getDefaultParameters(DefaultMathTransformFactory.java:316)
    at org.geotools.referencing.wkt.Parser.parseProjection(Parser.java:603)
    at org.geotools.referencing.wkt.Parser.parseProjCS(Parser.java:917)
    at org.geotools.referencing.wkt.Parser.parseCoordinateReferenceSystem(Parser.java:225)
    at org.geotools.referencing.wkt.Parser.parseCoordinateReferenceSystem(Parser.java:204)
    at org.geotools.referencing.factory.ReferencingObjectFactory.createFromWKT(ReferencingObjectFactory.java:1090)
    at projection.TestCustomProjection.main(TestCustomProjection.java:64)
Caused by: java.lang.NoSuchFieldError: LONGITUDE_OF_CENTRE
    at org.geotools.referencing.operation.projection.AzimuthalEquidistant$Provider.<clinit>(AzimuthalEquidistant.java:432)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
    ... 14 more

I guess the key text here is:

Provider org.geotools.referencing.operation.projection.AzimuthalEquidistant$Provider could not be instantiated"

The code in question is pretty simple but I'll include it here for completeness:

CoordinateReferenceSystem targetCRS = targetCRS = factory.createFromWKT(s);

I'm not sure if I'm missing a dependency from Maven, but I don't think so as the AzimuthalEquidistant class is in the gt-referencing dependency.

The funny thing is, the code continues to run and successfully completes otherwise. The output is reported as a "WARNING" so I can probably ignore it. But I'm curious why the "warning" occurs, even though the code should be available in the compiled JAR.

I am adding my custom project string. This is an early test application so I'm ok with using hard coded values:

private static final String REFERENCE_SYSTEM = "PROJCS[\"WGS 84 / CYUL Local TM\"," + "  GEOGCS[\"WGS 84\","
        + "    DATUM[\"World Geodetic System 1984\","
        + "      SPHEROID[\"WGS 84\", 6378137.0, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]],"
        + "      AUTHORITY[\"EPSG\",\"6326\"]]," + "    PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]],"
        + "    UNIT[\"degree\", 0.017453292519943295]," + "    AXIS[\"Geodetic longitude\", EAST],"
        + "    AXIS[\"Geodetic latitude\", NORTH]," + "    AUTHORITY[\"EPSG\",\"4326\"]],"
        + "  PROJECTION[\"Transverse Mercator\", AUTHORITY[\"EPSG\",\"9807\"]],"
        + "  PARAMETER[\"central_meridian\", -73.736055]," + "  PARAMETER[\"longitude_of_origin\", -73.736055],"
        + "  PARAMETER[\"latitude_of_origin\", 45.470006667]," + "  PARAMETER[\"scale_factor\", 1.0],"
        + "  PARAMETER[\"false_easting\", 0.0]," + "  PARAMETER[\"false_northing\", 0.0]," + "  UNIT[\"m\", 1.0],"
        + "  AXIS[\"Easting\", EAST]," + "  AXIS[\"Northing\", NORTH]," + "  AUTHORITY[\"EPSG\",\"3997\"]]";

What may I have missed?

4
  • I think that your string (which it would be helpful to see) contains a parameter LONGITUDE_OF_CENTRE which GeoTools doesn't recognise
    – Ian Turton
    Commented Apr 21, 2017 at 9:42
  • I added the string as requested. @PolyGeo, why did you edit my post? Commented Apr 21, 2017 at 14:33
  • A key difference between a discussion forum and a Stack Exchange is its wiki style Q&A that encourages users to improve the posts of others. In this case my edit was to remove the thanks (we do that via voting) and to turn your last statement into a question to make clear what you are asking.
    – PolyGeo
    Commented Apr 21, 2017 at 18:46
  • Understood, obviously I'm still learning the Way-Of-The-Stack-Exchange. Commented Apr 21, 2017 at 19:52

1 Answer 1

2

I'm not sure what's happening here, I created the following:

import org.geotools.referencing.ReferencingFactoryFinder;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CRSFactory;
import org.opengis.referencing.crs.CoordinateReferenceSystem;

public class MakeProj {

  public static void main(String[] args) throws FactoryException {
    final String REFERENCE_SYSTEM = "PROJCS[\"WGS 84 / CYUL Local TM\"," + "  GEOGCS[\"WGS 84\","
        + "    DATUM[\"World Geodetic System 1984\","
        + "      SPHEROID[\"WGS 84\", 6378137.0, 298.257223563, AUTHORITY[\"EPSG\",\"7030\"]],"
        + "      AUTHORITY[\"EPSG\",\"6326\"]]," + "    PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]],"
        + "    UNIT[\"degree\", 0.017453292519943295]," + "    AXIS[\"Geodetic longitude\", EAST],"
        + "    AXIS[\"Geodetic latitude\", NORTH]," + "    AUTHORITY[\"EPSG\",\"4326\"]],"
        + "  PROJECTION[\"Transverse Mercator\", AUTHORITY[\"EPSG\",\"9807\"]],"
        + "  PARAMETER[\"central_meridian\", -73.736055]," + "  PARAMETER[\"longitude_of_origin\", -73.736055],"
        + "  PARAMETER[\"latitude_of_origin\", 45.470006667]," + "  PARAMETER[\"scale_factor\", 1.0],"
        + "  PARAMETER[\"false_easting\", 0.0]," + "  PARAMETER[\"false_northing\", 0.0]," + "  UNIT[\"m\", 1.0],"
        + "  AXIS[\"Easting\", EAST]," + "  AXIS[\"Northing\", NORTH]," + "  AUTHORITY[\"EPSG\",\"3997\"]]";

    CRSFactory factory = ReferencingFactoryFinder.getCRSFactory(null);
    CoordinateReferenceSystem targetCRS = factory.createFromWKT(REFERENCE_SYSTEM);
    System.out.println(targetCRS.toWKT());
  }

}

which produces this with no error or warning:

PROJCS["WGS 84 / CYUL Local TM", 
  GEOGCS["WGS 84", 
    DATUM["World Geodetic System 1984", 
      SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]], 
      AUTHORITY["EPSG","6326"]], 
    PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], 
    UNIT["degree", 0.017453292519943295], 
    AXIS["Geodetic longitude", EAST], 
    AXIS["Geodetic latitude", NORTH], 
    AUTHORITY["EPSG","4326"]], 
  PROJECTION["Transverse_Mercator"], 
  PARAMETER["central_meridian", -73.736055], 
  PARAMETER["latitude_of_origin", 45.47000666700001], 
  PARAMETER["scale_factor", 1.0], 
  PARAMETER["false_easting", 0.0], 
  PARAMETER["false_northing", 0.0], 
  UNIT["m", 1.0], 
  AXIS["Easting", EAST], 
  AXIS["Northing", NORTH], 
  AUTHORITY["EPSG","3997"]]

So without more code and the exact maven dependencies I can't reproduce the issue.

1
  • Ok, thanks, this is great. I'll have to inspect my Maven dependencies carefully as there may be something amiss in there. But that's a good catch. Commented Apr 21, 2017 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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