I want to join an input feature class (~11,000 polygons) with another feature class (~31,000,000 polygons). When I do this through ArcMaps 'Join - based on spatial location' tool, it takes quite long but eventually succeeds (adding 'Sum' for all joined fields). I monitored memory consumption throughout and it seems 'healthy' to me (not even going close to my 64 GB RAM).
When I try to do the same with the follwing ArcPy code (as adapted from the documentation: https://pro.arcgis.com/en/pro-app/tool-reference/analysis/spatial-join.htm):
outfc = "VG250_GEM_WBUILD"
inputFeature = "VG250_GEM"
joinFeature = "buildings_all"
fieldmappings = arcpy.FieldMappings()
# Add all fields from inputs.
fieldmappings.addTable(inputFeature)
fieldmappings.addTable(joinFeature)
# set sum area field
areaFieldIndex = fieldmappings.findFieldMapIndex("Area")
fieldmap = fieldmappings.getFieldMap(areaFieldIndex)
# Get the output field's properties as a field object
field = fieldmap.outputField
# Rename the field and pass the updated field object back into the field map
field.name = "sum_area"
field.aliasName = "sum_area"
fieldmap.outputField = field
# Set the merge rule to mean and then replace the old fieldmap in the mappings object
# with the updated one
fieldmap.mergeRule = "sum"
fieldmappings.replaceFieldMap(areaFieldIndex, fieldmap)
# Delete fields that are no longer applicable
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("osm_id"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("name"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("code"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("type"))
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex("fclass"))
arcpy.SpatialJoin_analysis(inputFeature, joinFeature, outfc, "#", "#", fieldmappings)
I obtain the following error message after around 10 minutes:
Runtime error Traceback (most recent call last): File "", line 1, in File "C:\tmp.py", line 259, in
main() File "C:\tmp.py", line 251, in main
calc() File "C:\tmp.py", line 105, in calc
arcpy.SpatialJoin_analysis(inputFeature, joinFeature, outfc, "#", "#", fieldmappings) File "c:\program files (x86)\arcgis\desktop10.7\arcpy\arcpy\analysis.py", line 533, in SpatialJoin raise e ExecuteError: ERROR 000426: Out Of Memory ERROR 000426: Out Of Memory Failed to execute (SpatialJoin).
What's strange about it is that, again, as far I can tell from the task manager, it's nowhere close from actually running out of my memory.
So, I believe I'm doing exactly the same thing through ArcPy as through the GUI, yet getting no result. What might cause these differences? How to troubleshout this?
Edit: I'm using ArcGIS Desktop 10.7.1 and the following Python version is used:
2.7.16 (v2.7.16:413a49145e, Mar 4 2019, 01:30:55) [MSC v.1500 32 bit (Intel)]
No comments:
Post a Comment