Inspired by geobuf and flatbush. Deliberately does not support random writes for simplicity and to be able to cluster the data on a packed Hilbert R-Tree enabling fast bounding box spatial filtering. The spatial index is however optional to allow the format to be efficiently written as a stream.
Goals are to be suitable for large volumes of static data, significantly faster than legacy formats without size limitations for contents or metainformation and to be suitable for streaming/random access.
The site http://switchfromshapefile.org has more in depth information about the problems of legacy formats and provides some alternatives but acknowledges that the current alternatives has some drawbacks on their own, for example they are not suitable for streaming.
Live demonstration at https://observablehq.com/@bjornharrtell/streaming-flatgeobuf. (conceptual, not performance optimized)
- MB: Magic bytes (0x6667620266676200)
- H: Header (variable size flatbuffer)
- I+O (optional): Static packed Hilbert R-tree index (static size custom buffer) and Feature offsets index (static size custom buffer, feature count * 8 bytes)
- DATA: Features (variable size flatbuffers)
Any 64-bit flatbuffer value contained anywhere in the file (for example coordinate values) is aligned to 8 bytes to from the start of the file to allow for direct memory access.
Preliminary performance tests has been done using road data from OSM for Denmark in SHP format from https://download.geofabrik.de/, containing 884594 LineString features with a set of attributes.
|Read full dataset||1||0.94||0.47||14||7.9|
|Read w/spatial filter||1||0.14||0.13||102||53|
|Write full dataset||1||0.78||0.40||3.1||3.2|
|Write w/spatial index||1||1.6||0.65||-||-|
The test was done using GDAL implementing FlatGeobuf as a driver and measurements for repeated reads using loops of
ogrinfo -qq -oo VERIFY_BUFFERS=NO runs and measurements for repeated writes was done with
ogr2ogr conversion from the original to a new file with
-lco SPATIAL_INDEX=NO and
-lco SPATIAL_INDEX=YES respectively.
Note that for the test with spatial filter a small bounding box was chosen resulting in only 16 features. The reason for this is to test mainly the spatial index search performance for that case.
- Efficient I/O (streaming and random access)
- GDAL/OGR driver
- QGIS provider (WIP @ https://github.com/bjornharrtell/QGIS/tree/fgb)
- OpenLayers example (WIP @ https://github.com/bjornharrtell/ol3/tree/flatgeobuf)
- GeoServer WFS output format (WIP @ https://github.com/bjornharrtell/geoserver/tree/flatgeobuf-output)
- Complete test coverage
- Java index support
- C# support update
- C langauge support
- Go langauge support
- Rust language support
- Further optimizations
Why not use WKB geometry encoding?
It does not align on 8 bytes so it not always possible to consume it without copying first.
Why not use Protobuf?
Performance reasons and to allow streaming/random access.
Why am I not getting expected performance in GDAL?
Default behaviour is to assume untrusted data and verify buffer integrity for safety. If you have trusted data and want maximum performance make sure to set the open option VERIFY_BUFFERS to NO.