Expand description
§geonative-geojson
Pure-Rust reader and writer for GeoJSON (RFC 7946), part of the
geonative geospatial library.
§What v0.1 covers
Reader:
- Top-level
FeatureCollection, bareFeature, or bare geometry object - All seven RFC 7946 geometry types (Point/Multi*/Polygon/Multi*/Collection)
- Schema inference from
properties(one pass; widening rules inproperties) - CRS detection: default
EPSG:4326, honours legacy 2008crs.properties.nameURNs likeurn:ogc:def:crs:EPSG::3857 - String / numeric
id→Feature::fid(i64 only — string ids that don’t parse as integers fall back to row index)
Writer:
- Streaming — O(one feature) memory regardless of input size
- Compact output (no whitespace); wrap your sink in a pretty-printer if you need indentation
- Always writes
FeatureCollection; nocrsmember (RFC 7946 removed it)
§v0.1 scope cuts
- Z/M coordinates silently truncated on read; never emitted on write.
GeoJSON’s third position is optional and underspecified across tools;
v0.2 will add an opt-in
--preserve-zswitch. - Foreign members (
bbox, custom top-level keys) are read but not round-tripped on write — only spec-defined fields are emitted. - Streaming reader (v0.4) —
GeoJsonReader::open(path)now scans the file in two streaming passes (schema inference + feature yield) instead of materialising the whole JSON tree. Peak RAM is bounded to ~one feature regardless of file size; the previous in-memory path (from_bytes/from_value) is still available for callers who already have the bytes and want the eagerfeatures()slice.
§Usage
let r = geonative_geojson::GeoJsonReader::open("things.geojson")?;
println!("{} features, schema: {:?}", r.feature_count(), r.schema());
for f in r.features() {
// f.fid, f.geometry, f.attributes
}Re-exports§
pub use error::GeoJsonError;pub use error::Result;pub use reader::GeoJsonReader;pub use writer::write_features_to_path;pub use writer::GeoJsonWriter;
Modules§
- error
- GeoJSON-specific error type.
- geometry
- Convert between RFC 7946 JSON shapes and the geonative-core
Geometrytree. 2D only in v0.1 — Z/M coordinates are silently truncated on read, and never emitted on write. - properties
- GeoJSON
propertiesobject handling: schema inference on read,Value↔ JSON conversion on read+write. - reader
- GeoJSON reader.
- writer
- GeoJSON writer — streams a
FeatureCollectionto anyWritesink, one feature at a time. Memory use is O(one feature), so multi-GB outputs are fine to produce.