过滤功能只能使用getnextfeature()尊敬

过滤功能只能使用getnextfeature()尊敬
发布日期: 2017-01-17 更新日期: 2017-01-17 编辑:bukun 浏览次数: 3807

标签:
 from osgeo import ogr
inDataSource = ogr.Open( "parcels.shp" )
lyr = inDataSource.GetLayer()
# this is a unique attribute filter targeting only one record
lyr.SetAttributeFilter("PIN = '0000200001'")      
for i in range( 0, lyr.GetFeatureCount() ):
    feat = lyr.GetFeature( i )
    # this will print one feat, but it's the first feat in the Layer and NOT our target filtered feat
    print (feat)
说明:

有两种方法可以访问一个图层的功能。你可以使用 getfeature() 和传递功能或使用 getnextfeature() 传回来以后的特征。如果你正在使用一个属性过滤器( setattributefilter() )或空间滤波器 ( setspatialfilter()setspatialfilterrect() )然后你必须使用getnextfeature()。

如果你读过任何的过滤者你会看到ogr_l_getnextfeature()警告文件。这意味着,如果你使用getfeature(),代替getnextfeature(),那么你仍然可以访问与不被滤层功能的工作。getfeaturecount()将尊重过滤器和显示正确的数字滤波功能。然而,在一个循环getfeaturecount()工作会导致一些有趣的结果。使用层对象作为一个功能的迭代器或使用getnextfeature()明确应该访问功能的默认方法:


Copyright © Since 2014. 开源地理空间基金会中文分会 吉ICP备05002032号

Powered by TorCMS

OSGeo 中国中心 邮件列表

问题讨论 : 要订阅或者退订列表,请点击 订阅

发言 : 请写信给: osgeo-china@lists.osgeo.org