Python GDAL/OGR - 获取 KML headers

Python GDAL/OGR - get KML headers

是否可以使用 GDAL/OGR 为 Python 获取 KML 名称 and/or 描述字段?我可以很容易地获取各个图层的字段,只是不能获取整个图层。

代码是:

from osgeo import ogr
file = #path to file goes here

inDriver = ogr.GetDriverByName( 'KML' )
inDataSource = inDriver.Open( file )
inLayer = inDataSource.GetLayer()

获取 KML name/description 字段的最佳方法是什么?

最简单的方法是使用单独的 Python XML 解析器而不是 GDAL/OGR 包。

import xml.etree.ElementTree as ET

tree = ET.parse( file )
root = tree.getroot()
description = root[0][1].text