Calculate Row if Row Value Equals Value in List

المشرف العام

Administrator
طاقم الإدارة
I have a folder of photos named with a building ID that corresponds to a building ID in a building footprints feature class. Not all rows in the footprints feature class have a corresponding photo. So, I want to use an update cursor to calculate a photofile field in the footprints feature class if there is a photo in the folder.

I've gotten this to work with both arcpy.UpdateCursor [getValue(), setValue()] and arcpy.da.UpdateCursor, but I don't think it's the most efficient method due to the time it takes to run (new cursor for each value in the list?). Here is the working method using da, but again, it takes forever to run.

import arcpyphotos = arcpy.GetParameterAsText(0) #photos folderfc = arcpy.GetParameterAsText(1) #feature classarcpy.env.workspace = photosphotoList = arcpy.ListRasters()fields = ('BLDG_ID','PHOTOFILE')with arcpy.da.UpdateCursor(fc,fields) as uc: for row in uc: for photo in photoList: if (row[0] == photo[:-4]): row[1] = photo else: pass uc.updateRow(row)del row, ucThat's probably not the most Pythonic way. I want to use something like:

with arcpy.da.UpdateCursor(fc,fields) as uc: for row in uc: if row[0] in photoList: row[1] = value in list uc.updateRow(row)del row, ucThe problem is that the values in the photoList have ".jpg" after the BLDG_ID, so it is not equal without removing ".jpg" from each value in the list or concatenating ".jpg" to the BLDG_ID value in the row (row[0]+".jpg" ... I don't think that works). I'm also not sure how to update the row in the field as the value in the list without iterating through the list, and I need to retain the ".jpg" in the PHOTOFILE field as well.

Example:

Photo in folder = 12345.jpg

BLDG_ID in fc = 12345

PHOTOFILE in fc = 12345.jpg

Thanks!



أكثر...
 
أعلى