Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 3 down vote accepted

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";

Spatial Join class documentation:

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

IGPFieldMapping fieldMapping = new GPFieldMappingClass();

Field Mapping Documentation:

share|improve this answer
If you're curious about the match_option values available, check this page (10.0) or this page (10.1). The docs linked in the answer didn't elaborate deeply on the match_option. Thanks to this question for the tip. – elrobis Dec 5 '12 at 18:05

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.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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