OSGeo / PROJ

PROJ - Cartographic Projections and Coordinate Transformations Library
https://proj.org
Other
1.76k stars 790 forks source link

Conversion Issue between WGS84-4326 to NAD27-3069 #1350

Closed HaotianShi closed 5 years ago

HaotianShi commented 5 years ago

We encountered a conversion issue from WGS84-4326 to NAD27-3069 while doing a project.

We used two ways for projection based on the same longitude and latitude: A: ESRI ArcMap Projection (using ArcGIS Project tool) B: Proj4j javacode EPSG geoCode

However, there are some differences between the data (projected x and y of NAD27-3069) obtained by the two methods, which is not reasonable. The x coordinate difference of the same point is around 7-10 meters and the difference of y is about 1-2m, as shown in the table below.

LON |LAT | A.NAD27_X | B.NAD27_X | A.NAD27_Y | B. NAD27_Y -88.5228 | 42.57655 | 621238.4835 | 621229.7628 | 214633.296 | 214635.8638 -92.2959 | 44.53028 | 317580.3702 | 317565.4482 | 433121.7068 | 433119.4047 -87.9028 | 42.7361 | 671687.3028 | 671680.2527 | 233424.7366 | 233427.5733 -88.5282 | 42.57733 | 620795.31 | 620786.5774 | 214712.7471 | 214715.3176 -88.6028 | 44.03688 | 611961.6631 | 611952.165 | 376702.9819 | 376701.8832 -88.4651 | 44.29296 | 622464.2818 | 622455.3098 | 405342.0929 | 405341.2876 -88.2424 | 44.30755 | 640197.7963 | 640188.9205 | 407318.7782 | 407318.1713 -90.7711 | 43.56154 | 437733.8693 | 437722.7151 | 323251.3754 | 323249.4127 -88.0876 | 43.00795 | 655871.2693 | 655863.4741 | 263254.573 | 263256.7669

How can we address this issue? Thank you!

Here is the java code of Method B: package Projection;

import java.io.IOException; import java.net.UnknownHostException; import java.sql.*; import java.util.ArrayList; import java.util.Arrays; import Projection.db.ConnectionBean; import org.osgeo.proj4j.CRSFactory; import org.osgeo.proj4j.CoordinateReferenceSystem; import org.osgeo.proj4j.CoordinateTransform; import org.osgeo.proj4j.CoordinateTransformFactory; import org.osgeo.proj4j.ProjCoordinate;

public class Main {

public static void main(String[] args) throws SQLException, UnknownHostException, IOException  {
    CRSFactory csFactory = new CRSFactory();
    CoordinateTransformFactory txFactory = new CoordinateTransformFactory();
    CoordinateReferenceSystem from1 = csFactory.createFromName("EPSG:4326");
    CoordinateReferenceSystem to1 = csFactory.createFromName("EPSG:3069");
    //CoordinateReferenceSystem from2 = csFactory.createFromName("EPSG:4152");
    //CoordinateReferenceSystem to2 = csFactory.createFromName("EPSG:3069");
    CoordinateTransform tx1 = txFactory.createTransform(from1, to1);
    //CoordinateTransform tx2 = txFactory.createTransform(from2, to2);
    long startTime = System.nanoTime();
    //connect to database
    ConnectionBean con = new ConnectionBean();
    PreparedStatement statement = null;
    ResultSet resultSet = null;
    try
    {
         String loadSql = "select XXX,LON,LAT,GIS_X,GIS_Y,NAD27_X, NAD27_Y "+
                "from xxxxx";

         statement = con.prepareStatement(loadSql);
         resultSet = statement.executeQuery();

      while (resultSet.next())
      {  
        // find empty NAD27 coords 
        if (resultSet.getDouble("NAD27_X") <1 || resultSet.getDouble("NAD27_Y") < 1) {

            if (resultSet.getDouble("lon") >0 || resultSet.getDouble("lat") > 0 ) {
                // projection from lonlat to nad27
                double raw_lon = resultSet.getDouble("lon"); 
                double raw_lat = resultSet.getDouble("lat");
                double ACCDNMBR = resultSet.getDouble("ACCDNMBR");
                ProjCoordinate p1 = new ProjCoordinate(raw_lon, raw_lat);
                tx1.transform(p1, p1);
                //tx2.transform(p1, p1);
                double NAD27_x = p1.x;
                double NAD27_y = p1.y;
                //upadate nad27
                String loadSq2 = "update XXXX set NAD27_X ="+ NAD27_x + ", NAD27_Y = " + NAD27_y + " where XXX =" + XXX;
                statement = con.prepareStatement(loadSq2);
                statement.executeQuery();
                statement.close();
            }       
         }          
       }
      con.commit();
      long endTime   = System.nanoTime();
      long totalTime = endTime - startTime;
      System.out.println(totalTime);
    }

    catch (SQLException e)
    { 
        System.out.println(e);
    }  
    finally {
        //System.out.print("finally");
        statement.close();
        con.close();

    }
}

}

Thank you very much!

Timothy

rouault commented 5 years ago

Likely datum shift missing, but it seems this is a bug for Proj4J, not for PROJ. So https://trac.osgeo.org/proj4j would be a better place to report this (although it does not look to be maintained...)

rouault commented 5 years ago

Closing as a non-PROJ bug