<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Spatial Join &amp;amp; Dictionary transfer in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1196460#M65072</link>
    <description>&lt;P&gt;One thing I see is that you are not setting the upd_row[#] to anything, == is to compare, not set.&lt;/P&gt;&lt;P&gt;Try something like this, see if it works:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;    with arcpy.da.UpdateCursor(pointLayer,["SHAPE@","SiteCity"]) as upd_cur:
        for upd_row in upd_cur:
            try:
                if search_feats[upd_row[0]][1] == "Sea":              
                    upd_row[1] = "Seattle"
                elif search_feats[upd_row[0]][1] == "Spo":
                    upd_row[1] = "Spokane"
                elif search_feats[upd_row[0]][1] == "Tac":
                    upd_row[1] = "Tacoma"
                upd_cur.updateRow(upd_row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jul 2022 17:33:19 GMT</pubDate>
    <dc:creator>RhettZufelt</dc:creator>
    <dc:date>2022-07-27T17:33:19Z</dc:date>
    <item>
      <title>Spatial Join &amp; Dictionary transfer</title>
      <link>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1196406#M65071</link>
      <description>&lt;P&gt;I have a two layers, I need to transfer a field attribute to the other layer of the selected feature.&lt;/P&gt;&lt;P&gt;The EMS layer has a filed "SiteCity" and so does the "Ass_Parcels" layer.&lt;/P&gt;&lt;P&gt;I need to transfer the Ass_Parcels SiteCity attribute to the EMS's SiteCity field.&lt;/P&gt;&lt;P&gt;I have the following but I am not able to get it to work.&lt;/P&gt;&lt;P&gt;I don't get an error, but the EMs's SiteCity field doesn't get populated.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;pointLayer = 'EMS'
parcel = 'Ass_Parcels'

ptCount = int(arcpy.GetCount_management(pointLayer).getOutput(0))

dsc = arcpy.Describe(pointLayer)     
selection_set = dsc.FIDSet             
if len(selection_set) == 0:
    print "There are no features selected"

elif ptCount &amp;gt;= 1:
elif ptCount &amp;gt;= 1:

    arcpy.SpatialJoin_analysis(pointLayer, parcel, sjpoints)
    search_feats ={f[0]:(f[1:]) for f in arcpy.da.SearchCursor(sjpoints,'SiteCity_1')}
    print(search_feats)

    with arcpy.da.UpdateCursor(pointLayer,["SHAPE@","SiteCity"]) as upd_cur:
        for upd_row in upd_cur:
            try:
                if search_feats[upd_row[0]][1] == "Sea":              
                    upd_row[1] == "Seattle"
                elif search_feats[upd_row[0]][1] == "Spo":
                    upd_row[1] == "Spokane"
                elif search_feats[upd_row[0]][1] == "Tac":
                    upd_row[1] == "Tacoma"
                upd_cur.updateRow(upd_row)
            except:
               continue&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 15:58:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1196406#M65071</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2022-07-27T15:58:41Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join &amp; Dictionary transfer</title>
      <link>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1196460#M65072</link>
      <description>&lt;P&gt;One thing I see is that you are not setting the upd_row[#] to anything, == is to compare, not set.&lt;/P&gt;&lt;P&gt;Try something like this, see if it works:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;    with arcpy.da.UpdateCursor(pointLayer,["SHAPE@","SiteCity"]) as upd_cur:
        for upd_row in upd_cur:
            try:
                if search_feats[upd_row[0]][1] == "Sea":              
                    upd_row[1] = "Seattle"
                elif search_feats[upd_row[0]][1] == "Spo":
                    upd_row[1] = "Spokane"
                elif search_feats[upd_row[0]][1] == "Tac":
                    upd_row[1] = "Tacoma"
                upd_cur.updateRow(upd_row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 17:33:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1196460#M65072</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-07-27T17:33:19Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join &amp; Dictionary transfer</title>
      <link>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1196726#M65078</link>
      <description>&lt;P&gt;Just a note... if you are going to have a long list of if/elif, you can use a dictionary lookup to save you some elifs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;place_dict = {"Sea":"Seattle", "Spo":"Spokane", "Tac":"Tacoma", ...}

for upd_row in upd_cur:
    try:
        upd_row[1] = place_dict.get(search_feats[upd_row[0]][1], upd_row[1])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;... at 3.10 they introduced pattern matching &lt;A href="https://docs.python.org/3.10/whatsnew/3.10.html#pep-634-structural-pattern-matching" target="_blank" rel="noopener"&gt;structural-pattern-matching&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 13:26:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1196726#M65078</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-07-28T13:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join &amp; Dictionary transfer</title>
      <link>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1196780#M65082</link>
      <description>&lt;P&gt;I did catch that after I posted, but I still get the same thing. No errors but nothing is updated. I did look into the field a little and found that the pointLayer "SiteCity" field has domains, not sure if this has any effect or not.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 14:45:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1196780#M65082</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2022-07-28T14:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join &amp; Dictionary transfer</title>
      <link>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1196785#M65083</link>
      <description>&lt;P&gt;Make sure your conditionals are working as expected by adding some print statements&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if search_feats[upd_row[0]][1] == "Sea"
    arcpy.AddMessage(f'{search_feats[upd_row[0]][1]} setting Seattle')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 14:53:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1196785#M65083</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-07-28T14:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join &amp; Dictionary transfer</title>
      <link>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1196802#M65084</link>
      <description>&lt;P&gt;i have tried the following and get this error.&lt;/P&gt;&lt;P&gt;Runtime error SyntaxError: can't assign to operator (&amp;lt;string&amp;gt;, line 35)&lt;/P&gt;&lt;P&gt;Not sure what that means but one thing I did find out about that field is that there is domains to that field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;pointLayer = 'EMS'
parcel = 'Ass_Parcels'

ptCount = int(arcpy.GetCount_management(pointLayer).getOutput(0))

dsc = arcpy.Describe(pointLayer)     
selection_set = dsc.FIDSet             
if len(selection_set) == 0:
    print "There are no features selected"

elif ptCount &amp;gt;= 1:

    arcpy.SpatialJoin_analysis(pointLayer, parcel, sjpoints)
    search_feats ={f[0]:(f[1:]) for f in arcpy.da.SearchCursor(sjpoints,'SiteCity_1')}
    print(search_feats)

##    with arcpy.da.UpdateCursor(pointLayer,["SHAPE@","SiteCity"]) as upd_cur:
##        for upd_row in upd_cur:
##            try:
##                if search_feats[upd_row[0]][1] == "Sea":              
##                    upd_row[1] = "Seattle"
##                elif search_feats[upd_row[0]][1] == "Spo":
##                    upd_row[1] = "Spokane"
##                elif search_feats[upd_row[0]][1] == "Tac":
##                    upd_row[1] = "Tacoma"
##                upd_cur.updateRow(upd_row)
##            except:
##               continue

    place_dict = {"Sea":"Seattle", "Spo":"Spokane", "Tac":"Tacoma"}

    with arcpy.da.UpdateCursor(pointLayer,["SHAPE@","SiteCity"]) as upd_cur:
        for upd_row in upd_cur:
            try:
                upd_row[1] = place_dict.get(search_feats[upd_row[0]][1], upd_row[1])
                upd_cur.updateRow(upd_row)
            except:
               continue&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 15:16:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1196802#M65084</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2022-07-28T15:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join &amp; Dictionary transfer</title>
      <link>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1196822#M65086</link>
      <description>&lt;P&gt;What does the sjpoints table look like?&amp;nbsp; is there a field with the abbreviation and one with the fullname that you are trying to load into the dictionary?&amp;nbsp; If so, you are only loading the SiteCity_1 field into the cursor, but trying to assign the key and value from it?&lt;/P&gt;&lt;P&gt;I believe your issue is probably in this line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;search_feats ={f[0]:(f[1:]) for f in arcpy.da.SearchCursor(sjpoints,'SiteCity_1')}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Not sure what f[1:] is supposed to do, but is only returning an empty set of parrens when I try it.&lt;/P&gt;&lt;P&gt;What does the print(search_feats) show?&amp;nbsp; Probably something like below?&amp;nbsp; If so, that would tell it to update with empty value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;{"Sea":(), "Spo":(), "Tac":()}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If there is a fullname field in sjpoints table, suspect you were looking for something like this (add the other field and remove the colon from f[1]):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;search_feats ={f[0]:(f[1]) for f in arcpy.da.SearchCursor(sjpoints,['SiteCity_1','fullnamefield'])}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just need to make sure the search_feats prints out like:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;{"Sea":"Seattle", "Spo":"Spokane", "Tac":"Tacoma"}&lt;/LI-CODE&gt;&lt;P&gt;Also, describe can slow stuff down a lot, and the GetCountManagement will only return selected records if there is a selection, so no need for the extra load of the describe/compare.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 15:37:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1196822#M65086</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-07-28T15:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join &amp; Dictionary transfer</title>
      <link>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1196831#M65087</link>
      <description>&lt;P&gt;I don't know what they structure of search_feats looks like once its created, but it looks like the only field you have in the SearchCursor isnt a shape(?) "SiteCity_1", but are trying to match the Shape@ in your updatecursor to it since "Shape@" is at the 0 index.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.UpdateCursor(pointLayer,["SHAPE@","SiteCity"])
...
    search_feats[upd_row[0]]&lt;/LI-CODE&gt;&lt;P&gt;Id suggest adding some print statements or debugging to check what values you are getting, and sharing them to this thread if it is still having problems.&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;I think you'll need to get the corresponding code value of string value and use it instead of the string.&lt;/P&gt;&lt;P&gt;You can get the domains and convert it into a dictionary- this should get you started:&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/2.8/arcpy/data-access/listdomains.htm" target="_self"&gt;list domains&lt;/A&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 15:42:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1196831#M65087</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-07-28T15:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join &amp; Dictionary transfer</title>
      <link>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1199421#M65206</link>
      <description>&lt;P&gt;apologizes for the delay response, I got busy with something else.&lt;/P&gt;&lt;P&gt;The print(search_feats), prints {u'Ros': ()}&lt;/P&gt;&lt;P&gt;I have attached the data I am working with, if it helps.&lt;/P&gt;&lt;P&gt;I changed the parcel data to City limits to help with the size of the up loaded file.&lt;/P&gt;&lt;P&gt;I need to update the pointLayer = EMS points2 SiteCity field with the&lt;/P&gt;&lt;P&gt;Parcels =&amp;nbsp; CityLimits1&amp;nbsp;SiteCity field&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;pointLayer = 'EMS_Points2'
city = 'CityLimits1'
sjpoints = "In_memory\sjpoints"

ptCount = int(arcpy.GetCount_management(pointLayer).getOutput(0))

dsc = arcpy.Describe(pointLayer)     
selection_set = dsc.FIDSet             
if len(selection_set) == 0:
    print "There are no features selected"

elif ptCount &amp;gt;= 1:
    #Run the Spatial Join tool, using the defaults for the join operation and join type
    arcpy.SpatialJoin_analysis(pointLayer, city, sjpoints)

    search_feats ={f[0]:(f[0]) for f in arcpy.da.SearchCursor(sjpoints,'SiteCity_1')}
    print(search_feats)

##    with arcpy.da.UpdateCursor(pointLayer,["SHAPE@","SiteCity"]) as upd_cur:
##        for upd_row in upd_cur:
##            try:
##                if search_feats[upd_row[0]][1] == "Sea":              
##                    upd_row[1] = "Seattle"
##                elif search_feats[upd_row[0]][1] == "Spo":
##                    upd_row[1] = "Spokane"
##                elif search_feats[upd_row[0]][1] == "Tac":
##                    upd_row[1] = "Tacoma"
##                upd_cur.updateRow(upd_row)
##            except:
##               continue

    place_dict = {"Sea":"Seattle", "Spo":"Spokane", "Ros":"Roslyn"}

    with arcpy.da.UpdateCursor(pointLayer,["SHAPE@","SiteCity"]) as upd_cur:
        for upd_row in upd_cur:
            try:
                upd_row[1] = place_dict.get(search_feats[upd_row[0]][1], upd_row[1])
                upd_cur.updateRow(upd_row)
            except:
               continue&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2022 16:01:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1199421#M65206</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2022-08-04T16:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join &amp; Dictionary transfer</title>
      <link>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1199443#M65207</link>
      <description>&lt;P&gt;Adding the print statement give the following error.&lt;/P&gt;&lt;P&gt;print (search_feats[upd_row[0]])&lt;BR /&gt;error KeyError: &amp;lt;PointGeometry object at 0x3900e790[0x3900e620]&amp;gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2022 15:58:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1199443#M65207</guid>
      <dc:creator>2Quiker</dc:creator>
      <dc:date>2022-08-04T15:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: Spatial Join &amp; Dictionary transfer</title>
      <link>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1199509#M65209</link>
      <description>&lt;P&gt;That is expected because you are using the feature shape@ at upd_row[0] in your update cursor.&amp;nbsp; Like &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/15530"&gt;@RhettZufelt&lt;/a&gt; pointed to, and I pointed to in previous posts, you need to adjust the fields that you are using in your cursors to get past this and to create a usable dictionary.&lt;/P&gt;&lt;P&gt;I'd highly suggest getting to know how to use the debugger so you can examine what your code is doing and what your variables values are.&amp;nbsp; This would save you a lot of time and increase your knowledge of the language.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2022 17:22:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/spatial-join-amp-dictionary-transfer/m-p/1199509#M65209</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-08-04T17:22:15Z</dc:date>
    </item>
  </channel>
</rss>

