Python GDAL / OGR - 获取KML标头

时间:2015-09-04 18:33:34

标签: python kml gdal ogr

无论如何使用GDAL / OGR for Python获取KML名称和/或描述字段?我可以很容易地获得各个图层的字段,而不是整个事情。

代码是:

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

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

获取KML名称/说明字段的最佳方式是什么?

1 个答案:

答案 0 :(得分:1)

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

import xml.etree.ElementTree as ET

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