首页 / 浏览问题 / 云GIS / 问题详情
iServer扩展领域服务参数问题
216EXP 2019年09月10日

需求: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好像识别不了二维数据类型

1个回答

您好,您那边的具体需求是对多个点数据进行坐标点转换吗?如果是对多个点数据进行坐标点转换,可以这样操作:在传参数的传一个json对象,json对象中存储点坐标点数组,在代码中去解析这个json对象,获取里面的数组,依次进行转换就可以了。
9,137EXP 2019年09月10日

右侧的java type支持传入json对象?您验证过吗???我这里传入的是一个二维数据都不支持。

这个type是你这边规定的,你可以传String类型,然后通过将string转为json数据,再去解析json。您可以参考这篇博客:https://blog.csdn.net/supermapsupport/article/details/99671502

...