5

I am creating a tool which the user will select point or line features from the map and it will display their names in a list then after clicking on any of these features from the list, it will show the intersected polygons in another list.

The problem that I don't know how to do a SpatialFilter to do this intersecting functionality, which it will be done like the one in the Select By Location tool.

7

Please have a look IFeatureClass.Search Method

To get feature by mouse click:

public List<IFeature> Search(IPoint mousePoint, double buffer, IFeatureClass featureClass)
{
    var envelope = mousePoint.Envelope;
    envelope.Expand(buffer, buffer, false);
    var geodataset = (IGeoDataset)featureClass;
    string shapeFieldName = featureClass.ShapeFieldName;
    Geodatabase.ISpatialFilter spatialFilter = new Geodatabase.SpatialFilter();
    spatialFilter.Geometry = envelope;
    spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
    spatialFilter.set_OutputSpatialReference(shapeFieldName, geodataset.SpatialReference);

    Geodatabase.IFeatureCursor featureCursor = ArcFeatureClass.Search(spatialFilter, false);

    var features = new List<IFeature>();
    Geodatabase.IFeature feature;
    while ((feature = featureCursor.NextFeature()) != null)
        features.Add(new Feature(feature));
    return features;
}
|improve this answer|||||
  • Thanks, I will check this now but I am wondering about what spatialFilter.set_OutputSpatialReference does ? – Seem Feb 6 '13 at 10:05
  • It sets spatial reference for Query – Emi Feb 6 '13 at 10:10
  • I am working on it and I have some issues one of them that I am not using envelop because I have the ObjectId of the (point/line) feature and I have to get the intesection through this Id – Seem Feb 6 '13 at 13:14
  • Is it like, you have a feature and you need other features that are at the same location? – Emi Feb 7 '13 at 3:30
  • Thanks very much, your answer helped me a lot to find out the answer. – Seem Feb 7 '13 at 9:06

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.