[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Any Python gurus online? I've been wracking my brain around
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /wsr/ - Worksafe Requests

Thread replies: 9
Thread images: 2
File: 62050764.png (361 KB, 858x725) Image search: [Google]
62050764.png
361 KB, 858x725
Any Python gurus online?

I've been wracking my brain around this for days now....

I'm not sure if many would be familiar with arcpy. I'm trying to use the ADMINAREA field in TWB_Suburbs_layer to fill the LOCALITY field in TWB_Property_Layer.
The issue is somewhere in this segment. Assuming indentation is correct...

for counter in range(0,len(localityList)):
localityQuery = '"ADMINAREA" = ' + '\''+ str(localityList[indexCounter]) + '\''
arcpy.MakeFeatureLayer_management("TWB_Suburbs", "TWB_Suburbs_Layer", localityQuery)
location = arcpy.SelectLayerByLocation_management("TWB_Property_Layer", "WITHIN", "TWB_Suburbs_Layer")


with arcpy.da.UpdateCursor(fc, field) as cursor:
for row in cursor:
if row[0] == '':
row[0] = 'TESTVALUE'
cursor.updateRow(row)


del row
arcpy.Delete_management("TWB_Suburbs_Layer")
counter += 1
indexCounter += 1
print "pass"
>>
Whoops, I'll try this again with the correct code

print localityList
for counter in range(0,len(localityList)):
localityQuery = '"ADMINAREA" = ' + '\''+ localityList[indexCounter] + '\''
localityLayer = arcpy.MakeFeatureLayer_management("TWB_Suburbs", "TWB_Suburbs_Layer", localityQuery)
arcpy.SelectLayerByLocation_management("TWB_Property_Layer", "WITHIN", "TWB_Suburbs_Layer")

parcelList = []
sRows = arcpy.SearchCursor("TWB_Property_Layer")
sRow = sRows.next()

while sRow:
parcelList.append(sRow)
sRow = sRows.next()
print ("There are " + str(len(parcelList)) + " empty locality fields in " + localityList[indexCounter])
cursor = arcpy.UpdateCursor(fc)
uRow = cursor.next()
for uRow in cursor:
if uRow.LOCALITY == '':
uRow.LOCALITY = str(localityList[indexCounter])
cursor.updateRow(uRow)
uRow = cursor.next()

arcpy.Delete_management("TWB_Suburbs_Layer")
counter += 1
indexCounter += 1
>>
I was gonna ask you to upload the properly indented code to pastebin or the like and have a look, but

>Any Python gurus online?
>pepe shit
Just go ask reddit.
>>
>>126271
That's helpful, thanks.
>>
>>126269
>>126268
1) Just copy it and paste into irfanview, then post the picture.
2) You don't need to ask for a "Python Guru": profunctional OO code is profunctional OO code. There are many profunctional OO languages, and unless your problem is a failure to compile/interpret, your problem is unlikely to be Python-specific
3) You never actually posted a question; you just threw code over the wall and left us to assume it was broken somehow.
>>
File: Clipboard01.jpg (38 KB, 797x245) Image search: [Google]
Clipboard01.jpg
38 KB, 797x245
>>126276
No errors, program runs to completion.
However the fields remain unchanged.

I need to change the LOCALITY field in TWB_Property_Layer to match the ADMINAREA field found in TWB_Suburbs_Layer.
I'm not sure if I'm using selectLayerByLocation properly, and obviously my updateCursor isn't implemented properly either.

I broke the segment down a bit further.
>>
>>126287
Right off the bat, you're using a foreach loop and then incrementing your iterator at the end of it, so you ignore every other row.
>>
>>126293
So it will increment without counter += 1?
>>
>>126302
In Python, when you use "for X in Y" on anything iterable, it updates X automatically every time it loops.

If you were using "while X" you'd have to increment it manually.
Thread replies: 9
Thread images: 2

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.