1

I have two Point Feature Classes - Say FC1 and FC2 - added in the current map

I want to Select Features from FC1 that intersect with Features of FC2

This can be easily done with ArcMap's Select By Location (Providing FC1 in target layer, and FC2 in source layer)

However, when I'm trying to do it in ArcObjects, using IFeatureClass.Search Method and following this example I have the following code

public ESRI.ArcGIS.Geodatabase.IFeatureCursor PerformSpatialQuery(ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass, ESRI.ArcGIS.Geometry.IGeometry searchGeometry, ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum spatialRelation, System.String whereClause)
{
  // create a spatial query filter
  ESRI.ArcGIS.Geodatabase.ISpatialFilter spatialFilter=new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();

  // specify the geometry to query with
  spatialFilter.Geometry=searchGeometry;

  // specify what the geometry field is called on the Feature Class that we will be querying against
  System.String nameOfShapeField=featureClass.ShapeFieldName;
  spatialFilter.GeometryField=nameOfShapeField;

  // specify the type of spatial operation to use
  spatialFilter.SpatialRel=spatialRelation;

  // create the where statement
  spatialFilter.WhereClause=whereClause;

  // perform the query and use a cursor to hold the results
  ESRI.ArcGIS.Geodatabase.IQueryFilter queryFilter=new ESRI.ArcGIS.Geodatabase.QueryFilterClass();
  queryFilter=(ESRI.ArcGIS.Geodatabase.IQueryFilter)spatialFilter;
  ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor=featureClass.Search(queryFilter, false);

  return featureCursor;
}

In this function, I have to provide a feature class and a IGeometry as parameters, rather than two Feature Classes similar to Select By Location

Is there any other method, that simply takes two Feature Classes as whole and return the intersecting geometry from one Feature class? Or do I have to Iterate through the complete Feature Class and provide each point's geometry one by one?

  • One important thing to note is that selecting points with points mostly returns less points than it should, often even an empty selection, as geometries must precisely match to select.. I use ITopologicalOperator to buffer the selecting point by a very small amount and use the buffer polygon to do the actual selection; the value of very small amount is subjective, 1mm in a projected coordinate system seems to work well, selecting the matches and not including non-matches, 1e-07 for geographic works OK for me - experiment a bit and see what values work for you. – Michael Stimson Mar 8 at 3:09
  • @MichaelStimson Thanks for the suggestion. Although my layers on which I am performing the "select" are basically the same layers. One layer is from a geometric network, and the other is the source layer from which the geometric network was created. But I will still look into using buffers and check the difference. – Tayyab Mir Mar 10 at 3:55
1

I solved this by iterating through my feature class and adding all the points to a MultiPoint. Then I casted this multipoint into IGeometry and sent it to the function.

Code: (I already had a tracedJunct[] array of the points of FC2 in the code which got useful)

Multipoint searchGeom_MultiPoint = new Multipoint();
for (int i = 0; i < juncCount; i++)
    searchGeom_MultiPoint.AddPoint((IPoint)tracedJunct[i]);

IGeometry searchGeom = (IGeometry) searchGeom_MultiPoint;

Let me know if there is a better solution.

  • 2
    You can use IMap.SelectByShape on each feature and set the ISelectionEnvironment.CombinationMethod = esriSelectionResult.esriSelectionResultAdd. It probably won't be noticeably faster without a ton of features, but it will be cleaner. – danielm Mar 4 at 17:15
  • That's very similar to the method I use, I am assuming you set searchGeom.SpatialReference after casting from the multipoint.. when using polylines/polygons often it's best to use ITopologicalOperator.Union to make a super geometry for selection; as @danielm suggests you can also iterate the selecting geometries (point, line or polygon), starting with an empty ISelectionSet (IFeatureClass.Select with esriSelectionOption.esriSelectionOptionEmpty) Combine with esriSetOperation.esriSetUnion for each selecting geometry then create a cursor with ISelectionSet.Search (null,false,featureCursor). – Michael Stimson Mar 8 at 3:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.