Layer物件有一個方法叫做SetAttributeFilter(
>>> layer.GetFeatureCount()
42
>>> layer.SetAttributeFilter("cover = 'shruot'")
.
>>> layer .SetAttributeFilter(None) >>> layer.GetFeatureCount() 42空間過濾器Spatial filters有兩種。一種是SetSpatialFilter(( > poly = featAreas.Get.
42
>>> layerSites.SetSpatialFilter(poly)
>>> layerSites.GetFeatureCount()>>> layerSites.GetFeatureCount( FilterRect(460000, 4590000, 490000, 4600000 )
>>> layerSites.GetFeatureCount()
4
>>> layerSites.SetSpatialFilter(None)
🜎還有更複雜的Filter,例如執行SQL查詢語句ExecuteSQL(:
4
最後一句話ReleaseResultSet(
下面的例子,統計了cover為grass的所有Feature的數目
>>> result = dsSites.ExecuteSQL("select count(*) from sites where cover = 'grass'")
. GetFeatureCount()
11
>>> result.GetFeature(0).GetField(0)
11
result = ds .ExecuteSQL("select distinct cover from sites")
resultFeat = result.GetNextFeature()
while resultFeat: resultFeat = result.GetNextFeature()
ds.ReleaseResultSet(result )
shrubs
trees
rocks
grass
bare
有幾種統計ecuteSQL('select distinct cover from sites')coverFeat = coverLayer.GetNextFeature()while coverFeat:cntLayer = ds.ExecuteSQL("select count(*) from sites where cover = ' “ + coverFeat.GetField(0) + “ceat (0) + ' ' +print coverFeat.GetField(0) + ' ' + cntLayer.GetFeature(0).GetFieldAsString(0) ds.ReleaseResultSet(cntLayer). ReleaseResultSet(coverLayer) shrubs 6 trees 11 rocks 6 1111🜎 sect判斷兩個要素是否相交poly2.Intersect(poly1)
返回0表示不相交,返回1表示相交
Disjoint判斷兩個要素是否不相交
poly2.Disjoint(poly1)
返回1表示不相交,返回0poly2.Disjoint(poly1)
返回1表示不相交,返回00表示,跟Intersect正好相反
Touch表示相鄰(擦邊)
poly2.Touches(poly1)
返回0表示不擦邊,回1表示擦邊
Crosses穿越,一般是一條線穿過一個多邊形
Crosses穿越,一般是一條線穿過一個多邊形poly2.Crosses(line)
返回0表示不穿過,返回1表示穿過
Within包含,一個要素完全被另一個要素圈起來了
ptB.Within(poly1)
返回0表示點在多邊形外,返回1表示點在多邊形內
Contains包含,跟Within正好相反
poly1.Contains(ptB)
就是把主調對象和參數換一下啦
Overlaps重疊,好像只有兩個邊形之好像只有兩個邊形之間才能overlap
poly2.Overlaps(poly3)
回傳0表示不重疊,回傳1表示重疊
下面看簡單的地理資料處理geoprocessing
多邊形的:
交交交切並:poly3.Union(poly2)
差:poly3.Difference(poly2)
補:poly3.SymmetricDifference(poly2)
geometry的:
以上就是python gdal教程之:過濾器,簡單的空間分析,函數和模組的內容,更多相關內容請關注PHP中文網(m.sbmmt.com)!