2

I am reading a shapefile using org.geotols 9.4 and trying to get CRS code but org.opengis.referencing.crs.CoordinateReferenceSystem is null:

FileDataStore store = FileDataStoreFinder.getDataStore(shpFile);
CoordinateReferenceSystem crs = store.getFeatureSource().getSchema().getCoordinateReferenceSystem();
// crs is null

and parsing .prj throws an error:

  String wkt = new String(Files.readAllBytes(Paths.get(shpFile.getAbsolutePath().replace(".shp", ".prj"))));
  crs = CRS.parseWKT(wkt);
  // throws org.opengis.referencing.NoSuchIdentifierException: No transform for classification "Mercator_Auxiliary_Sphere"  

Projection file is:

PROJCS["WGS_1984_Web_Mercator_Auxiliary_Sphere",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Mercator_Auxiliary_Sphere"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",0.0],PARAMETER["Standard_Parallel_1",0.0],PARAMETER["Auxiliary_Sphere_Type",0.0],UNIT["Meter",1.0]]

I am looking for an answer to why geotools can not determine the CRS and for a solution to determine all CRS rather than a workaround with this particular projection/file.

1 Answer 1

4

The following code works for me:

    String wkt = "PROJCS[\"WGS_1984_Web_Mercator_Auxiliary_Sphere\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Mercator_Auxiliary_Sphere\"],PARAMETER[\"False_Easting\",0.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",0.0],PARAMETER[\"Standard_Parallel_1\",0.0],PARAMETER[\"Auxiliary_Sphere_Type\",0.0],UNIT[\"Meter\",1.0]]";
    CoordinateReferenceSystem crs = CRS.parseWKT(wkt);
    assert crs != null;
    Integer actualCode = CRS.lookupEpsgCode(crs, false);
    System.out.println(actualCode);

and provides the result 3857 which sounds about right as ESRI:102100 is deprecated.

Just in case it was an authority issue I tested with both gt-epsg-hsql and gt-epsg-wkt and both were fine.

2
  • Strange. I have both gt-epsg-hsql and gt-epsg-wkt in my classpath. Which version of geotools did you use? mine is 9.4
    – user435421
    Commented Sep 24 at 10:29
  • Well that might explain it - I'm using 31-SNAPSHOT but I'd recommend that use a recent stable on like - 31.3 and don't put both jars on your path one or the other
    – Ian Turton
    Commented Sep 24 at 11:01

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.