我有这个kml,文件很长,我已经设法从一个多边形中获取坐标。但我的循环似乎没有转移到下一个多边形。有没有办法“指向”下一个多边形,所以我可以从中获取坐标?谢谢
PS我已经从stackoverflow中一些问题的代码中获取了部分代码
from pykml import parser
import os, zipfile, os.path
from zipfile import ZipFile as zip
mapCoords = [[]]
def extractAll(zipName):
z = zip(zipName)
for f in z.namelist():
if f.endswith('/'):
os.makedirs(f)
else:
z.extract(f)
return f
doc = parser.parse(extractAll("temp_kmz")).getroot()
for Polygon in doc.Document.Folder.Placemark.MultiGeometry:
a = 0
mapCoords[a].append(doc.Document.Folder.Placemark.MultiGeometry.Polygon.outerBoundaryIs.LinearRing.coordinates)
a+=1
print mapCoords
这是kml文件的一部分
<MultiGeometry>
<Polygon>
<outerBoundaryIs><LinearRing><coordinates> 121.077285,14.626314 121.077006,14.626312 121.077009,14.626040 121.077287,14.626043 121.077285,14.626314</coordinates></LinearRing></outerBoundaryIs>
</Polygon>
<Polygon>
<outerBoundaryIs><LinearRing><coordinates> 121.077285,14.626314 121.077563,14.626316 121.077561,14.626587 121.077282,14.626585 121.077285,14.626314</coordinates></LinearRing></outerBoundaryIs>
</Polygon>
<Polygon>
<outerBoundaryIs><LinearRing><coordinates> 121.079236,14.626059 121.079234,14.626330 121.079512,14.626332 121.079510,14.626603 121.079231,14.626601 121.078953,14.626599 121.078955,14.626328 121.078958,14.626057 121.079236,14.626059</coordinates></LinearRing></outerBoundaryIs>
</Polygon>
<Polygon>
<outerBoundaryIs><LinearRing><coordinates> 121.077561,14.626587 121.077839,14.626590 121.077837,14.626861 121.077834,14.627132 121.077556,14.627129 121.077558,14.626858 121.077561,14.626587</coordinates></LinearRing></outerBoundaryIs>
</Polygon>
<Polygon>
<outerBoundaryIs><LinearRing><coordinates> 121.125000,14.627245 121.125000,14.627516 121.124887,14.627515 121.124890,14.627244 121.125000,14.627245</coordinates></LinearRing></outerBoundaryIs>
</Polygon>