5

I've created a point-data feature class (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'.

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'm new to ArcPy and have based most of the above on the Programming ArcGIS10.1 with Python Cookbook by E. Pimpler.


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
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Oct 23, 2013 at 12:14
0

2 Answers 2

9

You could try:

if row[i] == 9999:
 row[i] = None
 cursor.updateRow(row)
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Oct 23, 2013 at 12:28
0
2

The original error is indicating that setNull is not a method for arcpy.da.UpdateCursor, but it is a method for arcpy.UpdateCursor (no "da").

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Mar 27, 2015 at 1:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.