3
我想使用python GDAL/OGR模块从OSM.PBF文件中提取数据。使用GDAL/OGR python模块解析osm.pbf数据
目前我的代码看起来是这样的:
import gdal, ogr
osm = ogr.Open('file.osm.pbf')
## Select multipolygon from the layer
layer = osm.GetLayer(3)
# Create list to store pubs
pubs = []
for feat in layer:
if feat.GetField('amenity') == 'pub':
pubs.append(feat)
虽然这个代码稍微正常工作与small.pbf文件(15MB)。然而,解析大于50MB的文件时,我收到以下错误:
ERROR 1: Too many features have accumulated in points layer. Use OGR_INTERLEAVED_READING=YES MODE
当我把这个模式上:
gdal.SetConfigOption('OGR_INTERLEAVED_READING', 'YES')
OGR根本不返回任何特征的全部了,解析即使小文件。
有人知道这里发生了什么吗?
根据http://gdal.org/1.11/ogr/drv_osm.html交错也需要特殊的阅读模式。下面是这个特殊阅读模式的python示例:https://lists.osgeo.org/pipermail/gdal-dev/2014-April/038633.html 我从来没有使用GDAL/OGR,所以不知道细节。如果它可以随意发布更多有用的答案和示例代码。 – scai