方法一:
用proj4j(proj4对应的java库)towgs84参数对应的七个值为七参数值
public CoordinateTransform coordtrans() {
CRSFactory targetFactory = new CRSFactory();
CRSFactory crsFactory = new CRSFactory();
//目标坐标系统
String target_param = "+proj=longlat +datum=WGS84 +no_defs ";
CoordinateReferenceSystem target = targetFactory.createFromParameters("wgs84", target_param);
//源坐标系统
String xian80_param = "+proj=longlat +a=6378140 +b=6356755.288157528 +towgs84=115.8,-154.4,-82.3,0,0,0,8 +no_defs ";
CoordinateReferenceSystem xian80 = crsFactory.createFromParameters("xian80", xian80_param);
CoordinateTransformFactory ctf = new CoordinateTransformFactory();
CoordinateTransform transform = ctf.createTransform(xian80, target);
return transform;
}
public static void main(String[] args) {
SpringApplication.run(Demo1Application.class, args);
Project_54 project_54=new Project_54();
CoordinateTransform transforms=project_54.coordtrans();
if (transforms != null) {
ProjCoordinate projCoordinate = new ProjCoordinate(121.976469682,41.4470288037);
transforms.transform(projCoordinate, projCoordinate);
Double dNorth = projCoordinate.y;
Double dEast = projCoordinate.x;
System.out.print(dNorth);
System.out.print("/");
System.out.print(dEast);
}
}
方法二:
用arcgis js api steps.wkt参见https://developers.arcgis.com/java/10-2/guide/datum-transformations.htm#ESRI_SECTION1_7635FE2A60E6449898D5AD0ADE2CA0C,可以对wkt的七参数进行自定义调整。
var steps= new GeographicTransformationStep() ;
steps.wkt="GEOGTRAN[\"Xian_1980_To_WGS_1984\","+
"GEOGCS[\"GCS_Xian_1980\",DATUM[\"D_Xian_1980\",SPHEROID[\"Xian_1980\",6378140.0,298.257]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],"+
"GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],"+
"METHOD[\"Position_Vector\"],PARAMETER[\"X_Axis_Translation\",115.8],PARAMETER[\"Y_Axis_Translation\",-154.4],PARAMETER[\"Z_Axis_Translation\",-82.3],PARAMETER[\"X_Axis_Rotation\",0.0],PARAMETER[\"Y_Axis_Rotation\",0.0],PARAMETER[\"Z_Axis_Rotation\",0.0],PARAMETER[\"Scale_Difference\",8]]";
var geographicTransformation=new GeographicTransformation({
steps:[steps]
})
var inSpatialReference = new SpatialReference({
wkid: 4610 //Sphere_Sinusoidal
});
var outSpatialReference = new SpatialReference({
wkid: 4326
});
var wgsPoints=new Point([121.976469682,41.4470288037],inSpatialReference);
console.log(wgsPoints)
projection.load().then(function(){
var projectedPoints = projection.project(wgsPoints, outSpatialReference,geographicTransformation);
console.log(projectedPoints.x)
console.log(projectedPoints.y)
})
总结:经证明,两种方法得出的结果是一样的
方法1结果:
方法二结果: