I have two feature classes. The first is a point file, derived from a raster, with the values for slope of the terrain. The second is a shapefile of polygons. What I want to do is spatially join the points to polygons using the ONE_TO_ONE join option, and for each polygon contain an average value of the slope of all the points that are within the polygon.
The problem is when I execute the following code, the GRID_CODE field (slope values from the points shapefile) is empty for the output feature class.
import arcpy print "\n\n************************\n" slopes = r'C:\Users\slope_to_pt.shp' polygons = r'C:\Users\polygons.shp' outfc = r'C:\Users\slopeToPolygons' print "Creating Field Map" #create the field map myMap = arcpy.FieldMappings() myMap.addTable(polygons) myMap.addTable(slopes) fIndex = myMap.findFieldMapIndex("GRID_CODE") print "GRID_CODE index is:", fIndex #create new field map with the "GRID_CODE" field NewFieldMap = myMap.getFieldMap(fIndex) #set the merge rule NewFieldMap.mergeRule = 'Mean' print "merge rule is:", str(NewFieldMap.mergeRule) myMap.replaceFieldMap(fIndex,NewFieldMap) print "performing spatial join..." arcpy.SpatialJoin_analysis(polygons, slopes, slopeToPolygons, "JOIN_ONE_TO_ONE", "", myMap, "CONTAINS")
Again, when I run this code the GRID_CODE entry for each polygon is null, when it should be the average of all the values of the points that are within the polygon. Whenever I run it with a "JOIN_ONE_TO_MANY" option, it populates the GRID_CODE field; however, I want to perform a ONE_TO_ONE join.
Additional Information: the datatype for the GRID_CODE field is 'double'
Any ideas on why it wouldn't populated the GRID_CODE field for each polygon with the averages from the points?