1

none of these two unit tests runs fine but they both were supposed to.

public class CompareCrses extends TransformationTest {

  @Test
  public void comparingCrses() throws Exception {
    CoordinateReferenceSystem expectedCrs = CRS.decode("EPSG:32632");
    CoordinateReferenceSystem actualCrs = getEPSG32632ShapeValidFeatures().getSchema()
    .getCoordinateReferenceSystem();
    Assert.assertEquals(expectedCrs, actualCrs);
    // this one won't compile
//  Assert.assertTrue(expectedCrs.equals(actualCrs, false));
  }

  @Test
  public void comparingCrsesByTheirNames() throws Exception {
    CoordinateReferenceSystem expectedCrs = CRS.decode("EPSG:32632");
    CoordinateReferenceSystem actualCrs = getEPSG32632ShapeValidFeatures().getSchema()
    .getCoordinateReferenceSystem();
    Assert.assertEquals(expectedCrs.getName(), actualCrs.getName());
  }
}

I read how to compare crses but I did not found a solution. Variables differs but I don't get why. What am I missing? I am using geotools version 17.2. You can find the shape I use in the tests here.

  • Can you add the contents of the prj file to the question – Ian Turton Oct 20 '17 at 16:53
0

Those documents are out of date, the correct way to compare two CRS is to use

CRS.equalsIgnoreMetadata(expectedCrs, actualCrs)

But the notes at the end are still relevant:

The name is usually ignored, with only 2 exceptions:

Datum - The reason that we cannot ignore the name for a Datum is that it is the only way to differentiate between datum. We can have many datum using the same Ellipsoid and PrimeMeridian, and still be different datum (because AbstractDatum do not stores all the geodesy work behind the datum definition - it would be complex and out of ISO 19111 scope anyway).

In order to still allow a relaxed check we make use of a DatumAlias class, which help the referencing engine to recognise for example that “WGS84” and “D_WGS84” are synonymous.

CoordinateSystemAxis - CoordinateSystemAxis is clearly defined by ISO19111, but some variation is still seen in the wild. The DefaultCoordinateSystemAxis implementation handles a couple of alias as well (much less than Datum however).

We have be unable to define an alias for “x” and “y” up to date, because “x” (for example) can means too many different things: “Easting” in a map projection, “Geocentric X” in a GeocentricCRS, “Column” in an ImageCRS, etc...

In your case, while a human can see the two CRS match a machine can't as the differences are just too much, especially in the Datum and Axis names.

GeoTools:

PROJCS["WGS 84 / UTM zone 32N", 
  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 latitude", NORTH], 
    AXIS["Geodetic longitude", EAST], 
    AUTHORITY["EPSG","4326"]], 
  PROJECTION["Transverse_Mercator", AUTHORITY["EPSG","9807"]], 
  PARAMETER["central_meridian", 9.0], 
  PARAMETER["latitude_of_origin", 0.0], 
  PARAMETER["scale_factor", 0.9996], 
  PARAMETER["false_easting", 500000.0], 
  PARAMETER["false_northing", 0.0], 
  UNIT["m", 1.0], 
  AXIS["Easting", EAST], 
  AXIS["Northing", NORTH], 
  AUTHORITY["EPSG","32632"]]

ShapeFile

PROJCS["WGS_1984_UTM_Zone_32N", 
  GEOGCS["GCS_WGS_1984", 
    DATUM["D_WGS_1984", 
      SPHEROID["WGS_1984", 6378137.0, 298.257223563]], 
    PRIMEM["Greenwich", 0.0], 
    UNIT["degree", 0.017453292519943295], 
    AXIS["Longitude", EAST], 
    AXIS["Latitude", NORTH]], 
  PROJECTION["Transverse_Mercator"], 
  PARAMETER["central_meridian", 9.0], 
  PARAMETER["latitude_of_origin", 0.0], 
  PARAMETER["scale_factor", 0.9996], 
  PARAMETER["false_easting", 500000.0], 
  PARAMETER["false_northing", 0.0], 
  UNIT["m", 1.0], 
  AXIS["x", EAST], 
  AXIS["y", NORTH]]

I'm not entirely clear as to why you need to compare CRS anyway, in general you can just take the CRS provided by the data store and work with that. If you have to have all of your results in a certain CRS just reproject to that anyway, if the projections are mathematically identical the transform will make no difference and if they are different then the output will be correct.

  • I compare crses to check if I have to perform a reprojection or not. If desired crs match the shapefile crs I won't reproject the features. – Francesco Oct 21 '17 at 21:14

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.