FlatGeobuf
Overview
FlatGeobuf is a performant binary encoding for geographic data based on FlatBuffers. It supports random access via HTTP range requests, making it ideal for streaming large datasets over the web without downloading the entire file.
Key Features
| Feature | Description |
|---|---|
| Binary Format | Compact, fast to parse |
| Streaming | HTTP range request support |
| Spatial Index | Optional R-tree for filtered reads |
| Single File | All data in one .fgb file |
| Seekable | Random access to features |
| Attribute Types | Full type support |
Advantages
| Aspect | FlatGeobuf | GeoJSON | Shapefile |
|---|---|---|---|
| Size | Small | Large | Medium |
| Parse speed | Fast | Slow | Medium |
| Streaming | Yes | No | No |
| Spatial index | Built-in | No | Separate |
| Single file | Yes | Yes | No |
Usage
GDAL/OGR
# convert geojson to flatgeobuf
ogr2ogr -f FlatGeobuf output.fgb input.geojson
# with spatial index
ogr2ogr -f FlatGeobuf -lco SPATIAL_INDEX=YES output.fgb input.geojson
# query with bbox filter
ogrinfo output.fgb -spat -122.5 37.7 -122.3 37.9JavaScript (Web)
import { geojson } from 'flatgeobuf';
// stream features from URL with bbox filter
const bbox = { minX: -122.5, minY: 37.7, maxX: -122.3, maxY: 37.9 };
const iter = geojson.deserialize('https://example.com/data.fgb', bbox);
for await (const feature of iter) {
console.log(feature);
}Leaflet Integration
import { geojson } from 'flatgeobuf';
async function loadFlatGeobuf(map, url) {
const response = await fetch(url);
const iter = geojson.deserialize(response.body);
const layer = L.geoJSON();
for await (const feature of iter) {
layer.addData(feature);
}
layer.addTo(map);
}R
library(sf)
# read flatgeobuf
features <- sf::st_read("data.fgb")
# write flatgeobuf
sf::st_write(features, "output.fgb", driver = "FlatGeobuf")Python
import geopandas as gpd
# read
gdf = gpd.read_file("data.fgb")
# write
gdf.to_file("output.fgb", driver="FlatGeobuf")When to Use
Choose FlatGeobuf when:
- Web streaming of vector data
- Need bbox filtering via HTTP
- Medium datasets (10-500MB)
- Binary efficiency matters
- Building web map applications
Consider alternatives when:
- Analytics queries → GeoParquet
- Human readability → GeoJSON
- Desktop GIS workflows → GeoPackage
Comparison with GeoParquet
| Aspect | FlatGeobuf | GeoParquet |
|---|---|---|
| Orientation | Row-based | Columnar |
| Best for | Feature streaming | Analytics |
| Compression | Moderate | Excellent |
| Column selection | No | Yes |
| Ecosystem | Web mapping | Data science |
Appendix
Created: 2024-12-23 | Modified: 2024-12-23
See Also
- MOC - Geospatial
- Guide - Geospatial File Format Selection
- Row vs Columnar Geospatial Formats
- GeoJSON
- GeoParquet
Backlinks
(c) No Clocks, LLC | 2024