0

I'm trying to select a county feature from a nationwide counties layer using Geoprocessor's managed SelectLayerByLocation coclass:

internal static void GetCountyName(IPoint centerpoint, out string countyName)
{
    Geoprocessor gp = new Geoprocessor();
    SelectLayerByLocation selectByLocation = new SelectLayerByLocation();
    selectByLocation.in_layer = countiesLayer; //IFeatureLayer in mxd
    selectByLocation.select_features = centerpoint; //cause of error
    try
        {
            gp.Execute(selectByLocation, null);
            //countyName will be retrieved from value of selected feature
        }
    catch (Exception)
        {
            string message = "";
            for (int i = 0; i < gp.MessageCount; i++)
                message += gp.GetMessage(i) + "\n";
            MessageBox.Show(message);
        }
}

The MessageBox showed me this:

enter image description here

I found here that the "select_features" parameter requires either a FeatureLayer or FeatureClass:

enter image description here

But I know that ArcPy has PointGeometry specifically so that you don't have to create a stored feature class just to use it as a geoprocessing parameter:

In many geoprocessing workflows, you may need to run a specific operation using coordinate and geometry information but don't necessarily want to go through the process of creating a new (temporary) feature class, populating the feature class with cursors, using the feature class, then deleting the temporary feature class. Geometry objects can be used instead for both input and output to make geoprocessing easier.

Is there an option like this for ArcObjects?

  • 1
    I thought this was useful: edndoc.esri.com/arcobjects/9.2/NET/… ...the newer resource: desktop.arcgis.com/en/arcobjects/latest/net/… – T. Wayne Whitley Feb 24 '17 at 10:22
  • 1
    What are you hoping to achieve by this selection? I would recommend you use ISpatialFilter instead to return features from your county layer - your procedure returns None so I can't see if you want to select on map, get the name or return features. Geoprocessor objects are fine for python and can shortcut some operations but they're slow, you're much better off using the ArcObjects as intended for performance and stability. – Michael Stimson Feb 27 '17 at 22:16
2

I believe the select_features input needs to be an IFeatureLayer object.

If you want to avoid creating a feature layer in code and adding your point to it then you can use the ITopologicalOperater interface. Code example here: Determine if Point is in feature class attribute table

0

Yes, ISpatialFilter was what I needed. It allows you to input a geometry to perform a selection without having to store a Feature Layer.

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.