Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I've created a point-data featureclass (fc) containing data from a simple .txt file using Arcpy as follows:

arcpy.CreateFeatureclass_management(out_path= outPath, out_name= 'fcTest', geometry_type= "POINT", spatial_reference= spatRef, has_m= m, has_z= z)

I've read the text file to create fields and fill each field with data:

#lstFields= data from the text file
#fNames= list of fieldnames
#fClass= list of datatypes
for i in range(len(fNames)):
    arcpy.AddField_management(fcTest, fieldN, fieldT)

Let's say the .txt file contains the xy coordinates and two fields: fA and fB

with arcpy.da.InsertCursor('fcTest', ("SHAPE@XY", "fA", "fB")) as cursor: 
    for point in lstFields: 
        vals= point.split(";")
        x= float(vals[0])
        y= float(vals[1])
        a= int(vals[2])
        b= float(vals[3])
        rowValue= [(x, y), a, b]
        cursor.insertRow(rowValue)

So far so good. However, some values of fA and fB have value 9999, which actually means 'no data'. My question is: how do I convert the 9999 values to a 'real' NoData value? I thought

setNull(field_name)

might be it, but I can't get it to work. See ArcGIS help here. I tried something like:

with arcpy.da.UpdateCursor('fcTest', ("fA", "fB")) as cursor:
    for row in cursor:
        for i in range(len(row)):
            if row[i] == 9999:
                row.setNull(row[i])
                cursor.updateRow(row)
except Exception as e:
    print e.message

Which gives:

'list' object has no attribute 'setNull'

I would appreciate any help. I'm new to arcpy and have based most of the above on the Programming ArcGIS10.1 with Python Cookbook by E. Pimpler. Many thanks!

UPDATE! This works flawlessly:

with arcpy.da.UpdateCursor('fcTest', ("fA", "fB")) as cursor:
    for row in cursor:
        for i in range(len(row)):
            if row[i] == 9999:
                row[i] = None
                cursor.updateRow(row)
except Exception as e:
    print e.message

Thanks @Artwork21

share|improve this question
    
if row[i] = 9999: is wrong. It should be if row[i] == 9999: –  Nathan W Oct 23 '13 at 12:21
    
Thanks for pointing that out, I've revised it. However, it was only wrong here, not in my original code, so that can't be the issue. –  HDR Oct 23 '13 at 12:23
add comment

1 Answer 1

up vote 3 down vote accepted

Have you tried:

if row[i] == 9999:
   row[i] = None
   cursor.updateRow(row)
share|improve this answer
    
Woow! That's it, thanks a lot! –  HDR Oct 23 '13 at 12:31
    
@HDR, Please accept this answer, thx. –  artwork21 Oct 23 '13 at 19:01
    
Ah, didn't knew that was possible. It's done. –  HDR Oct 24 '13 at 7:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.