Hi all, This is relatively a common query but somehow i m not being able to solve it. I have 2 point shapefiles and i need to select points from Layer1 that intersects with points of Layer 2.I am trying this code : Dim IMxDoc As IMxDocument
Dim pMap As IMap
Dim Point_Layer1 As IFeatureLayer
Dim Point_Layer2 As IFeatureLayer
Dim pFeatureCursor As IFeatureCursor
Dim pFeature As IFeature
Dim pGeometryCollection As IGeometryCollection
Dim pSpatialfilter As ISpatialFilter
Dim pFeatureSelection As IFeatureSelection
Set IMxDoc = ThisDocument
Set pMap = IMxDoc.ActiveView
Set Point_Layer1 = pMap.Layer(0)
Set Point_Layer2 = pMap.Layer(1)
Set pFeatureCursor = Point_Layer1.FeatureClass.Search(Nothing, False)
Set pGeometryCollection = New GeometryBag
Set pFeature = pFeatureCursor.NextFeature
Do While Not pFeature Is Nothing
pGeometryCollection.AddGeometry pFeature.Shape
Set pFeature = pFeatureCursor.NextFeature
Loop
Set pSpatialfilter = New SpatialFilter
With pSpatialfilter
Set .Geometry = pGeometryCollection
.GeometryField = Point_Layer2.FeatureClass.ShapeFieldName
.SpatialRel = esriSpatialRelIntersects
End With
Set pFeatureSelection = Point_Layer1
pFeatureSelection.SelectFeatures pSpatialfilter, esriSelectionResultNew, False
IMxDoc.ActiveView.Refresh
but for some reason it selects all the points in layer(0).. where am i going wrong.. I need to select only the intersecting points.Thanks in Advance,Priyanka Mehta