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.
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?
<SPAN class="comment token"># import modules</SPAN> <SPAN class="keyword token">import</SPAN> arcpy <SPAN class="comment token"># Set workspaces</SPAN> workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\ESRITest\GeoReportingSystem\Testing9116\Testing9116.gdb'</SPAN> outWorkspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\ESRITest\GeoReportingSystem\Testing9116\Scratch.gdb'</SPAN> targetFeatures <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\ESRITest\GeoReportingSystem\Testing9116\Testing9116.gdb\GeoReporting'</SPAN> joinFeatures <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\ESRITest\GeoReportingSystem\Testing9116\Testing9116.gdb\GRSAldermanic'</SPAN> outfc <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\ESRITest\GeoReportingSystem\Testing9116\Scratch.gdb\AldermanicSJ'</SPAN> fieldmappings <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>FieldMappings<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> fieldmappings<SPAN class="punctuation token">.</SPAN>addTable<SPAN class="punctuation token">(</SPAN>targetFeatures<SPAN class="punctuation token">)</SPAN> fieldmappings<SPAN class="punctuation token">.</SPAN>addTable<SPAN class="punctuation token">(</SPAN>joinFeatures<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># 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</SPAN> <SPAN class="comment token"># The following inputs are layers or table views: "GeoReporting Features", "GRSAldermanic"</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SpatialJoin_analysis<SPAN class="punctuation token">(</SPAN>target_features<SPAN class="operator token">=</SPAN>targetFeatures<SPAN class="punctuation token">,</SPAN> join_features<SPAN class="operator token">=</SPAN>joinFeatures<SPAN class="punctuation token">,</SPAN> out_feature_class<SPAN class="operator token">=</SPAN>outfc<SPAN class="punctuation token">,</SPAN> join_operation<SPAN class="operator token">=</SPAN><SPAN class="string token">"JOIN_ONE_TO_ONE"</SPAN><SPAN class="punctuation token">,</SPAN> join_type<SPAN class="operator token">=</SPAN><SPAN class="string token">"KEEP_COMMON"</SPAN><SPAN class="punctuation token">,</SPAN> field_mapping<SPAN class="operator token">=</SPAN>fieldmappings<SPAN class="punctuation token">,</SPAN> match_option<SPAN class="operator token">=</SPAN><SPAN class="string token">"INTERSECT"</SPAN><SPAN class="punctuation token">,</SPAN> search_radius<SPAN class="operator token">=</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> distance_field_name<SPAN class="operator token">=</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Done with Spatial Join"</SPAN> <SPAN class="comment token"># 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</SPAN> <SPAN class="comment token"># The following inputs are layers or table views: "AldermanicSJ"</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>DeleteField_management<SPAN class="punctuation token">(</SPAN>in_table<SPAN class="operator token">=</SPAN>outfc<SPAN class="punctuation token">,</SPAN> drop_field<SPAN class="operator token">=</SPAN><SPAN class="string token">"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"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Done with Deleting Fields"</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>outfc<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"outfc_view"</SPAN><SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>MakeFeatureLayer_management<SPAN class="punctuation token">(</SPAN>targetFeatures<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"GRE_view"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># arcpy.MakeFeatureLayer_management(targetFeatures, "GRE_view")</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>AddJoin_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"GRE_view"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"ConcernID"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"outfc_view"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"ConcernID"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Joined Up Sir"</SPAN> fieldName1 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"GRE_view.AldermanicDistrict"</SPAN> fieldName2 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"!outfc_view.NAME!"</SPAN> <SPAN class="comment token"># 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</SPAN> <SPAN class="comment token"># The following inputs are layers or table views: "GeoReporting Features"</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>CalculateField_management<SPAN class="punctuation token">(</SPAN>in_table<SPAN class="operator token">=</SPAN>targetFeatures<SPAN class="punctuation token">,</SPAN> field<SPAN class="operator token">=</SPAN>fieldName1<SPAN class="punctuation token">,</SPAN> expression<SPAN class="operator token">=</SPAN>fieldName2<SPAN class="punctuation token">,</SPAN> expression_type<SPAN class="operator token">=</SPAN><SPAN class="string token">"PYTHON"</SPAN><SPAN class="punctuation token">,</SPAN> code_block<SPAN class="operator token">=</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Field Calculation Done"</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>RemoveJoin_management<SPAN class="punctuation token">(</SPAN>in_layer_or_view<SPAN class="operator token">=</SPAN>targetFeatures<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Removed Join"</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>DeleteFeatures_management<SPAN class="punctuation token">(</SPAN>outfc<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Spatial Join feature class deleted"</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.