GDAL/OGR空间过滤之SetSpatialFilter()

7 篇文章 0 订阅

SetSpatialFilter函数

SetSpatialFitler函数在osgeo.ogr模块下的Layer类中。
SetSpatialFilter(Geometry filter)
输入中的Geometry作为过滤的参数。

__object
MajorObject
Layer
SetSpatialFilter(Geometry filter)

示例

Python

from osgeo imiport ogr
import os
shp_file = 'sates.shp'
drv = ogr.GetDriverByName('ESRI Shapefile')
ds = drv.Open(shp_file)
lyr = ds.GetLayer()

wkt = 'POLYGON ((-103.81402655265633 50.253951270672125,-102.94583419409656 51.535568561879401,-100.34125711841725 51.328856095555651,-100.34125711841725 51.328856095555651,-93.437060743203844 50.460663736995883,-93.767800689321859 46.450441890315041,-94.635993047881612 41.613370178339181,-100.75468205106476 41.365315218750681,-106.12920617548238 42.564247523428456,-105.96383620242338 47.277291755610058,-103.81402655265633 50.253951270672125))'
geom = orgr.CreateGeometryFromWkt(wkt)
lyr.SetSpatialFilter(geom)
for feat in lyr:
  print feat.GetField('STATE_NAME')

lyr.SetSpatialFilter(None)
lyr.ResetReading()

重点

  • 参数Geometry的构造;
  • lyr在执行空间检索后,lyr中包含的要素即为检索的结果;
  • lyr循环后,如果要再使用lyr,则需要清除过滤条件,图层重新开始读取(ResetReading())

注意

官方关于该函数的文档中,有些值得注意的内容。

  1. This function set the geometry to be used as a spatial filter when fetching features via the OGR_L_GetNextFeature() function. Only features that geometrically intersect the filter geometry will be returned.
  2. Currently this test is may be inaccurately implemented(实现上不够精确), but it is guaranteed that all features whose envelope (as returned by OGR_G_GetEnvelope()) overlaps the envelope of the spatial filter will be returned(要素的外封与过滤要素的外封相叠). This can result in more shapes being returned that should strictly be the case(会返回更多的要素).
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值