Hallo,
momentan versuche ich ganz verzweifelt, mir mittels Spatialfilter, die Punkte innerhalb eines Polygons zu selektieren. Es funktioniert nur sofern ich in der Map den Point-Layer selectiere. Allerdings wollte ich das programmiertechnisch so lösen, dass 2 Layer angegeben werden --> also Polygon und Punktlayer und daraus dann selektiert wird.
Desweiteren, wie kann ich die selektierten Punkte in ein Shapefile schreiben, o.a.????
Ich hoffe das IHR mir helfen könnt. Ganz lieben Dank.
Gruß Geri
Hier mein Quellcode:
Sub raeumlBeding()
'Spatial filter
'PointShape and Polygonshape
'test which points are in the Polygon
Dim strMDBFile As String
Dim aoiAccFact As IWorkspaceFactory
Dim aoiAccWsp As IFeatureWorkspace
Dim aoiLAKEFeatureClass As IFeatureClass
Dim pFeatClass As IFeatureClass
strMDBFile = "c:\workspc"
' create ShapefileWorkspaceFactory
Set aoiAccFact = New ShapefileWorkspaceFactory
Set aoiAccWsp = aoiAccFact.OpenFromFile(strMDBFile, 0)
' IFeatureClass ...
Set aoiLAKEFeatureClass = aoiAccWsp.OpenFeatureClass("MyShapeFile1")
Set pPolygonFeatClass = aoiAccWsp.OpenFeatureClass("Merge_allDXFPoints")
Dim aoiCursor As IFeatureCursor
Dim aoiFeature As IFeature
Dim aoiMultiPart As IGeometryCollection
Dim aoiPolygon As IGeometryCollection
' Cursor ...
Set aoiMultiPart = New Polygon
Set aoiCursor = aoiLAKEFeatureClass.Search(Nothing, False)
Set aoiFeature = aoiCursor.NextFeature
Do While Not aoiFeature Is Nothing
Set aoiPolygon = aoiFeature.ShapeCopy
aoiMultiPart.AddGeometryCollection aoiPolygon
Set aoiFeature = aoiCursor.NextFeature
Loop
Dim aoiDocument As IMxDocument
Dim aoiActiveView As IActiveView
Dim aoiLayer As IFeatureLayer
' actuall Layer ... the selected Layer
Set aoiDocument = ThisDocument
Set aoiActiveView = aoiDocument.ActiveView
Set aoiLayer = aoiDocument.SelectedLayer
'............
' I get an result with the selected Layer
'but when I choose a other Layer --> the pointlayer
' so I get no result, why????
'How can I solve this problem?
Dim fLayer As IFeatureLayer
Set fLayer = New FeatureLayer
Set fLayer.FeatureClass = pPolygonFeatClass
'Set aoiLayer = flayer
'............
Dim aoiAreaOfInterest As IGeometry
Dim aoiSpatialFilter As ISpatialFilter
Dim aoiFeatureSelection As IFeatureSelection
' define the spatialFilter ...
Set aoiAreaOfInterest = aoiMultiPart
Set aoiSpatialFilter = New SpatialFilter
With aoiSpatialFilter
Set .Geometry = aoiAreaOfInterest
.GeometryField = fLayer.FeatureClass.ShapeFieldName
.SpatialRel = esriSpatialRelIntersects
End With
' new FeatureSelection ...
Set aoiFeatureSelection = fLayer
aoiFeatureSelection.SelectFeatures aoiSpatialFilter, _
esriSelectionResultNew, False
' show the result ...
aoiActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing
End Sub
momentan versuche ich ganz verzweifelt, mir mittels Spatialfilter, die Punkte innerhalb eines Polygons zu selektieren. Es funktioniert nur sofern ich in der Map den Point-Layer selectiere. Allerdings wollte ich das programmiertechnisch so lösen, dass 2 Layer angegeben werden --> also Polygon und Punktlayer und daraus dann selektiert wird.
Desweiteren, wie kann ich die selektierten Punkte in ein Shapefile schreiben, o.a.????
Ich hoffe das IHR mir helfen könnt. Ganz lieben Dank.
Gruß Geri
Hier mein Quellcode:
Sub raeumlBeding()
'Spatial filter
'PointShape and Polygonshape
'test which points are in the Polygon
Dim strMDBFile As String
Dim aoiAccFact As IWorkspaceFactory
Dim aoiAccWsp As IFeatureWorkspace
Dim aoiLAKEFeatureClass As IFeatureClass
Dim pFeatClass As IFeatureClass
strMDBFile = "c:\workspc"
' create ShapefileWorkspaceFactory
Set aoiAccFact = New ShapefileWorkspaceFactory
Set aoiAccWsp = aoiAccFact.OpenFromFile(strMDBFile, 0)
' IFeatureClass ...
Set aoiLAKEFeatureClass = aoiAccWsp.OpenFeatureClass("MyShapeFile1")
Set pPolygonFeatClass = aoiAccWsp.OpenFeatureClass("Merge_allDXFPoints")
Dim aoiCursor As IFeatureCursor
Dim aoiFeature As IFeature
Dim aoiMultiPart As IGeometryCollection
Dim aoiPolygon As IGeometryCollection
' Cursor ...
Set aoiMultiPart = New Polygon
Set aoiCursor = aoiLAKEFeatureClass.Search(Nothing, False)
Set aoiFeature = aoiCursor.NextFeature
Do While Not aoiFeature Is Nothing
Set aoiPolygon = aoiFeature.ShapeCopy
aoiMultiPart.AddGeometryCollection aoiPolygon
Set aoiFeature = aoiCursor.NextFeature
Loop
Dim aoiDocument As IMxDocument
Dim aoiActiveView As IActiveView
Dim aoiLayer As IFeatureLayer
' actuall Layer ... the selected Layer
Set aoiDocument = ThisDocument
Set aoiActiveView = aoiDocument.ActiveView
Set aoiLayer = aoiDocument.SelectedLayer
'............
' I get an result with the selected Layer
'but when I choose a other Layer --> the pointlayer
' so I get no result, why????
'How can I solve this problem?
Dim fLayer As IFeatureLayer
Set fLayer = New FeatureLayer
Set fLayer.FeatureClass = pPolygonFeatClass
'Set aoiLayer = flayer
'............
Dim aoiAreaOfInterest As IGeometry
Dim aoiSpatialFilter As ISpatialFilter
Dim aoiFeatureSelection As IFeatureSelection
' define the spatialFilter ...
Set aoiAreaOfInterest = aoiMultiPart
Set aoiSpatialFilter = New SpatialFilter
With aoiSpatialFilter
Set .Geometry = aoiAreaOfInterest
.GeometryField = fLayer.FeatureClass.ShapeFieldName
.SpatialRel = esriSpatialRelIntersects
End With
' new FeatureSelection ...
Set aoiFeatureSelection = fLayer
aoiFeatureSelection.SelectFeatures aoiSpatialFilter, _
esriSelectionResultNew, False
' show the result ...
aoiActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing
End Sub
- Anmelden oder Registieren, um Kommentare verfassen zu können