Just performed a spatial join operation on a polygon layer (made of 500 grids cells) and point layer (1 million points). The aim was to find the sum of a field in the points layer (field AREA) during the spatial join process. However, the result of the spatial join output shows 0 for all the rows. Below is the code used.

import arcpy

arcpy.env.overwriteOutput = True

point = r"C:\Example\Scratch.gdb\trees"
grid = r"C:\Example\Scratch.gdb\grid"
grid_join = r"C:\Example\Scratch.gdb\grid_join"

#Make feature layers
arcpy.MakeFeatureLayer_management(point, "point_lyr")
arcpy.MakeFeatureLayer_management(grid, "grid_lyr")

arcpy.SelectLayerByAttribute_management("point_lyr", "NEW_SELECTION", """ "TYPE" = 'Mangrove' """)
arcpy.FeatureClassToFeatureClass_conversion("point_lyr", "in_memory", "tree_new")
tree_new = r'in_memory\tree_new'

arcpy.SpatialJoin_analysis(grid, tree_new, grid_join, "JOIN_ONE_TO_ONE", "KEEP_ALL", "AREA \"AREA\" true true true 8 Double 6 7 ,Sum,#,C:\\Example\\Scratch.gdb\\in_memory\\tree_new,AREA,-1,-1", "COMPLETELY_CONTAINS", "", "")
  • What's treeCenter_C in the last line(spatialJoin). you create a new layer named "treeCenter_C" as a string ? Does selectbylocation selects any feature? – BBG_GIS Nov 20 '17 at 21:02
  • I apologise for the typographical error. That's corrected now. tree_new is the temporary layer saved in memory. – user109472 Nov 20 '17 at 21:16
  • What's the result of Select by attribute? – BBG_GIS Nov 20 '17 at 21:19
  • It shows the trees classed as Mangrove. This is a unique class of interest amongst five other classes. – user109472 Nov 20 '17 at 21:22
  • AREA is a reserved word, have a look for AREA_1 (or 2 or _1_1) in your table and see if that matches your point AREA field then use Summary Statistics resources.arcgis.com/en/help/main/10.2/index.html#//… to find the sum of AREA_X fields for each unique polygon ID (Statistics field AREA_X : Type SUM, Case field of polygon ID). – Michael Stimson Nov 20 '17 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.