Thank you

After
using 
AbstractCRS.castOrCopy(...).forConvention(AxesConvention.DISPLAY_ORIENTED),
I was able to get consistent results

Here is the updated unit test

    @Test
    public void testWKT 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.83333333333333],"
                + "PARAMETER[\"central_meridian\",-99.0],"
                + "PARAMETER[\"standard_parallel_1\",28.383333333333],"
                + "PARAMETER[\"standard_parallel_2\",30.283333333333],"
                + "PARAMETER[\"false_easting\",2000000],"
                + "PARAMETER[\"false_northing\",0],"
                + "UNIT[\"US survey foot\",0.304800609601219],"
                + "AXIS[\"Y\",NORTH],"
                + "AXIS[\"X\",EAST]]";
        CoordinateReferenceSystem fromCrs = CRS.fromWKT(wkt);
        CoordinateReferenceSystem toCrs = CRS.forCode("EPSG:4326");
        CoordinateReferenceSystem displayOrientedFromCrs =
AbstractCRS.castOrCopy(fromCrs).forConvention(AxesConvention.DISPLAY_ORIENTED);
        CoordinateReferenceSystem displayOrientedToCrs =
AbstractCRS.castOrCopy(toCrs).forConvention(AxesConvention.DISPLAY_ORIENTED);
        double x = 1934615.424;
        double y = 506052.281;
        CoordinateOperation operation =
CRS.findOperation(displayOrientedFromCrs, displayOrientedToCrs,
ExtentUtil.getExtentFromAreaOfUse(displayOrientedFromCrs, x, y, x, y));
        DirectPosition position = new DirectPosition2D(x, y);
        double[] coordinate =
operation.getMathTransform().transform(position, position).getCoordinate();
        Assert.assertEquals(coordinate[0], -99.205, 0.001);
        Assert.assertEquals(coordinate[1], 29.225, 0.001);
    }

    public static DefaultGeographicBoundingBox
getExtentFromAreaOfUse(CoordinateReferenceSystem displayOrientedFromCrs,
            double minX, double minY, double maxX, double maxY) throws
Exception {
        CoordinateReferenceSystem toCrs = CRS.forCode("EPSG:4326");
        AbstractCRS displayOrientedToCrs =
AbstractCRS.castOrCopy(toCrs).forConvention(AxesConvention.DISPLAY_ORIENTED);
// longitude should be first
        CoordinateOperation operation =
CRS.findOperation(displayOrientedFromCrs, displayOrientedToCrs, null);
        MathTransform mt = operation.getMathTransform();
        DirectPosition topLeftPosition = new DirectPosition2D(minX, maxY);
        DirectPosition topRightPosition = new DirectPosition2D(maxX, maxY);
        DirectPosition bottomRightPosition = new DirectPosition2D(maxX,
minY);
        DirectPosition bottomLeftPosition = new DirectPosition2D(minX,
minY);
        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()[0],
bottomLeftLatLongPosition.getCoordinate()[0]);
        double eastBoundLongitude =
Math.max(topLeftLatLongPosition.getCoordinate()[0],
bottomLeftLatLongPosition.getCoordinate()[0]);
        double southBoundLatitude =
Math.min(topRightLatLongPosition.getCoordinate()[1],
bottomRightLatLongPosition.getCoordinate()[1]);
        double northBoundLatitude =
Math.max(topRightLatLongPosition.getCoordinate()[1],
bottomRightLatLongPosition.getCoordinate()[1]);
        return new DefaultGeographicBoundingBox(westBoundLongitude,
eastBoundLongitude, southBoundLatitude, northBoundLatitude);
    }



On Wed, Oct 23, 2019 at 3:02 AM Martin Desruisseaux <
[email protected]> wrote:

> Hello Thierry
>
> Le 23/10/2019 à 01:10, Thierry Danard a écrit :
>
> 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 (...snip...) 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.
>
> This is expected. The AXIS attributes that are swapped in the test are
> the axes of the source CRS ("fromCRS"). Those axes define the expected
> order of coordinates given to the "transform" methods. If the AXIS
> attributes of the source CRS are swapped, then the input coordinate values
> need to be swapped to. In the following part of the test:
>
> double y = 1934615.424;
> double x = 506052.281;
>
> Just rename "y" as "x" and "x" as "y", and we are back on the expected
> results.
>
>     Regards,
>
>         Martin
>
>
>

Reply via email to