Extract Geometry By Polygon
利用ITopologicalOperator接口将多个多边形合并成单一多边形,用于进行查询.
Private Function ExtractGeometryByPolygon(pFeatClass As IFeatureClass) As IGeometry
'suppose all featuren in pFeatureClass are polygon user define
Dim pFilter As IQueryFilter
Dim pFeatureCursor As IFeatureCursor
Dim pFeat As IFeature
Dim pGeometryCollection As IGeometryCollection
Set pGeometryCollection = New GeometryBag
Set pFeatureCursor = pFeatClass.Search(Nothing, False)
Set pFeat = pFeatureCursor.NextFeature
Do While Not pFeat Is Nothing
Dim pGeometry As IGeometry
Set pGeometry = pFeat.Shape
pGeometryCollection.AddGeometry pGeometry
Set pFeat = pFeatureCursor.NextFeature
Loop
Dim pTopoOp As ITopologicalOperator
Set pTopoOp = pGeometryCollection
pTopoOp.Simplify
Set pTopoOp = New Polygon
pTopoOp.ConstructUnion pGeometryCollection
Dim pPolygon As IPolygon
Set pPolygon = pTopoOp
Set ExtractGeometryByPolygon = pPolygon
'dispose
Set pFilter = Nothing
Set pFeatureCursor = Nothing
Set pFeat = Nothing
End Function
'suppose all featuren in pFeatureClass are polygon user define
Dim pFilter As IQueryFilter
Dim pFeatureCursor As IFeatureCursor
Dim pFeat As IFeature
Dim pGeometryCollection As IGeometryCollection
Set pGeometryCollection = New GeometryBag
Set pFeatureCursor = pFeatClass.Search(Nothing, False)
Set pFeat = pFeatureCursor.NextFeature
Do While Not pFeat Is Nothing
Dim pGeometry As IGeometry
Set pGeometry = pFeat.Shape
pGeometryCollection.AddGeometry pGeometry
Set pFeat = pFeatureCursor.NextFeature
Loop
Dim pTopoOp As ITopologicalOperator
Set pTopoOp = pGeometryCollection
pTopoOp.Simplify
Set pTopoOp = New Polygon
pTopoOp.ConstructUnion pGeometryCollection
Dim pPolygon As IPolygon
Set pPolygon = pTopoOp
Set ExtractGeometryByPolygon = pPolygon
'dispose
Set pFilter = Nothing
Set pFeatureCursor = Nothing
Set pFeat = Nothing
End Function
-----------------------------------------------------------
佛对我说:你心里有尘。我用力的拭擦。