JTS 中geolatte转换为 locationtech的数据

工作中发现的困扰很久的问题,多次尝试最终揭开

代码奉上

 //String 转为 geolatte
    public static org.geolatte.geom.Geometry changeStringToGeom(String s){
        org.geolatte.geom.Geometry<?> geometry = Wkb.fromWkb(ByteBuffer.from(s));
        return geometry;
    }
    //转换geolatte类型
    public static Geometry changeGeolatteToLocationtech(org.geolatte.geom.Geometry geometry){
        PositionSequence positions = geometry.getPositions();
        int size = positions.size();
        int num = 0;
        List<double[]> list = new ArrayList<>();

        while (true){
            double[] pos = new double[3];
            Position positionN = positions.getPositionN(num);
            pos[0] = positionN.getCoordinate(0);
            pos[1] = positionN.getCoordinate(1);
            pos[2] = positionN.getCoordinate(2);

            ++num;
            list.add(pos);
            if(num == positions.size()){break;}

        }
        Coordinate[] c = new Coordinate[num];
        num = 0;
        for(Coordinate c1 :c){
            c1 = null;
            double[] doubles = list.get(num);
            Coordinate c0 = new Coordinate(doubles[0],doubles[1],doubles[2]);
            c[num] = c0;
            num++;
        }
        GeometryFactory factory = new GeometryFactory();
        LineString lineString = factory.createLineString(c);
        Geometry geometry2 = factory.createGeometry(lineString);
        return geometry2;
    }

因为数据库固定数据为LineString 线 类型,所以只使用它来存储数据,如果数据库中有多种类型的图形,可以通过拆分数据并分多种情况判断,再一一对应放入点位。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值