Esri JSON struct definitions and serde integration.

Overview

serde_esri

Esri JSON parsing library.

This crate provides representations of Esri JSON objects with serde::Deserialize and serde::Serialize trait implementations.

serde_esri has two additional features geo and geoarrow.

  • 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_arrow() which converts a FeatureSet to an arrow RecordBatch.

Supported Esri JSON objects:

Geometry

Esri Geometries Objects are encoded by the following structs:

  • EsriPoint
  • EsriMultiPoint<N>
  • EsriPolyline<N>
  • EsriPolygon<N>

They are encapsulated by the EsriGeometry enum:

enum EsriGeometry<const N: usize> {
    Point(EsriPoint),
    MultiPoint(EsriMultiPoint<N>),
    Polygon(EsriPolygon<N>),
    Polyline(EsriPolyline<N>),
}

The parameter N is used to specify the dimension of the geometries. Use <2> for 2 dimensional data, <3> for Z values and <4> when M and Z are present.

FeatureSets

An Esri JSON FeatureSet is what is most commonly returned from a Feature Service. It is comprised of a number of optional fields and most importantly, a vector of Features.

Features are a struct with a geometry and an attributes field. The geometry must be one of the possible geometry types and attributes can be an key-value pair.

struct Feature<const N: usize> {
    geometry: Option<EsriGeometry<N>>,
    attributes: Option<Map<String, Value>>,
}

FeatureSets are defined as

pub struct FeatureSet<const N: usize> {
    // ... other optional fields 
    features: Vec<Feature<N>>,
    geometryType: Option<String>,
    spatialReference: SpatialReference,
}

Spatial References

Esri Spatial Reference Objects are represented by the SpatialReference struct. Note that while all fields are optional, one should always be provided.

struct SpatialReference {
    wkid: Option<u32>,
    latest_wkid: Option<u32>,
    vcs_wkid: Option<u32>,
    latest_vcs_wkid: Option<u32>,
    wkt: Option<String>,
}

Example usage:

This example reads a single feature from a feature service and returns a FeatureSet struct.

use serde_esri::features::FeatureSet;
use reqwest::Error;
use std::io::Read;

fn main() -> Result<(), Error> {
    let flayer_url = "https://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/USA_Counties_Generalized_Boundaries/FeatureServer/0/query?where=1%3D1&outFields=*&returnGeometry=true&resultRecordCount=1&f=json";
    let mut res = reqwest::blocking::get(flayer_url)?;
    let mut body = String::new();
    res.read_to_string(&mut body).unwrap();

    let fset: FeatureSet<2> = serde_json::from_str(&body).unwrap(); 
    println!("{:#?}", fset);
    Ok(())
}
You might also like...
JSON parser which picks up values directly without performing tokenization in Rust
JSON parser which picks up values directly without performing tokenization in Rust

Pikkr JSON parser which picks up values directly without performing tokenization in Rust Abstract Pikkr is a JSON parser which picks up values directl

Strongly typed JSON library for Rust

Serde JSON   Serde is a framework for serializing and deserializing Rust data structures efficiently and generically. [dependencies] serde_json = "1.0

JSON implementation in Rust
JSON implementation in Rust

json-rust Parse and serialize JSON with ease. Changelog - Complete Documentation - Cargo - Repository Why? JSON is a very loose format where anything

Rust port of gjson,get JSON value by dotpath syntax

A-JSON Read JSON values quickly - Rust JSON Parser change name to AJSON, see issue Inspiration comes from gjson in golang Installation Add it to your

rurl is like curl but with a json configuration file per request

rurl rurl is a curl-like cli tool made in rust, the difference is that it takes its params from a json file so you can have all different requests sav

A rust script to convert a better bibtex json file from Zotero into nice organised notes in Obsidian

Zotero to Obsidian script This is a script that takes a better bibtex JSON file exported by Zotero and generates an organised collection of reference

A tool for outputs semantic difference of json

jsondiff A tool for outputs semantic difference of json. "semantic" means: sort object key before comparison sort array before comparison (optional, b

Easily create dynamic css using json notation

jss! This crate provides an easy way to write dynamic css using json notation. This gives you more convenient than you think. Considering using a dyna

Decode Metaplex mint account metadata into a JSON file.

Simple Metaplex Decoder (WIP) Install From Source Install Rust. curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh Clone the source: git c

Comments
  • Use separated Coords

    Use separated Coords

    Per recommendation separated x &y coordinates should be used when creating a geoarrow array as it will improve conversion to R types.

    Comment: https://github.com/geoarrow/geoarrow-c/issues/78

    Example affected lines: https://github.com/JosiahParry/serde_esri/blob/1f7f70e086463079bc2d99b925580e052b7382be/src/arrow_compat.rs#L209

    @kylebarron

    opened by JosiahParry 3
Owner
Josiah Parry
Social Scientist. Spatial Stats @ Esri
Josiah Parry
Get JSON values quickly - JSON parser for Rust

get json values quickly GJSON is a Rust crate that provides a fast and simple way to get values from a json document. It has features such as one line

Josh Baker 160 Dec 29, 2022
Rust libraries and tools to help with interoperability and testing of serialization formats based on Serde.

The repository zefchain/serde-reflection is based on Facebook's repository novifinancial/serde-reflection. We are now maintaining the project here and

Zefchain Labs 46 Dec 22, 2022
Serialize/Deserialize tch-rs types with serde

tch-serde: Serialize/Deserialize tch-rs types with serde This crate provides {ser,de}ialization methods for tch-rs common types. docs.rs | crates.io U

null 4 Apr 3, 2022
A SOME/IP serialization format using the serde framework

serde_someip implements SOME/IP ontop of serde use serde::{Serialize, Deserialize}; use serde_someip::SomeIp; use serde_someip::options::ExampleOption

Morten Mey 3 Feb 14, 2022
This library implements a type macro for a zero-sized type that is Serde deserializable only from one specific value.

Monostate This library implements a type macro for a zero-sized type that is Serde deserializable only from one specific value. [dependencies] monosta

David Tolnay 125 Dec 26, 2022
An auxiliary library for the serde crate.

An auxiliary library for the serde crate.

Victor Polevoy 98 Jan 2, 2023
Jsonptr - Data structures and logic for resolving, assigning, and deleting by JSON Pointers

jsonptr - JSON Pointers for Rust Data structures and logic for resolving, assigning, and deleting by JSON Pointers (RFC 6901). Usage Resolve JSON Poin

Chance 38 Aug 28, 2022
A fast and simple command-line tool for common operations over JSON-lines files

rjp: Rapid JSON-lines processor A fast and simple command-line tool for common operations over JSON-lines files, such as: converting to and from text

Ales Tamchyna 3 Jul 8, 2022
A easy and declarative way to test JSON input in Rust.

assert_json A easy and declarative way to test JSON input in Rust. assert_json is a Rust macro heavily inspired by serde json macro. Instead of creati

Charles Vandevoorde 8 Dec 5, 2022
Converts cargo check (and clippy) JSON output to the GitHub Action error format

cargo-action-fmt Takes JSON-formatted cargo check (and cargo clippy) output and formats it for GitHub actions. Examples This tool can be used with a v

Oliver Gould 8 Oct 12, 2022