需求:iServer扩展领域服务,实现同一个坐标系下的投影和地理坐标互转
问题:此方案可以实现一个坐标点的转换,但是实现多个坐标点的转换遇到问题。
方案一【可行】:同一坐标系下,单个坐标点的转换(投影转地理)
代码:
import com.supermap.data.CoordSysTranslator;
import com.supermap.data.Point2D;
import com.supermap.data.Point2Ds;
import com.supermap.data.PrjCoordSys;
import java.io.Console;
public class ProjectToGeo {
public double[] projectToGeo(double a, double b, int m) {
double[] result=new double[2];
Point2D[] pts = {new Point2D(a, b)};
Point2Ds te2DS = new Point2Ds(pts);
//把点击坐标转换成为同一个地理坐标系下的地理坐标
//CoordSysTranslator.inverse(te2DS, PrjCoordSys.fromEPSG(2383));
CoordSysTranslator.inverse(te2DS, PrjCoordSys.fromEPSG(m));
for (int i = 0; i < te2DS.getCount(); i++) {
result[0]=te2DS.getItem(i).x;
result[1]=te2DS.getItem(i).y;
}
return result;
}
public static void main(String[] args) {
// ProjectToGeo projectToGeo = new ProjectToGeo();
// double[] point2Ds = projectToGeo.projectToGeo(509294.479, 2522963.686, 2383);
// System.out.println(point2Ds[0]);
// System.out.println(point2Ds[1]);
// System.out.println(point2Ds);
}
}
方案2【不可行】:同一坐标系下,多个坐标点的转换(投影转地理和地理转投影),其中多个坐标点用的是二维数据
代码:
import com.supermap.data.CoordSysTranslator;
import com.supermap.data.Point2Ds;
import com.supermap.data.Point2D;
import com.supermap.data.PrjCoordSys;
public class ProGeoArr {
public double [][] proGeoArr(double[][] pointList, boolean flag, int epsgcode) {
if (pointList.length <= 0) {
return null;
}
double[][] result = new double[pointList.length][2];
Point2D[] pts = new Point2D[pointList.length];
for (int j = 0; j < pointList.length; j++) {
pts[j] = new Point2D(pointList[j][0], pointList[j][1]);
}
//Point2D[] pts = {new Point2D(a, b)};
Point2Ds te2DS = new Point2Ds(pts);
//把点击坐标转换成为同一个地理坐标系下的地理坐标
//CoordSysTranslator.inverse(te2DS, PrjCoordSys.fromEPSG(2383));
if (flag) {
CoordSysTranslator.inverse(te2DS, PrjCoordSys.fromEPSG(epsgcode));
} else {
CoordSysTranslator.forward(te2DS, PrjCoordSys.fromEPSG(epsgcode));
}
for (int i = 0; i < te2DS.getCount(); i++) {
result[i][0] = te2DS.getItem(i).x;
result[i][1] = te2DS.getItem(i).y;
}
return result;
}
public static void main(String[] args) {
// write your code here
// ProGeoArr projectToGeo = new ProGeoArr();
// double[][] projArr = {{509294.479, 2522963.686}, {509291.479, 2522962.686}, {509290.479, 2522962.686}};
// double[][] result = projectToGeo.proGeoArr(projArr, true, 2383);
//
// for (int i = 0; i < result.length; i++) {
// System.out.println(result[i][0]);
// System.out.println(result[i][1]);
// System.out.println("-------------------------");
// }
// ProGeoArr projectToGeo = new ProGeoArr();
// double[][] projArr = {{114.0905284269002,22.805152635365822}, {114.09049920090027,22.805143621913878}, {114.09048946088859,22.80514362744191}};
// double[][] result = projectToGeo.proGeoArr(projArr, false, 2383);
//
// for (int i = 0; i < result.length; i++) {
// System.out.println(result[i][0]);
// System.out.println(result[i][1]);
// System.out.println("-------------------------");
// }
}
}
问题:多个坐标点的坐标转换,iServer好像识别不了二维数据类型