Expand description
FlatGeobuf is a performant binary encoding for geographic data based on flatbuffers that can hold a collection of Simple Features including circular interpolations as defined by SQL-MM Part 3.
§Reading a FlatGeobuf file
use flatgeobuf::*;
use geozero::ToJson;
let mut filein = BufReader::new(File::open("countries.fgb")?);
let mut fgb = FgbReader::open(&mut filein)?.select_all()?;
while let Some(feature) = fgb.next()? {
println!("{}", feature.property::<String>("name").unwrap());
println!("{}", feature.to_json()?);
}
§Reading FlatGeobuf via HTTP
use flatgeobuf::*;
use geozero::ToWkt;
let mut fgb = HttpFgbReader::open("https://flatgeobuf.org/test/data/countries.fgb")
.await?
.select_bbox(8.8, 47.2, 9.5, 55.3)
.await?;
while let Some(feature) = fgb.next().await? {
let props = feature.properties()?;
println!("{}", props["name"]);
println!("{}", feature.to_wkt()?);
}
§Writing a FlatGeobuf file
use flatgeobuf::*;
use geozero::geojson::GeoJsonReader;
use geozero::GeozeroDatasource;
let mut fgb = FgbWriter::create("countries", GeometryType::MultiPolygon)?;
let mut fin = BufReader::new(File::open("countries.geojson")?);
let mut reader = GeoJsonReader(&mut fin);
reader.process(&mut fgb)?;
let mut fout = BufWriter::new(File::create("countries.fgb")?);
fgb.write(&mut fout)?;
§geo_traits
integration
This crate integrates with geo_traits
for easy zero-copy vector data interoperability.
It can be easier to use than geozero in some cases because you get random access to the
underlying coordinates, rather than needing to receive a stream of coordinates. This means that
you can write algorithms based on geo_traits
and pass in FlatGeobuf objects directly.
Because the underlying Flatbuffers support zero-copy access, you could even memory-map a
FlatGeobuf file directly.
Use FgbFeature::geometry_trait
to access an opaque object that implements
geo_traits::GeometryTrait
. Then with geo_traits::GeometryTrait::as_type
you can match
on the geometry type, downcasting to a trait implementation of concrete type.
use flatgeobuf::*;
use geo_traits::{GeometryTrait, GeometryType};
fn assert_multi_polygon(geom: &impl GeometryTrait<T = f64>) {
assert!(matches!(geom.as_type(), GeometryType::MultiPolygon(_)))
}
let mut filein = BufReader::new(File::open("countries.fgb")?);
let mut fgb = FgbReader::open(&mut filein)?.select_all()?;
while let Some(feature) = fgb.next()? {
println!("{}", feature.property::<String>("name").unwrap());
// Assert that each feature is a multi polygon type
assert_multi_polygon(&feature.geometry_trait().unwrap().unwrap());
}
Re-exports§
pub use geozero;
Modules§
- packed_
r_ tree - Create and read a packed Hilbert R-Tree to enable fast bounding box spatial filtering.
Structs§
- Async
Feature Iter - Column
- Column
Args - Column
Builder - Column
Type - Crs
- CrsArgs
- CrsBuilder
- Feature
- Feature
Args - Feature
Builder - Feature
Iter - FgbCrs
- FgbFeature
- Access to current feature
- FgbReader
- FlatGeobuf dataset reader
- FgbWriter
- FlatGeobuf dataset writer
- FgbWriter
Options - Options for FlatGeobuf writer
- Geometry
- Geometry
Args - Geometry
Builder - Geometry
Type - Header
- Header
Args - Header
Builder - Http
FgbReader - FlatGeobuf dataset HTTP reader
- NotSeekable
- Seekable
Enums§
Constants§
- ENUM_
MAX_ COLUMN_ TYPE Deprecated - ENUM_
MAX_ GEOMETRY_ TYPE Deprecated - ENUM_
MIN_ COLUMN_ TYPE Deprecated - ENUM_
MIN_ GEOMETRY_ TYPE Deprecated - ENUM_
VALUES_ COLUMN_ TYPE Deprecated - ENUM_
VALUES_ GEOMETRY_ TYPE Deprecated - VERSION
Traits§
- Fallible
Streaming Iterator - A fallible, streaming iterator.
- Feature
Access - Feature processing API
- Feature
Properties - Feature properties processing API
- Geozero
Geometry - Geometry processing trait.
Functions§
- finish_
feature_ buffer - finish_
header_ buffer - finish_
size_ prefixed_ feature_ buffer - finish_
size_ prefixed_ header_ buffer - read_
geometry - Read FlatGeobuf geometry
- root_
as_ feature - Verifies that a buffer of bytes contains a
Feature
and returns it. Note that verification is still experimental and may not catch every error, or be maximally performant. For the previous, unchecked, behavior useroot_as_feature_unchecked
. - root_
as_ ⚠feature_ unchecked - Assumes, without verification, that a buffer of bytes contains a Feature and returns it.
- root_
as_ feature_ with_ opts - Verifies, with the given options, that a buffer of bytes
contains a
Feature
and returns it. Note that verification is still experimental and may not catch every error, or be maximally performant. For the previous, unchecked, behavior useroot_as_feature_unchecked
. - root_
as_ header - Verifies that a buffer of bytes contains a
Header
and returns it. Note that verification is still experimental and may not catch every error, or be maximally performant. For the previous, unchecked, behavior useroot_as_header_unchecked
. - root_
as_ ⚠header_ unchecked - Assumes, without verification, that a buffer of bytes contains a Header and returns it.
- root_
as_ header_ with_ opts - Verifies, with the given options, that a buffer of bytes
contains a
Header
and returns it. Note that verification is still experimental and may not catch every error, or be maximally performant. For the previous, unchecked, behavior useroot_as_header_unchecked
. - size_
prefixed_ root_ as_ feature - Verifies that a buffer of bytes contains a size prefixed
Feature
and returns it. Note that verification is still experimental and may not catch every error, or be maximally performant. For the previous, unchecked, behavior usesize_prefixed_root_as_feature_unchecked
. - size_
prefixed_ ⚠root_ as_ feature_ unchecked - Assumes, without verification, that a buffer of bytes contains a size prefixed Feature and returns it.
- size_
prefixed_ root_ as_ feature_ with_ opts - Verifies, with the given verifier options, that a buffer of
bytes contains a size prefixed
Feature
and returns it. Note that verification is still experimental and may not catch every error, or be maximally performant. For the previous, unchecked, behavior useroot_as_feature_unchecked
. - size_
prefixed_ root_ as_ header - Verifies that a buffer of bytes contains a size prefixed
Header
and returns it. Note that verification is still experimental and may not catch every error, or be maximally performant. For the previous, unchecked, behavior usesize_prefixed_root_as_header_unchecked
. - size_
prefixed_ ⚠root_ as_ header_ unchecked - Assumes, without verification, that a buffer of bytes contains a size prefixed Header and returns it.
- size_
prefixed_ root_ as_ header_ with_ opts - Verifies, with the given verifier options, that a buffer of
bytes contains a size prefixed
Header
and returns it. Note that verification is still experimental and may not catch every error, or be maximally performant. For the previous, unchecked, behavior useroot_as_header_unchecked
.