locationtech / proj4j

Java port of the Proj.4 library for coordinate reprojection
Other
181 stars 71 forks source link

Setting earth radius The calculation result is wrong #70

Closed jidengke closed 3 years ago

jidengke commented 3 years ago

String lccParam="+proj=lcc +lat_1=20.0 +lat_2=50.0 +lat_0=38.00001 +lon_0=102.0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +R=6370000 +no_defs";
The calculation result is wrong

pomadchin commented 3 years ago

Hello, thanks for reporting! Could you prepare the failing test case? I.e. the code that generates a wrong result + what should be the expected result.

jidengke commented 3 years ago

Thank you for your reply code

import org.locationtech.proj4j.*;

/**
 * Proj4jTest
 *
 * @author jidengke
 * @date 2021/3/7 13:24
 */
public class Proj4jTest {
    public static void main(String[] args) {
        ProjCoordinate s=new ProjCoordinate();
        s.y=-4.504755;
        s.x=65.324837;
        String wgsParam="+proj=longlat +datum=WGS84 +no_defs";
        String lccParam="+proj=lcc +lat_1=20.0 +lat_2=50.0 +lat_0=38.00001 +lon_0=102.0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +R=6370000 +no_defs";;
        CoordinateTransformFactory ctFactory = new CoordinateTransformFactory();
        CRSFactory csFactory = new CRSFactory();
        CoordinateReferenceSystem source = csFactory.createFromParameters("wgs", wgsParam);
        CoordinateReferenceSystem target = csFactory.createFromParameters("lcc", lccParam);
        CoordinateTransform coordinateTransform = ctFactory.createTransform(source, target);
        ProjCoordinate t = new ProjCoordinate();
        coordinateTransform.transform(s, t);
        System.out.println(t.x);
        System.out.println(t.y);
    }
}

Program output x=-4813708.6575989155 y=-3981769.0948999394

this is qgis output x=-4819499.5840 y=-4009501.2945

1615096378(1)

jidengke commented 3 years ago

I tried to add a new datum to the source code 1615097481(1)

String lccParam="+proj=lcc +lat_1=20.0 +lat_2=50.0 +lat_0=38.00001 +lon_0=102.0 +x_0=0 +y_0=0 +ellps=CLEAR +units=m +no_defs";

this output

x=-4819499.583995361 y=-4009501.2944552563