Previous: , Up: Shapefile   [Contents][Index]


1.5 dbf - Database

Module (shapefile dbf).

Contains auxiliary information about the shapes in the shp file. With one record per shape.

Wikipedia claims that the DBase files should be Version IV 3. The files I have however all use DBase version 3, therefor that is what is supported in the code.

Function: load-dbase-file port transcoder

port is an open input port which the data will be read from. transcoder is an (rnrs io base) transcoder, which signifies which charset the data has.

Returns two values. A list of field descriptors See field-descriptor-v3, and a vector of records.

Each record is a list list on the form (bool data ...), where bool is whether or not the record is removed (#t for removed, #f if still there). The remaining data fields corresponds directly to the fields in the field descriptor list.

However, usually you don’t want to deal with the data that way.

Function: dbase-build-assoc-list dbf-headers dbf-record-vector

Takes the headers and data returned by load-dbase-file, and instead returns a list of association lists. One assoc list per record (leading boolean removed), with the cars being the field names as symbols, and the cdrs being the values.

Example:

(call-with-values (λ () (load-dbase-file port transcoder))
  dbase-build-assoc-list)

Dynamically defining record types, and returning instances would be fancier. However, the utilities for record introspection are lacking, leading to the programmer needing to know the form of the generated records beforehand, defeating the point.

Data Type: field-descriptor-v3 name type length decimal-count work-area-id set-fields-flag

name is the name of the field. type signifies the type of the field, usually unneeded since the values are converted to proper scheme types when reading. See some official reference for proper information.


Footnotes

(3)

https://en.wikipedia.org/wiki/Shapefile#Shapefile_attribute_format_(.dbf)


Previous: , Up: Shapefile   [Contents][Index]