1

我正在尝试从 KML 文件中提取坐标。但是,我不断收到此错误:

for e in doc.Document.Folder.Placemark:
  File "src\lxml\objectify.pyx", line 230, in lxml.objectify.ObjectifiedElement.__getattr__
  File "src\lxml\objectify.pyx", line 450, in lxml.objectify._lookupChildOrRaise
AttributeError: no such child: {http://www.opengis.net/kml/2.2}Placemark

我提取坐标的代码如下:

kml_file = path.join(fileName_kml)

           with open(kml_file) as f:
               doc = parser.parse(f).getroot()
            for e in doc.Document.Folder.Placemark:
                 coor = e.Point.coordinates.text.split(',')
                 print(coor)

不完全确定要做什么或如何解决它。

编辑:这是我的 kml 文件的第一位。我对 Python 也很陌生,所以我不太了解 attritubes 和儿童之类的东西。因此,尽可能提供信息的答案将是很好的感谢。

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <name>loc</name>
    <description/>
    <Style id="poly-000000-1200-77-nodesc-normal">
      <LineStyle>

这就是:

 <Folder>
      <name>Untitled layer</name>
      <Placemark>
        <name>loc</name>
        <styleUrl>#poly-000000-1200-77-nodesc</styleUrl>
        <Polygon>
          <outerBoundaryIs>
            <LinearRing>
              <tessellate>1</tessellate>
              <coordinates>
                -1.0947725,53.9600505,0
                -1.0967252,53.95697,0
                -1.0909316,53.9562629,0
                -1.0887214,53.9598864,0
                -1.0947725,53.9600505,0
              </coordinates>
            </LinearRing>
          </outerBoundaryIs>
        </Polygon>
      </Placemark>
    </Folder>
4

0 回答 0