How can I make a "Select by location" in PRO SDK

4112
11
02-26-2018 11:22 AM
René_AstadDupont
New Contributor II

I have been searching the samples and the API, but so far I have not been able to find any signs on how to make a "Select by Location" in C# With PRO-SDK.

Anyone out there that can point me in the right direction?

Regards

Tags (1)
0 Kudos
11 Replies
Amadeus111
Occasional Contributor II

Thanks for the code, it would make more sense if formatted properly.

0 Kudos
Amadeus111
Occasional Contributor II

 Based on spatial query selecting multiple features and going through selected features

QueuedTask.Run(() =>
{
  using (Geodatabase DMPGeodatabase = new Geodatabase(DMPReadConn))
  {
  FeatureClass featureClassToBeSelected = 
   DMPGeodatabase.OpenDataset<FeatureClass>("featureClassToBeSelected");
  FeatureClass featureClassSelectionCriteria =
   DMPGeodatabase.OpenDataset<FeatureClass>("featureClassSelectionCriteria");

   using (RowCursor rowCursor = featureClassSelectionCriteria.Search())
   {
    while (rowCursor.MoveNext())
    {
      using (ArcGIS.Core.Data.Row row = rowCursor.Current)
      {
       if (row["Field"].ToString() == "someAtrribute") //e.g., row[city] = "Chicago"
       {
        Feature feature = rowCursor.Current as Feature;

        Geometry geometry = feature.GetShape(); //Get Chicago's shape point, polygon or line

       var spatialQuery = new SpatialQueryFilter() { FilterGeometry = geometry, SpatialRelationship = SpatialRelationship.Intersects };
      var selectedFeatures = featureClassToBeSelected.Select(spatialQuery, SelectionType.ObjectID, SelectionOption.Normal); //selected features inside Chicago

      using (RowCursor rowCursorPB = selectedFeatures.Search())
      {
       while (rowCursorPB.MoveNext())
       {
        using (ArcGIS.Core.Data.Row rowPropBoundsPB = rowCursorPB.Current)
        {
        //Go through all selected features based on spatial query
        //Do something with selected features 
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            });

 

0 Kudos