Description of this paper

Loading

I need help with arcgis arcpy python coding. I'm trying to assign-(Answered)

Description

Step-by-step Instant Solution


Question

I need help with arcgis arcpy python coding.


I'm trying to assign LOCALITY found in TWB_Suburbs to elements in TWB_Property where LOCALITY is null.


Program seems to run, but it doesn't alter anything.


# Import modules

 

import arcpy

 

import os

 

#Set workspace geodatabase

 

arcpy.env.workspace = "C:\Users\max\Documents\ArcGIS\GIS3407

 

2016\Assignment2\Assignment2database.gdb"

 

#Start an editing session

 

edit = arcpy.da.Editor("C:\Users\max\Documents\ArcGIS\GIS3407

 

2016\Assignment2\Assignment2database.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:

 

localityList.append(str(row.ADMINAREA))

 

#Move to the next row

 

row = rows.next()

 

print(str(len(localityList)) + " <-- # of suburbs")

 

del row, rows

 

# Make a layer of all of the properties with no locality value

 

# Create query

 

nullQuery = '"LOCALITY" = \'\''

 

# Create layer

 

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)):

 

localityQuery = '"ADMINAREA" = ' + '\''+ str(localityList[indexCounter]) +

 

'\''

 

arcpy.MakeFeatureLayer_management("TWB_Suburbs", "TWB_Suburbs_Layer",

 

localityQuery)

 

arcpy.SelectLayerByLocation_management("TWB_Property_Layer", "WITHIN",

 

"TWB_Suburbs_Layer")

 

updateRows = arcpy.UpdateCursor("TWB_Property", '"LOCALITY" = ' + "'" +

 

str(localityList[indexCounter]) + "'")

 

updateRow = updateRows.next()

 

updateRows.updateRow(updateRow)

 


 

del updateRows, updateRow

 


 

arcpy.Delete_management("TWB_Suburbs_Layer")

 

counter += 1

 

indexCounter += 1

 

print "pass"

 


 

arcpy.Delete_management("TWB_Property_Layer")

 

arcpy.Delete_management("TWB_Suburbs_Layer")

 


 

 

Paper#9256848 | Written in 27-Jul-2016

Price : $16
SiteLock