重现问题 "Create a kml in python that has both points and lines" post
Issue reproducing "Create a kml in python that has both points and lines" post
我正在尝试复制我在下面 link 中遇到的 post 并出现一条错误消息 我有点不确定如何解决:
Link to Prior Post I'm trying to replicate
我在以下行中收到错误:
coord = (row[5], row[6]) # lon, lat order
错误消息显示为 IndexError:字符串索引超出范围。 我正在调用具有我的纬度和经度的列号,即 5 和 6。知道什么吗此错误消息指的是什么?
这是我此时的脚本:
import geopandas as gpd
import simplekml
kml = simplekml.Kml()
inputfile = gpd.read_file("C:/Users/CombineKMLs_AddLabels/Data/ScopePoles.shp")
points = []
for row in inputfile:
coord = (row[5], row[6]) # lon, lat order
pnt = kml.newpoint(name=row[2], coords=[coord])
points.append(coord)
pnt.style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/placemark_square.png'
ls = kml.newlinestring(name='A LineString')
ls.coords = np.array(points)
ls.altitudemode = simplekml.AltitudeMode.relativetoground
ls.extrude = 1
kml.save("C:/Users/CombineKMLs_AddLabels/Data/PolesandLines.shp")
使用 df.iterrows()
遍历数据框并使用 df.loc[index, 'geometry']
访问点。
import geopandas as gpd
import simplekml
kml = simplekml.Kml()
df = gpd.read_file("C:/Users/CombineKMLs_AddLabels/Data/ScopePoles.shp")
points = []
for index, poi in df.iterrows():
pt = df.loc[index, 'geometry']
coord = (pt.x, pt.y)
pnt = kml.newpoint(name=index, coords=[coord])
points.append(coord)
pnt.style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/placemark_square.png'
ls = kml.newlinestring(name='A LineString', coords=points)
kml.save('PolesandLines.kml')
我正在尝试复制我在下面 link 中遇到的 post 并出现一条错误消息 我有点不确定如何解决: Link to Prior Post I'm trying to replicate
我在以下行中收到错误:
coord = (row[5], row[6]) # lon, lat order
错误消息显示为 IndexError:字符串索引超出范围。 我正在调用具有我的纬度和经度的列号,即 5 和 6。知道什么吗此错误消息指的是什么?
这是我此时的脚本:
import geopandas as gpd
import simplekml
kml = simplekml.Kml()
inputfile = gpd.read_file("C:/Users/CombineKMLs_AddLabels/Data/ScopePoles.shp")
points = []
for row in inputfile:
coord = (row[5], row[6]) # lon, lat order
pnt = kml.newpoint(name=row[2], coords=[coord])
points.append(coord)
pnt.style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/placemark_square.png'
ls = kml.newlinestring(name='A LineString')
ls.coords = np.array(points)
ls.altitudemode = simplekml.AltitudeMode.relativetoground
ls.extrude = 1
kml.save("C:/Users/CombineKMLs_AddLabels/Data/PolesandLines.shp")
使用 df.iterrows()
遍历数据框并使用 df.loc[index, 'geometry']
访问点。
import geopandas as gpd
import simplekml
kml = simplekml.Kml()
df = gpd.read_file("C:/Users/CombineKMLs_AddLabels/Data/ScopePoles.shp")
points = []
for index, poi in df.iterrows():
pt = df.loc[index, 'geometry']
coord = (pt.x, pt.y)
pnt = kml.newpoint(name=index, coords=[coord])
points.append(coord)
pnt.style.iconstyle.icon.href = 'http://maps.google.com/mapfiles/kml/shapes/placemark_square.png'
ls = kml.newlinestring(name='A LineString', coords=points)
kml.save('PolesandLines.kml')