sfconversions

Crates.iosfconversions
lib.rssfconversions
version0.2.0
sourcesrc
created_at2023-03-12 14:14:20.534632
updated_at2023-08-22 18:17:02.382364
descriptionSupport conversion from R's sf package types to geo_types geometry primitives using extendr
homepage
repositoryhttps://github.com/josiahparry/sfconversions
max_upload_size
id808058
size25,351
Josiah Parry (JosiahParry)

documentation

README

sfconversions

A minimal Rust library to convert geometry objects from the R package {sf} into geo-types geometry primitives using extendr.

Provides simple conversions between sfg, sfc objects from sf, and geometry primitives from geo_types that can be used with other georust libraries powered by extendr.

Due to the orphan rule conversion directly from extendr Lists to geo_types is not possible. For that reason a simple struct Geom is implemented with a single field geom which contains a geo_types Geometry enum.

Example

Basic conversion from sfg objects is done with sfg_to_geom().

use sfconversions::{sfg_to_geom, geom::Geom};
use extendr_api::prelude::*;

#[extendr]
fn extract_sfg(x: Robj) -> String {
  sfg_to_geom(x).unwrap().print()
}

The Geom struct is an extendr compatible struct with a single method which prints the string.

sfconversions acts similarly to sfheaders in that it returns the correct R objects with the appropriate classes without dependence upon sf. If sf is not available the conversions still will work but the print methods and other functions from sf will not be available.

It is important to note that sfconversions will only create sfg objects and will not make sfc class object. This is because sfc objects require a bounding box attribute which can only be calculated using geo which is a larger dependency. To create an sfc object return a List of sfg objects and in R use sf::st_sfc() to complete the conversion. Use geos_to_sfc() to aid in this process.

Commit count: 29

cargo fmt