使用postgres的控件postgis计算gemo路段长度及路段定长分隔点

1、postgres控件postgis安装

CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology;

2、计算路段长度(单位M)

SELECT guid,ST_Length(gemo,false) distance from gemotable
gemotable :表名
guid:键值
gemo:表中gemo数据的字段名称
distance:查询结果中长度字段名称

3、计算路段定长分割点

SELECT st_astext(ST_LineInterpolatePoint(ST_LineMerge(gemo),{i/lenth})) FROM gemotable WHERE guid = ‘';
gemotable :表名
guid = '
’:指定路段的查询条件
gemo:表中gemo数据的字段名称
i、lenth:第几个分割点,分割点总数(如定长为1cm,则分割点总数=长度*100)

4、分割点计算python

        open(file, 'w', encoding='utf-8').close()
        gps,m,l={},0,[]
        for i in range(lenth):
            sql1=f"SELECT st_astext(ST_LineInterpolatePoint(ST_LineMerge(geom),{i/lenth})) FROM geomtable WHERE guid = '{gid}';"
            cur.execute(sql1)
            distance = cur.fetchall()
            if list(distance):
                #获得经纬度
                long,lat=distance[0][0].replace("(","").split(" ")[2:4]	
                #根据前一个点经纬度,计算进入该点的角度
                degree=self.getDegree(gps_point_map[luxian][i - 1][:2], (long, lat)) if i > 0 else config["gps"]["firstdegree"] 
                gps[i]=(long,lat,degree)
                m+=1
            if m%1000==0 or i+1==lenth:
                #进度及数据保存
                print(time.time(),(i+1)/lenth)
                l0=sorted(list(set(gps)-set(l)))
                with open(file, 'a+', encoding='utf-8') as f:
                    [f.write(",".join([str(j) for j in gps[k]])+"\n") for k in l0]
                l=list(gps)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值