4

I feel like this has to be on the internet somewhere, but I haven't been able to find it.

I'm attempting to perform a spatial join on a polygon and point layer. My goal is to push the polygon's ID to each point that it contains. In PostGIS, it might look close to this: SELECT a.*, b.* FROM a, b WHERE ST_CONTAINS(a, b).

I have:

  1. A polygon IFeatureClass, from a geodatabase
  2. A point IFeatureClass, from a geodatabase
  3. The name of the polygon field

I would like to turn this into a point IFeatureClass with an extra field.

My question: How do I do this? Bonus points for links to relevant documentation.

3

It's possible to do it with the Geoprocessor in ArcObjects like this:

public static void SpatialJoiner(IFeatureClass sourceFC, IFeatureClass joinFC)
{
    Geoprocessor GP = new Geoprocessor();
    ESRI.ArcGIS.AnalysisTools.SpatialJoin spatialJoin = new ESRI.ArcGIS.AnalysisTools.SpatialJoin();
    spatialJoin.join_features = joinFC;
    spatialJoin.target_features = sourceFC;
    spatialJoin.join_type = "KEEP_COMMON";
    spatialJoin.match_option = "WITHIN";
    spatialJoin.fieldmapping = fieldMapping;
    spatialJoin.out_feature_class = @"c:\yourPath\your.gdb\outfile";
    GP.Execute(spatialJoin,null);
}

Spatial Join class documentation: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Overview/00470000328n000000/

Note that the "fieldmMapping" object needs to be constructed and populated with the IGPFieldMapping interface:

IGPFieldMapping fieldMapping = new GPFieldMappingClass();

Field Mapping Documentation: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//004800000194000000

1
2

One approach is to do this through the geoprocessor.

You can run geoprocessing tools from ArcObjects using these general steps:

  1. Add a reference to ESRI.ArcGIS.Geoprocessing to your project. This is the only reference you need if you use the geoprocessing assembly.
  2. Create the geoprocessor object.
  3. Add the path to the custom toolbox if you are running a custom tool.
  4. Create an IVariantArray and populate it with tool parameter values. The IVariantArray is available through the esriSystem library.
  5. Call the Execute method on the geoprocessor.

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.