0

I am using ArcGIS Desktop 10.5. I have a shapefile with many -9999 values in multiple columns.

Since I have to do mathematical calculations with the values (stuff like the numbers in row a are XY% of the numbers in row b), this is completely unsuitable as a "no data" format.

How can I transform all -9999 into ?

Most options I found are only for rasters (like setnull). I also found this here, it worked for other cases where I just wanted to transform between a null and a true zero, but in this case, I couldn't get it to work.

  • 1
    Export to file database. Add any field, null ok. Select records and populate by nulls from new field. – FelixIP Sep 13 '18 at 21:27
2

Using Actual NULL Values

Shapefiles cannot handle NULL values so copy the feature class to a file geodatabase. Then in the new copied fGDB feature class, view the attribute table, and right-click on the field heading and choose 'Field Calculator`.

In the Field Calculator options, set the options as per below (replacing 'fieldName' with the actual name of the field):

Parser: 'Python'

Show Codeblock: ON

Pre-Logic Script Code (appears after setting 'Show Codeblock' ON above):

def calc(value):
    if value == -9999:
        return None
    return value

fieldName = : calc(!fieldName!)

Click OK.

(Note that None is the Python way of specifying the NULL value.)

Alternatively, you can first select only the records with the -9999 values, and then in the Field Calculator just select 'Python' and enter the expression as None. The Field Calculator will only run on the selected records (if there are any selected). This is simpler to implement but my personal preference is to use the method described above, as it has all the logic in one place.

Using Another Value Instead of NULL

If you don't explicitly need NULL but some other value will do (eg, and empty string, '', or 0), then you don't need to copy to a fGDB first. But I'd still recommending using a copy of the data (eg copy to a new shapefile) to avoid corrupting your original data. In this case, use the Field Calculator as above, but, replace return None with return ''.

  • Awesome! Thank you so much. My mistake was that I tried everything with the shape-file. – Canna Sep 14 '18 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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