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 am trying to add a new field to a shapefile and need it to store null values. But by using SimpleFeatureTypeBuilder from the Geotools library and then using the Add command, it is not giving the desired result: it just creates a field that can not contain null values.

Please help.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

A shapefile stores attributes in dBase III format. That format stores everything as ASCII text strings. Although these are perfectly capable of containing some kind of code for null values, no convention ever developed for this. Accordingly, most software for reading and writing dBase files interprets non-numeric ASCII text within numeric fields either as an error or--far worse!--as zero. E.g., ESRI software has shown that it can distinguish empty numeric fields from zeros and treat them as nulls, but somehow it eventually converts any empty numeric values to zeros, so you cannot rely on it. (Because the shapefile is originally an ESRI format and many, if not most, shapefiles will be processed by ESRI software at some point, this means that nobody can rely on using empty values for nulls in shapefiles.)

There are some solutions, all workarounds:

  1. Use a different physical format for the dataset, such as a geodatabase, which supports nulls.

  2. Adopt your own convention for representing null values, as discussed at http://gis.stackexchange.com/a/9801. (This will not work for Boolean fields but is effective for dates and numeric fields.)

  3. If either all or none of the fields will simultaneously be null, create them in a separate table and join that table to the shapefile. Represent a null (which is effectively a null record, by assumption) simply by not including any record for that feature. All the joined fields will be interpreted as nulls.

share|improve this answer

It isn't valid to have NULLs in a shapefile, see http://forums.esri.com/Thread.asp?c=93&f=993&t=125464 for a fuller discussion.

share|improve this answer

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.