I want to perform a spatial join to find the join point (a node in the code below) that is closest to a target point (a consumer in the code below). In the result, I only need certain attributes from both input features:
- node: "ID", "name"
- consumer "ID", "a_value"
For doing this in arcpy it seems that I need a
FieldMappings object to specify which columns I want to keep, but I can't figure out how. There are few examples in the documentation, but they appear to be more complex than what I need (merge rules an all that)
How do I perform a spatial join in arcpy where the result only contains specific columns?
fieldmappings = arcpy.FieldMappings() fieldmap_consumer = arcpy.FieldMap() fieldmap_node = arcpy.FieldMap() # How to specify columns to be included in join result? arcpy.SpatialJoin_analysis(target_features = paramConsumerFeatures, join_features = paramNodeFeatures, out_feature_class = paramWS + "\\" + paramOutFile + "_tmpjoin", join_operation = "JOIN_ONE_TO_ONE", join_type = "KEEP_ALL", field_mapping = fieldmappings, match_option="CLOSEST", distance_field_name="join_dist")