Passing selection to SelectByLocation Tool

1815
1
Jump to solution
05-29-2013 12:08 AM
AlbertoLaurenti
New Contributor III
Hi,
I need to run "Select By Location" tool for each of the polygon (ring) created by Service Area Network tool. I do not know how to pass the selected polygon to the tool.
Please, any help would be appreciated.
Thanks

Dim ToolSelByLoc As SelectLayerByLocation = New SelectLayerByLocation() Dim naContext As ESRI.ArcGIS.NetworkAnalyst.INAContext = naLayer.Context Dim table As ITable = TryCast(naContext.NAClasses.ItemByName("SAPolygons"), ITable) If table.RowCount(Nothing) > 0 Then    For rec = 1 To table.RowCount(Nothing)       'Dim qF As IQueryFilter = New QueryFilter       'qF.WhereClause = "OBJECTID = " & rec       'selSet = table.Select(qF, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, Nothing)       With ToolSelByLoc            .in_layer = pointFL            .overlap_type = "WITHIN"            .select_features = table '.Select(qF, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, Nothing)       End With       RunTool(gp, ToolSelByLoc, Nothing)      'SelectByLocation    next rec End If
0 Kudos
1 Solution

Accepted Solutions
AlbertoLaurenti
New Contributor III
To those who are interested in I solved my problem with a Definition Query for each of the polygon Service Area found.

Dim featureCursor As IFeatureCursor Dim feature As IFeature 'Dim naContext As ESRI.ArcGIS.NetworkAnalyst.INAContext = naLayer.Context 'Dim fc As IFeatureClass = TryCast(naContext.NAClasses.ItemByName("SAPolygons"), IFeatureClass) Dim qF As IQueryFilter = New QueryFilter Dim defQuery As IFeatureLayerDefinition2 Dim fl As IFeatureLayer = GetLayerByName("Polygons") fc = fl.FeatureClass If fc.FeatureCount(Nothing) > 1 Then             featureCursor = fc.Search(Nothing, False)             feature = featureCursor.NextFeature             Do While Not feature Is Nothing                 defQuery = fl                 defQuery.DefinitionExpression = ""                 defQuery.DefinitionExpression = "OBJECTID = " & feature.Value(feature.Fields.FindField("OBJECTID"))                 With ToolSelByLoc                     .in_layer = pointFL                     .overlap_type = "WITHIN"                     .select_features = fl                 End With                 '---------------------                 RunTool(gp, ToolSelByLoc, Nothing)                 '---------------------                 '---------------------                 StorePointIDInArray(CDbl(feature.Value(feature.Fields.FindField("ToBreak"))))                 '---------------------                 defQuery = fl                 defQuery.DefinitionExpression = ""                 defQuery = Nothing                 feature = featureCursor.NextFeature             Loop Else             featureCursor = fc.Search(Nothing, False)             feature = featureCursor.NextFeature             With ToolSelByLoc                 .in_layer = pointFL                 .overlap_type = "WITHIN"                 .select_features = fl             End With             '---------------------             RunTool(gp, ToolSelByLoc, Nothing)             '---------------------             '---------------------             StorePointIDInArray(CDbl(feature.Value(feature.Fields.FindField("ToBreak"))))             '--------------------- End If feature = Nothing featureCursor = Nothing

View solution in original post

0 Kudos
1 Reply
AlbertoLaurenti
New Contributor III
To those who are interested in I solved my problem with a Definition Query for each of the polygon Service Area found.

Dim featureCursor As IFeatureCursor Dim feature As IFeature 'Dim naContext As ESRI.ArcGIS.NetworkAnalyst.INAContext = naLayer.Context 'Dim fc As IFeatureClass = TryCast(naContext.NAClasses.ItemByName("SAPolygons"), IFeatureClass) Dim qF As IQueryFilter = New QueryFilter Dim defQuery As IFeatureLayerDefinition2 Dim fl As IFeatureLayer = GetLayerByName("Polygons") fc = fl.FeatureClass If fc.FeatureCount(Nothing) > 1 Then             featureCursor = fc.Search(Nothing, False)             feature = featureCursor.NextFeature             Do While Not feature Is Nothing                 defQuery = fl                 defQuery.DefinitionExpression = ""                 defQuery.DefinitionExpression = "OBJECTID = " & feature.Value(feature.Fields.FindField("OBJECTID"))                 With ToolSelByLoc                     .in_layer = pointFL                     .overlap_type = "WITHIN"                     .select_features = fl                 End With                 '---------------------                 RunTool(gp, ToolSelByLoc, Nothing)                 '---------------------                 '---------------------                 StorePointIDInArray(CDbl(feature.Value(feature.Fields.FindField("ToBreak"))))                 '---------------------                 defQuery = fl                 defQuery.DefinitionExpression = ""                 defQuery = Nothing                 feature = featureCursor.NextFeature             Loop Else             featureCursor = fc.Search(Nothing, False)             feature = featureCursor.NextFeature             With ToolSelByLoc                 .in_layer = pointFL                 .overlap_type = "WITHIN"                 .select_features = fl             End With             '---------------------             RunTool(gp, ToolSelByLoc, Nothing)             '---------------------             '---------------------             StorePointIDInArray(CDbl(feature.Value(feature.Fields.FindField("ToBreak"))))             '--------------------- End If feature = Nothing featureCursor = Nothing
0 Kudos