【发布时间】:2017-09-03 13:34:20
【问题描述】:
我正在尝试使用 GDAL 的 SetAttributeFilter() 过滤我的 shapefile 图层中的特征,但过滤器似乎没有效果。
我当前的数据是来自美国人口普查局的 shapefile,但我尝试使用其他 shapefile 并得到类似的结果。
例如
from osgeo import ogr
shapefile_path = '../input/processed/shapefile/'
shapefile_ds = ogr.Open(shapefile_path)
cbsa = shapefile_ds.GetLayer('cb_2016_us_cbsa_500k')
print(cbsa.GetFeatureCount())
cbsa.SetAttributeFilter('NAME = "Chicago-Naperville-Elgin, IL-IN-WI"')
feat = cbsa.GetNextFeature()
print(feat.GetField('NAME'))
print(cbsa.GetFeatureCount())
产量
945
Platteville, WI
945
我正在使用 Python 3.6 和 GDAL 2.2.1
【问题讨论】:
标签: python-3.x gis gdal