Dbf
Dbf files are dBase files, used as part of the ESRI Shapefile or as separate data file.
In reading and writing dbf files, the value types of the values units of the attributes should match with the data types of the attributes in the dbf file.
The following value types can be used for dbf data:
- (u)int8/16/32/64 for byte, integer and long integer
- float32/64 for single/double
- bool for boolean
- string for string
Other data/value types can not be read from (e.g. date) or written to (e.g. all Point Group types) dbf storages.
The dbf StorageManager reads and writes int64 and uint64, the value types to use for ids of 16 to 18 digits. The values are read as integers, so they stay exact above 2^53, where a float64 would round them. Where the dbf StorageManager derives the value type of a column itself, as with SyncMode, a numeric column without decimals that is wider than 10 digits, N(11,0) to N(19,0), becomes int64; N(10,0), the usual width of an ESRI long integer, becomes int32.
Read
The GeoDMS supports two ways of reading dbf files:
- gdal.vect: we advise to use the gdal.vect StorageManager to read dbf files as it supports segmented data, see the next subparagraph.
- dbf StorageManager
gdal.vect
The following example shows how to read a .dbf file with Gdal.vect.
example:
unit<uint32> table: StorageName = "%projDir%/data/DBF.dbf"
, StorageType = "gdal.vect"
, StorageReadOnly = "True"
{
attribute<int32> IntegerAtt;
attribute<float32> FloatAtt;
attribute<bool> BoolAtt;
attribute<string> StringAtt;
}
dbf storagemanager
The following example shows how to read a .dbf file with the dbf storagemanager.
example:
unit<uint32> table: StorageName = "%projDir%/data/DBF.dbf"
, StorageReadOnly = "True"
{
attribute<int32> IntegerAtt;
attribute<float32> FloatAtt;
attribute<bool> BoolAtt;
attribute<string> StringAtt;
}
A numeric field that holds only blanks or * characters, the way dBase, ESRI and GDAL store a NULL, is read as Null.
The dbf StorageManager reads a column a block of records at a time, and it reads and writes a .dbf larger than 2 GB.
Write
The GeoDMS supports two ways of writing dbf files:
- gdalwrite.vect: we advise to use the gdalwrite.vect StorageManager to write dbf files, see the next subparagraph.
- dbf StorageManager
Be aware: the names of attributes written to a .dbf file may not exceed 10 characters, as the .dbf file does not support longer fields.
We advise to write attributes to dbf file that do not have Null values, as strange results might occur. Use the MakeDefined function to convert null values to a specific missing data value for your dbf file.
gdalwrite.vect
The following example shows how to write a .dbf file with the Gdalwrite.vect.
example:
unit <uint32> pc6_export := src/pc6
, StorageName = "%localDataProjDir%/export_table.dbf"
, StorageType = "gdalwrite.vect"
, StorageReadOnly = "false"
{
attribute<uint32> IntegerAtt := const(1, .);
attribute<float32> FloatAtt := const(1f, .);
attribute<string> StringAtt := const('A', .);
attribute<bool> BoolAtt := const(true, .);
}
dbf storagemanager
The following example shows how to write a .dbf file with the dbf storagemanager.
example:
unit <uint32> pc6_export := src/pc6
, StorageName = "%localDataProjDir%/export_table.dbf"
, StorageReadOnly = "false"
{
attribute<uint32> IntegerAtt := const(1, .);
attribute<float32> FloatAtt := const(1f, .);
attribute<string> StringAtt := const('A', .);
attribute<bool> BoolAtt := const(true, .);
}
A write that fails, on a full disk or a share that went away, is an error. The header of a .dbf stores its own size and the record size in 16 bits, so a .dbf holds at most 2046 columns and records of at most 65535 bytes, the sum of the column widths; more is refused before anything is written. The written copy replaces the existing file in one step, also for a path with characters outside the Windows code page in the Python module; when it cannot, the existing file stays as it was.
files written by older versions
A .dbf written by a GeoDMS version before 20.23.1 can be damaged without that version having reported it: a file larger than 2 GB may not have its records beyond 2 GB in the right place, a file with more than 2046 columns or with records of more than 65535 bytes has a header that no reader takes, and a write that failed on a full disk or a lost share left a truncated file. Write such a file again; a table that the format cannot hold has to be written with fewer or narrower columns, or to another format.