多个点坐标存储在str中,转换成LineString
多个点坐标存储在str中,如何转换成LineString?
思路:
1.str转换成list
2.经度、维度转换成float
3.构建元祖,添加到一个空list(line_list)
4.最后直接通过LineString构建
- 数据如下
from shapely.geometry import LineString
tmp = '114.185246,30.523517;114.18529,30.52349;114.185478,30.523372;114.185698,30.523238;114.186717,30.522626;114.187774,30.521971;114.188412,30.521553;114.189003,30.521199;114.189475,30.520888;114.189748,30.520716;114.190022,30.520534'
def turn_to_linestring(x):
line = LineString()
line_list = []
for i in x.split(';'):
lng = float(i.split(',')[0])
lat = float(i.split(',')[1])
point_tuple = (lng,lat) #构建元祖
line_list.append(point_tuple)
linestring = LineString(line_list)
return linestring
turn_to_linestring(tmp)
- 结果