Hello,
I noticed a surprising behavior, I do not know whether this is a bug, or
whether it's expected: I found that when the order of the AXIS attributes
is changed, the conversion returns different results
I have the unit test below performing a sample conversion, and getting the
right result
(longitude=-99.20531579390813
latitude=29.225237498621965)
private DefaultGeographicBoundingBox
getExtentFromAreaOfUse(CoordinateReferenceSystem fromCrs,
CoordinateReferenceSystem toCrs,
double minX, double minY, double maxX, double maxY) throws
Exception {
CoordinateOperation operation = CRS.findOperation(fromCrs, toCrs,
null);
MathTransform mt = operation.getMathTransform();
DirectPosition topLeftPosition = new DirectPosition2D(maxY, minX);
DirectPosition topRightPosition = new DirectPosition2D(maxY, maxX);
DirectPosition bottomRightPosition = new DirectPosition2D(minY,
maxX);
DirectPosition bottomLeftPosition = new DirectPosition2D(minY,
minX);
DirectPosition topLeftLatLongPosition =
mt.transform(topLeftPosition, topLeftPosition);
DirectPosition topRightLatLongPosition =
mt.transform(topRightPosition, topRightPosition);
DirectPosition bottomLeftLatLongPosition =
mt.transform(bottomLeftPosition, bottomLeftPosition);
DirectPosition bottomRightLatLongPosition =
mt.transform(bottomRightPosition, bottomRightPosition);
double westBoundLongitude =
Math.min(topLeftLatLongPosition.getCoordinate()[1],
bottomLeftLatLongPosition.getCoordinate()[1]);
double eastBoundLongitude =
Math.max(topLeftLatLongPosition.getCoordinate()[1],
bottomLeftLatLongPosition.getCoordinate()[1]);
double southBoundLatitude =
Math.min(topRightLatLongPosition.getCoordinate()[0],
bottomRightLatLongPosition.getCoordinate()[0]);
double northBoundLatitude =
Math.max(topRightLatLongPosition.getCoordinate()[0],
bottomRightLatLongPosition.getCoordinate()[0]);
return new DefaultGeographicBoundingBox(westBoundLongitude,
eastBoundLongitude, southBoundLatitude, northBoundLatitude);
}
@Test
public void testWKTGitHub() throws FactoryException, Exception {
String wkt = "PROJCS[\"NAD27 / Texas South Central\","
+ "GEOGCS[\"NAD27\","
+ "DATUM[\"North American Datum 1927\","
+ "SPHEROID[\"Clarke 1866\", 6378206.4, 294.97869821]],"
+ "UNIT[\"degree\", 0.0174532925199433],"
+ "AXIS[\"Lat\", NORTH],"
+ "AXIS[\"Long\", EAST]],"
+ "PROJECTION[\"Lambert_Conformal_Conic_2SP\"],"
+ "PARAMETER[\"latitude_of_origin\", 27.833333333333332],"
+ "PARAMETER[\"central_meridian\", -99.0],"
+ "PARAMETER[\"standard_parallel_1\", 28.383333333333333],"
+ "PARAMETER[\"standard_parallel_2\", 30.28333333333333],"
+ "PARAMETER[\"false_easting\", 2000000.0],"
+ "PARAMETER[\"false_northing\", 0.0],"
+ "UNIT[\"US survey foot\", 0.30480060960121924],"
+ "AXIS[\"X\", EAST],"
+ "AXIS[\"Y\", NORTH]]";
CoordinateReferenceSystem fromCrs = CRS.fromWKT(wkt);
CoordinateReferenceSystem toCrs = CRS.forCode("EPSG:4326");
double x = 1934615.424;
double y = 506052.281;
CoordinateOperation operation = CRS.findOperation(fromCrs, toCrs,
getExtentFromAreaOfUse(fromCrs, toCrs, x, y, x, y));
DirectPosition position = new DirectPosition2D(x, y);
double[] coordinate =
operation.getMathTransform().transform(position, position).getCoordinate();
System.out.println("longitude=" + coordinate[1]);
System.out.println("latitude=" + coordinate[0]);
}
If I change the WKT from
+ "AXIS[\"X\", EAST],"
+ "AXIS[\"Y\", NORTH]]";
to
+ "AXIS[\"Y\",NORTH],"
+ "AXIS[\"X\",EAST]]";
I get a different, incorrect result:
(longitude=-103.86819946668828
latitude=33.06508313602342)
Is this an expected behavior (the WKT string does not meet the specs?), or
is it a defect ?
-Thierry