fcb_core 0.7.7

FlatCityBuf is a library for reading and writing CityJSON with FlatBuffers. Contains code derived from FlatGeobuf (BSD-2-Clause) for spatial indexing.
Documentation

fcb_core

Read and write FlatCityBuf (.fcb) — a cloud-optimized binary encoding of CityJSON. It carries the standard's semantics in FlatBuffers, with a packed Hilbert R-tree for spatial queries and static B+tree indices for attribute queries, laid out so a client reads only the bytes it actually needs — from a local file, a non-seekable stream, or a remote URL over HTTP range requests. fcb_core is the reference implementation of the format and the only one that writes it.

Install

cargo add fcb_core

The http feature is enabled by default and brings in reqwest and http-range-client. For a dependency-light, purely local reader:

[dependencies]
fcb_core = { version = "0.7", default-features = false }

Reading a file

use fcb_core::{deserializer::to_cj_metadata, FcbReader};
use std::fs::File;
use std::io::BufReader;

let file = BufReader::new(File::open("delft.fcb")?);
let mut features = FcbReader::open(file)?.select_all()?;

// The CityJSON metadata object (version, transform, CRS, extent) is the
// header; it is the first line of the equivalent CityJSONSeq document.
let cj = to_cj_metadata(&features.header())?;
println!("CityJSON {}, {} features", cj.version, features.header().features_count());

while let Some(feature) = features.next()? {
    let cj_feature = feature.cur_cj_feature()?;
    println!("{}: {} city object(s)", cj_feature.id, cj_feature.city_objects.len());
}

Spatial queries (select_query), attribute queries (select_attr_query), HTTP streaming (HttpFcbReader) and writing (FcbWriter) are all covered in the crate documentation on docs.rs.

Documentation

Attribution

Portions of this software are derived from FlatGeobuf (BSD 2-Clause License), copyright (c) 2018-2024 Björn Harrtell and contributors — specifically the packed R-tree spatial index, the HTTP range request handling, and parts of the binary format design. See ATTRIBUTION.md for details.

License

MIT — see LICENSE. FlatGeobuf portions remain under their original BSD 2-Clause License.