Skip to content

Commit

Permalink
Merge pull request #17 from JosiahParry/places
Browse files Browse the repository at this point in the history
add places compatibility and client
  • Loading branch information
JosiahParry committed Apr 16, 2024
2 parents 29d9cc5 + d31470f commit 9e1ab1f
Show file tree
Hide file tree
Showing 11 changed files with 2,078 additions and 50 deletions.
948 changes: 927 additions & 21 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
[package]
name = "serde_esri"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/josiahparry/serde_esri"
authors = ["Josiah Parry<josiah.parry@gmail.com>"]
categories = ["science::geo", "parser-implementations", "encoding"]
keywords = ["esri", "arcgis", "geo", "gis", "spatial"]
readme = "README.md"
description = "A library for serializing and deserializing Esri JSON FeatureSet and Geometry objects."
description = "A library for serializing and deserializing JSON from Esri Location Services."


[dependencies]
arrow = { version = "51.0.0", optional = true }
geoarrow = { version = "0.2.0", optional = true }
geo-types = { version = "0.7.12", optional = true }
reqwest = { version = "0.12.3", optional = true }
serde = { version = "1.0.192", features = ["derive"] }
serde_json = "1.0.108"
serde_with = "3.4.0"
derive_builder = "0.20.0"

[lib]
crate-type = ["staticlib", "lib"]

[features]
default = []
places-client = ["reqwest/blocking", "reqwest/json"]
geo = ["dep:geo-types"]
geoarrow = ["dep:geo-types", "dep:geoarrow", "arrow"]
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ Esri JSON parsing library.

This crate provides representations of Esri JSON objects with [`serde::Deserialize`](https://docs.rs/serde/1.0.192/serde/de/trait.Deserialize.html) and [`serde::Serialize`](https://docs.rs/serde/1.0.192/serde/de/trait.Serialize.html) trait implementations.

`serde_esri` has two additional features `geo` and `geoarrow`.
`serde_esri` has additional features:

- `geo` implements `From` for the Esri JSON objects.
- `geoarrow` provides compatibility with arrow and geoarrow by implementing geoarrow geometry traits as well as providing a utility function `featureset_to_geoarrow()` which converts a `FeatureSet` to an arrow `GeoTable`.
- `places-client` provides an API client for the Places Service REST API.


## Example usage:
Expand Down Expand Up @@ -125,3 +126,39 @@ struct SpatialReference {
wkt: Option<String>,
}
```

## Places Service API Client

Activate the PlaceAPI client in your Cargo.toml


```toml
[dependencies]
serde_esri = { version = "0.3.0", features = ["places-client"] }
```

```rust
fn main() {

let client = PlacesClient::new(
PLACES_API_URL,
"your-developer-credential",
);

// Use the query within extent query builder to create query parameters
let params = WithinExtentQueryParamsBuilder::default()
.xmin(139.74)
.ymin(35.65)
.xmax(139.75)
.ymax(35.66)
.build()
.unwrap();

// Call the within_extent method with the query parameters
let res = client.within_extent(params).unwrap();

// use the automatic pagination for the iterator method
res.into_iter()
.for_each(|r| println!("{:?}", r.unwrap().name));
}

27 changes: 1 addition & 26 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,11 @@
#![doc = include_str!("../README.md")]
//!
//! Example usage:
//!
//! ```rust
//! use serde_esri::features::FeatureSet;
//! use reqwest::Error;
//! use std::io::Read;
//!
//! fn main() {
//!
//! // USA counties query
//! let flayer_url = "https://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/USA_Counties_Generalized_Boundaries/FeatureServer/0/query?where=1%3D1&outFields=*&returnGeometry=false&resultRecordCount=1&f=json";
//!
//! // perform request
//! let mut res = reqwest::blocking::get(flayer_url).unwrap();
//! let mut body = String::new();
//!
//! // read body into string
//! res.read_to_string(&mut body).unwrap();
//!
//! // process into FeatureSet
//! let fset: FeatureSet<2> = serde_json::from_str(&body).unwrap();
//! println!("{:#?}", fset);

//! }
//! ```
mod de_array;
pub mod features;
pub mod field_type;
pub mod geometry;
pub mod places;
pub mod spatial_reference;

// feature flag: geo-types
#[cfg(feature = "geo")]
pub mod geo_types;
Expand Down
5 changes: 5 additions & 0 deletions src/places/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! Representation of the [Places Service REST API](https://developers.arcgis.com/rest/places/) types and responses. Activate the `"places-client"` feature to enable the `PlacesClient` struct and the ability to query the API.
mod places;
pub use places::*;

pub mod query;

0 comments on commit 9e1ab1f

Please sign in to comment.