I have a hard time with field mapping and the only form I seem to understand is the following but it also seems to not work, maybe I doing it wrong but here is what I found. Using a code like below
PIN <SPAN class="string token">"PIN"</SPAN> true true false <SPAN class="number token">13</SPAN> Text <SPAN class="number token">0</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="punctuation token">,</SPAN>First<SPAN class="punctuation token">,</SPAN><SPAN class="comment token">#, {0}, PIN,-1,-1;</SPAN>
ACRES <SPAN class="string token">"ACRES"</SPAN> true true false <SPAN class="number token">4</SPAN> Double <SPAN class="number token">0</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="punctuation token">,</SPAN>First<SPAN class="punctuation token">,</SPAN><SPAN class="comment token">#, {0}, ACRES,-1,-1;</SPAN>
PARCEL <SPAN class="string token">"PARCEL"</SPAN> true true false <SPAN class="number token">50</SPAN> Text <SPAN class="number token">0</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="punctuation token">,</SPAN>First<SPAN class="punctuation token">,</SPAN>"<SPAN class="comment token">#",{0}, PARCEL,-1,-1;</SPAN>
PARCELS <SPAN class="string token">"PARCELS"</SPAN> true true false <SPAN class="number token">200</SPAN> Text <SPAN class="number token">0</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="punctuation token">,</SPAN>Join<SPAN class="punctuation token">,</SPAN><SPAN class="string token">","</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN> PARCEL<SPAN class="punctuation token">,</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SpatialJoin_analysis<SPAN class="punctuation token">(</SPAN>Par<SPAN class="punctuation token">,</SPAN> Par1<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"BlahTest"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"JOIN_ONE_TO_ONE"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"KEEP_ALL"</SPAN><SPAN class="punctuation token">,</SPAN>Layers1<SPAN class="punctuation token">(</SPAN>Par1<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"INTERSECT"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
I found that the output had 19 parcels inside the "PARCELS" field and it looked incorrect. So I opened up Arcmap and used select by location with the same spatial selection method "intersect" and selected 25. So I would like to use spatial join with Dictionaries or Select By Location if possible but my problem is how to use the merge rule and delimiter to update the fields. How would I apply the code I am using to use Dictionaries or Select By Location?
Outcome of field PARCELS should be something like the following.
PIN12345,PIN12346,PIN12347, PIN12348, etc.
arcpy<SPAN class="punctuation token">.</SPAN>SpatialJoin_analysis<SPAN class="punctuation token">(</SPAN>updateFC<SPAN class="punctuation token">,</SPAN> Par<SPAN class="punctuation token">,</SPAN> sj<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"JOIN_ONE_TO_ONE"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"KEEP_ALL"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># define the field list from the spatial join</SPAN>
sourceFieldsList <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"TARGET_FID"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Parcel_1"</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># define the field list to the original Parcels</SPAN>
updateFieldsList <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"OID@"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"PARCELS"</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># populate the dictionary from the polygon</SPAN>
valueDict <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN>r<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">(</SPAN>r<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> r <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>sj<SPAN class="punctuation token">,</SPAN> sourceFieldsList<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN>updateFC<SPAN class="punctuation token">,</SPAN> updateFieldsList<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> updateRows<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> updateRow <SPAN class="keyword token">in</SPAN> updateRows<SPAN class="punctuation token">:</SPAN>
keyValue <SPAN class="operator token">=</SPAN> updateRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">if</SPAN> keyValue <SPAN class="keyword token">in</SPAN> valueDict<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> n <SPAN class="keyword token">in</SPAN> range <SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN>len<SPAN class="punctuation token">(</SPAN>sourceFieldsList<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
updateRow<SPAN class="punctuation token">[</SPAN>n<SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> valueDict<SPAN class="punctuation token">[</SPAN>keyValue<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN>n<SPAN class="number token">-1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token">#How do update the field to include multi values from the selection by location?</SPAN>
updateRows<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>updateRow<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">del</SPAN> valueDict<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>targetLayer = "In_memory\tempTarget"
arcpy.MakeFeatureLayer_management(target, targetLayer)
MergetLayer = "In_memory\tempMerge"
arcpy.MakeFeatureLayer_management(Merge2,MergetLayer)
with arcpy.da.SearchCursor(Merge2,["SHAPE@", "PARCEL"]) as cursorSearch:
for row in cursorSearch:
arcpy.SelectLayerByLocation_management (targetLayer, "INTERSECT", row[0])
with arcpy.da.UpdateCursor(targetLayer,["SHAPE@", "PARCELS"]) as cursorUpdate:
for row2 in cursorUpdate:
row2[1] = row[1] #How do update the field to include multi values from the selection by location?
cursorUpdate.updateRow(row2)<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>