<?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: Please help with update cursor. So close I can taste it. in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/please-help-with-update-cursor-so-close-i-can/m-p/173480#M5822</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did you get an error message?&lt;/P&gt;&lt;P&gt;I am surprised it gets past your paths... they need to be in raw format ie&amp;nbsp;&amp;nbsp; r"c:\yourpathhere\your.gdb"&lt;/P&gt;&lt;P&gt;and you would be advised to use paths that don't contain spaces or other stuff.&lt;/P&gt;&lt;P&gt;for paths &lt;A href="https://community.esri.com/migration-blogpost/55463"&gt;Filenames and file paths in Python&lt;/A&gt;&lt;/P&gt;&lt;P&gt;code formatting &lt;A href="https://community.esri.com/migration-blogpost/55181"&gt;Code Formatting... the basics++&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 16 May 2016 12:46:39 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2016-05-16T12:46:39Z</dc:date>
    <item>
      <title>Please help with update cursor. So close I can taste it.</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/please-help-with-update-cursor-so-close-i-can/m-p/173479#M5821</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I need some help with this script I am developing. I need the update cursor to overwrite the empty LOCALITY values in TWB_Property with the ADMINAREA from TWB_Suburbs that I have turned into a list. I know the code is a little messy and I also can not figure out how to display it all using this forum. Any help will be appreciated. Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;code begins below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import modules
import arcpy
import os

#Set workspace geodatabase
arcpy.env.workspace = "C:\Users\Harry\Documents\Uni\Semester 1 2016\GIS3407 GIS Programming and Visualisation\Assignment 2\Assignment2.gdb"

#Start an editing session
edit = arcpy.da.Editor("C:\Users\Harry\Documents\Uni\Semester 1 2016\GIS3407 GIS Programming and Visualisation\Assignment 2\Assignment2.gdb")
edit.startEditing(False, False)

# Create a list of suburbs
# Create an empty list
localityList = []

#Create the search cursor
rows = arcpy.SearchCursor("TWB_Suburbs")

#Move to the first row
row = rows.next()

#Append the list with the selected locality name
while row:
&amp;nbsp;&amp;nbsp;&amp;nbsp; localityList.append(str(row.ADMINAREA))
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Move to the next row
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next()

print(str(len(localityList)) + " &amp;lt;-- # of suburbs")

del row, rows
# Make a layer of all of the properties with no locality value
# Create query
nullQuery = '"LOCALITY" = \' \''

# Create layer
nullLayer = arcpy.MakeFeatureLayer_management("TWB_Property", "TWB_Property_Layer", nullQuery)
field = "LOCALITY"
fc = "TWB_Property_Layer"

#Counter
counter = 0

# Select by location
indexCounter = 0
print localityList
for counter in range(0,len(localityList)):
&amp;nbsp;&amp;nbsp;&amp;nbsp; localityQuery = '"ADMINAREA" = ' + '\''+ localityList[indexCounter] + '\''
&amp;nbsp;&amp;nbsp;&amp;nbsp; localityLayer = arcpy.MakeFeatureLayer_management("TWB_Suburbs", "TWB_Sububs_Layer", localityQuery)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management("TWB_Property_Layer", "WITHIN", "TWB_Sububs_Layer")

&amp;nbsp;&amp;nbsp;&amp;nbsp; parcelList = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; sRows = arcpy.SearchCursor("TWB_Property_Layer")
&amp;nbsp;&amp;nbsp;&amp;nbsp; sRow = sRows.next()

&amp;nbsp;&amp;nbsp;&amp;nbsp; while sRow:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; parcelList.append(sRow)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sRow = sRows.next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; print ("There are " + str(len(parcelList)) + " empty locality fields in " + localityList[indexCounter])
&amp;nbsp;&amp;nbsp;&amp;nbsp; numberParcel = int(len(parcelList))
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(fc, field) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for uRow in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if uRow[0] == '':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uRow[0] = str(localityList[indexCounter])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(uRow)

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management("TWB_Sububs_Layer")
&amp;nbsp;&amp;nbsp;&amp;nbsp; counter += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; indexCounter += 1

del uRow

arcpy.Delete_management("TWB_Property_Layer")
arcpy.Delete_management("TWB_Sububs_Layer")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:58:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/please-help-with-update-cursor-so-close-i-can/m-p/173479#M5821</guid>
      <dc:creator>HarryKlein</dc:creator>
      <dc:date>2021-12-11T08:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: Please help with update cursor. So close I can taste it.</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/please-help-with-update-cursor-so-close-i-can/m-p/173480#M5822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did you get an error message?&lt;/P&gt;&lt;P&gt;I am surprised it gets past your paths... they need to be in raw format ie&amp;nbsp;&amp;nbsp; r"c:\yourpathhere\your.gdb"&lt;/P&gt;&lt;P&gt;and you would be advised to use paths that don't contain spaces or other stuff.&lt;/P&gt;&lt;P&gt;for paths &lt;A href="https://community.esri.com/migration-blogpost/55463"&gt;Filenames and file paths in Python&lt;/A&gt;&lt;/P&gt;&lt;P&gt;code formatting &lt;A href="https://community.esri.com/migration-blogpost/55181"&gt;Code Formatting... the basics++&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 May 2016 12:46:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/please-help-with-update-cursor-so-close-i-can/m-p/173480#M5822</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-05-16T12:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: Please help with update cursor. So close I can taste it.</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/please-help-with-update-cursor-so-close-i-can/m-p/173481#M5823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First just a piece of advice - Python string substitution is much easier than creating queries by adding strings:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;localityQuery = '"ADMINAREA" = ' + '\''+ localityList[indexCounter] + '\'' 
localityQuery = '"ADMINAREA" = \'{}\''.format(localityList[indexCounter])&amp;nbsp; # better&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also you may do better in the update query by checking for null values (not just blank):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(fc, field) as cursor: 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for uRow in cursor: 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if uRow[0] in ['', None]: 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uRow[0] = str(localityList[indexCounter]) 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(uRow)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:58:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/please-help-with-update-cursor-so-close-i-can/m-p/173481#M5823</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T08:58:31Z</dc:date>
    </item>
  </channel>
</rss>

