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:
- A polygon IFeatureClass, from a geodatabase
- A point IFeatureClass, from a geodatabase
- 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.
Answer
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
No comments:
Post a Comment