Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Check field before populating field

$
0
0
I would like to find a way to have my code check the field (FacltyType) and see if there is any text and if there is skip that feature and continue to check each selected feature and if there is not text in that Field (FacltyType) check the CPUC field in Points_2 for "DWELL" and populate FacltyType with "Single Family Home" if CPUC is "NULL" populate FacltyType with "MobileHome"

Here is my current code.
Code:

import arcpy, time
arcpy.env.overwriteOutput = True

arcpy.env.workspace = r"C:\Temp\Defult.gdb"
fcTarget = 'Points_1'
fcJoin = 'Points_2'
fcOutput = 'Points_joined'

arcpy.SpatialJoin_analysis(fcTarget, fcJoin, fcOutput, 'JOIN_ONE_TO_ONE', 'KEEP_COMMON')

curR = arcpy.SearchCursor(fcOutput, '', '', '', 'AddressID A')
curW = arcpy.UpdateCursor(fcTarget, '', '', '', 'AddressID A')

# init rowW and rowR
rowW = curW.next()
rowR = curR.next()

while rowR:
    currentAddress = rowR.AddressID
    print 'current add: ' + currentAddress
    while rowW.AddressID != currentAddress:
        rowW = curW.next()
    if rowR.CPUC == 'DWELL':
        rowW.FacltyType = 'Single Family Home'
        rowW.APA_CODE = '1110'
        rowW.StructType = 'Primary, Private'
        rowW.Verified = 'Yes, GRM, TA, ' + time.strftime('%m/%d/%Y')
        rowW.Status = 'Active'
        rowW.StructCat = 'Residential'
    else:
        rowW.FacltyType = 'MobileHome'
        rowW.APA_CODE = '1150'
        rowW.StructType = 'Primary, Private'
        rowW.Verified = 'Yes, GRM, TA, ' + time.strftime('%m/%d/%Y')
        rowW.Status = 'Active'
        rowW.StructCat = 'Residential'
        # put any additional conditional field statements here
    else:
    rowW.FacltyType = rowR.CPUC
   
# changed the delete statement, targeting the cursor objs (rather than the row objs)
if curW:
    del curW
if curR:
    del curR

del rowW, rowR


Viewing all articles
Browse latest Browse all 2485

Trending Articles