14 unstable releases (4 breaking)
new 0.4.0-beta.2 | Dec 11, 2024 |
---|---|
0.4.0-beta.1 | Oct 4, 2024 |
0.3.0 | Sep 7, 2024 |
0.3.0-beta.2 | Aug 23, 2024 |
0.0.0 | Sep 29, 2022 |
#39 in Geospatial
1,309 downloads per month
Used in 7 crates
(6 directly)
4.5MB
39K
SLoC
A Rust implementation of the GeoArrow specification, including algorithms implemented on and returning these GeoArrow arrays.
Reading and writing
The [io] module has functions for reading and writing GeoArrow data from a variety of formats.
To use most format readers and writers, you must enable their corresponding feature.
For example, to convert between geojson and GeoArrow, enable the geozero
feature in your Cargo.toml
:
[dependencies]
geoarrow = { version = "*" }
Then:
use std::{io::Cursor, fs::File};
// Reads geojson from a file into a GeoArrow table.
let file = File::open("fixtures/roads.geojson").unwrap();
let table = geoarrow::io::geojson::read_geojson(file, None).unwrap();
// Writes that table to a cursor as JSON, then reads it back into a `serde_json::Value`.
let mut cursor = Cursor::new(Vec::new());
geoarrow::io::geojson::write_geojson(table, &mut cursor);
let value: serde_json::Value = serde_json::from_slice(&cursor.into_inner()).unwrap();
See the [io] module for more information on the available formats and their features.
Constructing
You can build GeoArrow arrays all at once from [mod@geo] structures, or anything that implements geometry traits, e.g. PointTrait. Along with the GeoRust community, geoarrow-rs has been prototyping geometry access traits for a standardized way to access coordinate information, regardless of the storage format of the geometries. For now, we vendor an implementation of geo-traits (see [mod@geo_traits]), but this may be upstreamed to georust in the future.
use geoarrow::array::PointArray;
use geoarrow::datatypes::Dimension;
let point = geo::point!(x: 1., y: 2.);
let array: PointArray = (vec![point].as_slice(), Dimension::XY).into();
Or you can use builders, e.g. PointBuilder:
use geoarrow::array::PointBuilder;
use geoarrow::datatypes::Dimension;
let mut builder = PointBuilder::new(Dimension::XY);
builder.push_point(Some(&geo::point!(x: 1., y: 2.)));
let array = builder.finish();
Dependencies
~23–49MB
~839K SLoC