NetTopologySuite / NetTopologySuite.IO.ShapeFile

The ShapeFile IO module for NTS.
33 stars 25 forks source link

Null Values in Dbase file #64

Closed kristofdegrave closed 3 years ago

kristofdegrave commented 3 years ago

When writing NULL values to a Dbase file, a string.empty is written instead: https://github.com/NetTopologySuite/NetTopologySuite.IO.ShapeFile/blob/3c952d5df92d1b5cc3c78b7f9d4815f129c2b719/src/NetTopologySuite.IO.ShapeFile/Dbase/DbaseFileWriter.cs#L151-L156 When we look at the write implemenation, we also see that the remaining bytes are filled with the value 0x20 (space) https://github.com/NetTopologySuite/NetTopologySuite.IO.ShapeFile/blob/3c952d5df92d1b5cc3c78b7f9d4815f129c2b719/src/NetTopologySuite.IO.ShapeFile/Dbase/DbaseFileWriter.cs#L320-L337

When reading the values of a dbase file, we don't take this into account. For example a NULL value for a boolean will be read as false. https://github.com/NetTopologySuite/NetTopologySuite.IO.ShapeFile/blob/3c952d5df92d1b5cc3c78b7f9d4815f129c2b719/src/NetTopologySuite.IO.ShapeFile/Dbase/DbaseFileReader.cs#L145-L150

So if the entire byte array length of the field is filled with spaces 0x20, can't we just convert this to null instead?

airbreather commented 3 years ago

I think this is fixed now. Thanks!