How can I replace -9999 values in an attribute table with null values, in order to average all of the rows that have real values?

1438
5
Jump to solution
11-19-2018 05:57 PM
SkySmith
New Contributor

I am an ArcPy beginner, and I wrote a pretty clunky python script to populate a column of a point shapefile's attribute table with data from a slope map raster. Basically, it uses 'extract multi values to points' tool to find the slope of the raster at all of the points in my shapefile, and store those values in an attribute field. It looks like this:

# Set points shapefile to populate with slope info, set input directory of slope raster
inPointFeatures = "E:/ArcGis_Final_MHWLines_CenCal/2016/Cencal_2016_SD.shp/"
inDEM_ = "E:/Lidar/LidarData_CenCal/C2016/C2016_slopes/Cencal_2016_02_slope.tif"
print "input slope map is " + inDEM_
print "input shapefile is " + inPointFeatures

# Execute ExtractValuesToPoints
arcpy.gp.ExtractMultiValuesToPoints_sa(inPointFeatures, inDEM_, "NONE")

I repeat that code for each slope raster.

Unfortunately, when I ran that code for multiple rasters (and the same point shapefile) it created a new column for each raster. I wanted to merge all of these columns together to make one, neat column that stores all of the slope values and erases all of the -9999 values. And in the end, I just want an average of all of these values- just one final number.

Is it possible to do this in ArcPy? Or with field calculator? I will have to do this multiple times (unless I can write a code to loop through my rasters and leave the slope value in one column.. so far this has been unsuccessful.) So I want to avoid exporting to MATLAB or Excel.

Any tips are greatly appreciated!

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

copy the shapefile to a geodatabase featureclass and use it rather than the shapefile.

With any luck your fields will be nullable and shouldn't have those -9999 values (unless you had to specify a nodata value)

If you need to stick with the point shapefile, sadly you will have to query each column for values > -9999,if you want to get valid counts and sums or to calculate other statistics.

View solution in original post

5 Replies
DanPatterson_Retired
MVP Emeritus

copy the shapefile to a geodatabase featureclass and use it rather than the shapefile.

With any luck your fields will be nullable and shouldn't have those -9999 values (unless you had to specify a nodata value)

If you need to stick with the point shapefile, sadly you will have to query each column for values > -9999,if you want to get valid counts and sums or to calculate other statistics.

SkySmith
New Contributor

Dan Patterson‌ , Thanks for your reply. I copied my file to a geodatabase featureclass, but I'm still not sure how to nullify the -9999 values. I think it would be easiest to write a little python code to put in field calculator, that finds all of the -9999 and replaces them with null, so that I can average all of the columns and ignore the null values. Any help with this would be awesome!

0 Kudos
DanPatterson_Retired
MVP Emeritus

easy

DanPatterson_Retired
MVP Emeritus

did you see my field calculator response?

0 Kudos
SkySmith
New Contributor

Yes, thanks so much for your help with this. Glad to see it was so simple!

0 Kudos