没有合适的资源?快使用搜索试试~ 我知道了~
首页GDAL文档说明(图文说明)
资源详情
资源评论
资源推荐

Filters & Simple Analysis of
Vector Data; Functions &
Modules
OS Python week 3: Filters & analysis; Functions & modules [1]
Modules
Open Source RS/GIS Python
Week 3

Attribute filters
• The Layer object has a method
SetAttributeFilter(<where_clause>)
• Resets reading so GetNextFeature()
gets the first feature that matches the filter
•
Pass
None
to clear the filter
OS Python week 3: Filters & analysis; Functions & modules [2]
•
Pass
None
to clear the filter
>>> layer.GetFeatureCount()
42
>>> layer.SetAttributeFilter("cover = 'shrubs'")
>>> layer.GetFeatureCount()
6
>>> layer.SetAttributeFilter(None)
>>> layer.GetFeatureCount()
42

Spatial filters
• There are two methods on the Layer
object to set spatial filters
• SetSpatialFilter(<geom>)
•
SetSpatialFilterRect(<minx>, <miny>,
OS Python week 3: Filters & analysis; Functions & modules [3]
SetSpatialFilterRect(<minx>, <miny>,
<maxx>, <maxy>)
• Use SetSpatialFilter(None) to clear the
filter

layerAreas is polygon and layerSites is points
>>> featAreas = layerAreas.GetNextFeature()
>>> poly = featAreas.GetGeometryRef()
>>> layerSites.GetFeatureCount()
42
>>> layerSites.SetSpatialFilter(poly)
>>> layerSites.GetFeatureCount()
3
OS Python week 3: Filters & analysis; Functions & modules [4]
>>> layerSites.GetFeatureCount()
3
>>> layerSites.SetSpatialFilterRect(460000,
4590000, 490000, 4600000)
>>> layerSites.GetFeatureCount()
4
>>> layerSites.SetSpatialFilter(None)
>>> layerSites.GetFeatureCount()
42

More complicated filters
• DataSource objects have a method
ExecuteSQL(<SQL>)
• Returns a Layer object that can be looped
through like other layers
OS Python week 3: Filters & analysis; Functions & modules [5]
through like other layers
• When done with the resulting layer, call
ReleaseResultSet(<result_layer>) on
the DataSource
• See http://www.gdal.org/ogr/ogr_sql.html
for more info about valid SQL syntax
剩余38页未读,继续阅读



















安全验证
文档复制为VIP权益,开通VIP直接复制

评论1