orbisgis / cts

Projection library in Java
GNU Lesser General Public License v3.0
50 stars 16 forks source link

Bug or misuse ? #97

Closed krooo closed 5 years ago

krooo commented 5 years ago

I'm discovering your library. But I have difficulty to use it. I'm also new to geodesic's subject.

I'm want to convert Lambert93 coordinates to WSG84. So I made the example below:

@Test
public void testLambertToWgs84() throws IllegalCoordinateException, CoordinateOperationException, CRSException {
    // Create a new CRSFactory, a necessary element to create a CRS without defining one by one all its components
    final CRSFactory cRSFactory = new CRSFactory();

    // Add the appropriate registry to the CRSFactory's registry manager. Here the EPSG registry is used.
    final RegistryManager registryManager = cRSFactory.getRegistryManager();
    registryManager.addRegistry(new EPSGRegistry());
    registryManager.addRegistry(new IGNFRegistry());

    // CTS will read the EPSG registry seeking the 4326 code (WGS84), when it finds it,
    // it will create a CoordinateReferenceSystem using the parameters found in the registry.
    final CoordinateReferenceSystem crsWgs84 = cRSFactory.getCRS("EPSG:4326");

    // RGF93 / Lambert-93
    final CoordinateReferenceSystem lambert = cRSFactory.getCRS("IGNF:LAMB93");

    final Set<CoordinateOperation> coordinateOperations = CoordinateOperationFactory.createCoordinateOperations((GeodeticCRS) lambert, (GeodeticCRS) crsWgs84);
    final Iterator<CoordinateOperation> iterator = coordinateOperations.iterator();
    final CoordinateOperation lambertTransfo1 = iterator.next();
    final CoordinateOperation lambertTransfo2 = iterator.next();

    // Note that we get a List and not a single CoordinateTransformation, because several methods may exist to
    // transform a position from crs1 to crs2

    // Caution, coordinates are modified by transform
    final double[] coord = new double[2];
    // French private school CHATEAUBRIAND in St Malo
    coord[0] = 7287371.01;
    coord[1] = 2560129;

    System.out.println(lambertTransfo1);
    lambertTransfo1.transform(coord);
    printAndValidate(coord);

    // French private school CHATEAUBRIAND in St Malo
    coord[0] = 7287371.01;
    coord[1] = 2560129;

    System.out.println(lambertTransfo2);
    lambertTransfo2.transform(coord);
    printAndValidate(coord);
}

private void printAndValidate(double[] coord) {
    System.out.println(coord[0]);
    System.out.println(coord[1]);
    Assert.assertEquals(48.6507649, coord[0], 0.001);
    Assert.assertEquals(-2.00555, coord[1], 0.001);
}

It give me the ouput below:

IGNF:LAMB93 to EPSG:4326 through Geographic Transformation from WGS 84 to WGS 84{ Lambert Conic Conformal (2SP) [lat0=46.5°;sp1=44.0°;sp2=49.0°;lon0=3.0°;x0=700000.0m;y0=6600000.0m] inverse [LOCAL_CoordinateOperation:22] Coordinates switch [LOCAL_CoordinateOperation:23] radian to degree } precision = 0.0 48.65099999471074 -2.0050000347712

IGNF:LAMB93 to EPSG:4326 through Geographic Transformation from UNKNOWN to WGS 84{ Lambert Conic Conformal (2SP) [lat0=46.5°;sp1=44.0°;sp2=49.0°;lon0=3.0°;x0=700000.0m;y0=6600000.0m] inverse [EPSG:9659i] Geographic 2D to 3D conversion Geographic to geocentric conversion (GRS 1980) Geocentric to geographic conversion (WGS 84) [EPSG:9659] Geographic 3D to 2D conversion [LOCAL_CoordinateOperation:22] Coordinates switch [LOCAL_CoordinateOperation:23] radian to degree } precision = 2.0E-4 -0.03499385210935824 0.8491201342954462

The first transformation is good for me, but the second provides a different result. Why ? How do I avoid this transformation ?

Futhermore, I have the following warnings:

11:23:13.082 [main] WARN org.cts.CRSHelper - A component has already been registered for key EPSG:9603. 11:23:13.082 [main] WARN org.cts.CRSHelper - A component has already been registered for key EPSG:9603. 11:23:13.082 [main] WARN org.cts.CRSHelper - A component has already been registered for key EPSG:1031. 11:23:13.082 [main] WARN org.cts.CRSHelper - A component has already been registered for key EPSG:1031. 11:23:13.098 [main] WARN org.cts.CRSHelper - A component has already been registered for key EPSG:9602. 11:23:13.098 [main] WARN org.cts.CRSHelper - A component has already been registered for key EPSG:9601. 11:23:13.098 [main] WARN org.cts.CRSHelper - A component has already been registered for key EPSG:9601. 11:23:13.098 [main] WARN org.cts.CRSHelper - A component has already been registered for key EPSG:9602.

I'm using cts-1.5.1

ebocher commented 5 years ago

Thanks we will look on it asap

ebocher commented 5 years ago

I m not able to understand your problem. So please have a look on this test https://github.com/orbisgis/cts/blob/332fe9c10fb9d47c49a05518bac82307052c69fa/src/test/java/org/cts/op/BatchCoordinateTransformTest.java You will find all the material to test several transformations.