Ryan,
Did you ever find a solution to your question? Which option did you choose?
What's wrong with Spatial Join?
Darren,
In my workflow option 3 might be a better an option. Spatial Join produces a whole new feature class as an output, instead of transferring an attribute from a selected polygon to the point features within the selected polygon. Thoughts?
Oh I see. It probably depends somewhat on the size of the datasets. Suppose there are 1000 points. You could do 1000 individual selections/field calculations, or 1 spatial join (to an in-memory feature class if you don't want to keep it) then 1 join then 1 field calculation. I'm guessing the second option is faster, but haven't tested.
Darren,
I know I am not an efficient python scripter, so bear with me. I have attempted to script it with spatial join. The goal is to calculate the zone of a concern for only the ones that the zone field is null. Both feature classes are in an enterprise environment (the concerns and the zones). Here is what I have so far from testing on a file geodatabase. I am not sure it is joining properly and the field calculator dies. Any suggestions?
# import modules
import arcpy
# Set workspaces
workspace = r'C:\ESRITest\GeoReportingSystem\Testing9116\Testing9116.gdb'
outWorkspace = r'C:\ESRITest\GeoReportingSystem\Testing9116\Scratch.gdb'
targetFeatures = r'C:\ESRITest\GeoReportingSystem\Testing9116\Testing9116.gdb\GeoReporting'
joinFeatures = r'C:\ESRITest\GeoReportingSystem\Testing9116\Testing9116.gdb\GRSAldermanic'
outfc = r'C:\ESRITest\GeoReportingSystem\Testing9116\Scratch.gdb\AldermanicSJ'
fieldmappings = arcpy.FieldMappings()
fieldmappings.addTable(targetFeatures)
fieldmappings.addTable(joinFeatures)
# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script
# The following inputs are layers or table views: "GeoReporting Features", "GRSAldermanic"
arcpy.SpatialJoin_analysis(target_features=targetFeatures, join_features=joinFeatures, out_feature_class=outfc, join_operation="JOIN_ONE_TO_ONE", join_type="KEEP_COMMON", field_mapping=fieldmappings, match_option="INTERSECT", search_radius="", distance_field_name="")
print "Done with Spatial Join"
# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script
# The following inputs are layers or table views: "AldermanicSJ"
arcpy.DeleteField_management(in_table=outfc, drop_field="SpecificConcern;DescriptionOfConcern;ReportingEmail;DateClosed;ConcernStatus;PriorityLevel;PrimaryDepartment;PrimaryContact;PrimaryInformation;DeptLogging;ReportingMethod;FollowUpRequest;FollowUpContactInfo;AldermanicDistrict;ApproriateYN;NUMVOTES;DaysToClose;Match_Addr;Loc_Name;created_user;created_date;last_edited_user;last_edited_date;Address;Visibility;Report_ID;DISTRICTID")
print "Done with Deleting Fields"
arcpy.MakeFeatureLayer_management(outfc, "outfc_view")
arcpy.MakeFeatureLayer_management(targetFeatures, "GRE_view")
# arcpy.MakeFeatureLayer_management(targetFeatures, "GRE_view")
arcpy.AddJoin_management("GRE_view", "ConcernID", "outfc_view", "ConcernID")
print "Joined Up Sir"
fieldName1 = "GRE_view.AldermanicDistrict"
fieldName2 = "!outfc_view.NAME!"
# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script
# The following inputs are layers or table views: "GeoReporting Features"
arcpy.CalculateField_management(in_table=targetFeatures, field=fieldName1, expression=fieldName2, expression_type="PYTHON", code_block="")
print "Field Calculation Done"
arcpy.RemoveJoin_management(in_layer_or_view=targetFeatures)
print "Removed Join"
arcpy.DeleteFeatures_management(outfc)
print "Spatial Join feature class deleted"
Perhaps try expression_type="PYTHON_9.3". If that doesn't work, can you provide the error message?
ExecuteError: Failed to execute. Parameters are not valid.
Error 000728: Field GRE_view.AldermanicDistrict does not exist within table
Failed to to execute (CalculateField).
Have you tried running through the workflow manually to see exactly what's going on? You could also verify the field names like:
print [i.name for i in arcpy.ListFields('GRE_view')]