您好,想问一个问题,我这边根据某个数据源的 PrjCoordSys 为基础,将得到的 wgs84 经纬度坐标进行投影为xyz的形式,但是forward方法得到的结果一直不对(第三方的软件结果正确),具体代码如下,通过 ConvertGpsToPrj 进行调用
1、形成特定的投影坐标系
public static PrjCoordSys formingPrjCoordSys(JSONObject jsonPro) {
String geoString = jsonPro.optString( "GPSEllipsoid");
PrjCoordSys prjCoordSys = new PrjCoordSys();
GeoCoordSys geoCoordSys = new GeoCoordSys();
//gps椭球体
switch (geoString) {
case "WGS_1984":
geoCoordSys.setType(GeoCoordSysType.GCS_WGS_1984);
break;
case "CHINA_2000":
geoCoordSys.setType(GeoCoordSysType.GCS_CHINA_2000);
break;
case "XiAn_1980":
geoCoordSys.setType(GeoCoordSysType.GCS_XIAN_1980);
break;
case "Beijing_1954":
geoCoordSys.setType(GeoCoordSysType.GCS_BEIJING_1954);
break;
default:
geoCoordSys.setType(GeoCoordSysType.GCS_WGS_1984); //默认为wgs_84
break;
}
geoCoordSys.setGeoSpatialRefType(GeoSpatialRefType.SPATIALREF_EARTH_LONGITUDE_LATITUDE);
prjCoordSys.setGeoCoordSys(geoCoordSys);
//GPS投影类型设置
Projection projection = new Projection();
String proTypeString = jsonPro.optString( "Name");
switch (proTypeString){
case "Gauss_Kruger":
projection.setType(ProjectionType.PRJ_GAUSS_KRUGER);
break;
case "UTM":
projection.setType(ProjectionType.PRJ_TRANSVERSE_MERCATOR);
break;
case "平面无参数":
projection.setType(ProjectionType.PRJ_NONPROJECTION);
break;
default: //默认为高斯克吕格投影
projection.setType(ProjectionType.PRJ_GAUSS_KRUGER);
break;
}
//设置投影参数
PrjParameter prjParameter = new PrjParameter();
prjParameter.setCentralMeridian(Double.valueOf(jsonPro.optString("CentralMeridian")));
prjParameter.setFalseEasting(Double.valueOf(jsonPro.optString("FalseEasting")));
prjParameter.setFalseNorthing(Double.valueOf(jsonPro.optString("FalseNorthing")));
prjParameter.setScaleFactor(0.9996);
prjParameter.setStandardParallel1(0.);
prjCoordSys.setPrjParameter(prjParameter);
prjCoordSys.setProjection(projection);
return prjCoordSys;
}
2、进行forward调用
public static Point2Ds ConvertGpsToPrj(Context context, Point2Ds point2Ds) {
if (!new File(path, jason_name).exists()) {
Toast.makeText(context, "请创建本工程的投影文件", Toast.LENGTH_SHORT).show();
JsonUtil.creatNewFile(path, jason_name);
return point2Ds;
}
JSONObject jsonObject = JsonUtil.parseJson(path, jason_name);
JSONObject jsonObjectProjection = null;
try {
jsonObjectProjection = jsonObject.getJSONObject( "Projection");
} catch (JSONException e) {
e.printStackTrace();
}
//首先将gps点转为投影坐标,然后进行两个投影坐标系的转换
PrjCoordSys gps_prjCoordSys = formingPrjCoordSys(jsonObjectProjection);
CoordSysTranslator.forward(point2Ds, gps_prjCoordSys);
Log.e("GPS",point2Ds.getItem(0).getX()+" /投影后的GPS/"+ point2Ds.getItem(0).getY());
Log.e("GPS",point2Ds.getItem(1).getX()+" /投影后的GPS/"+ point2Ds.getItem(1).getY());
return point2Ds;
}