重现“在 python 中创建具有点和线的 kml”问题邮政
我正在尝试复制我在下面的链接中遇到的帖子,但出现了一条错误消息,我有点不确定如何解决: 链接到之前的帖子我'我尝试复制
我在以下行中收到错误:
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")
I'm trying to replicate a post I came across in the link below and had an error message come up I'm a bit unsure how to resolve:
Link to Prior Post I'm trying to replicate
I'm getting an error on the following line:
coord = (row[5], row[6]) # lon, lat order
The error message reads IndexError: string index out of range. I'm calling the column numbers that have my lat and long, which is 5 & 6. Any idea what this error message is referring to?
Here's the script I have at this point:
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")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 df.iterrows() 迭代数据框,使用 df.loc[index, 'geometry'] 访问点。
Use
df.iterrows()
to iterate over the data frame anddf.loc[index, 'geometry']
to access the point.