Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dcooley/sfheaders
Build sf objects from R and Rcpp
https://github.com/dcooley/sfheaders
r rcpp simple-features
Last synced: 7 days ago
JSON representation
Build sf objects from R and Rcpp
- Host: GitHub
- URL: https://github.com/dcooley/sfheaders
- Owner: dcooley
- License: other
- Created: 2019-06-15T02:04:32.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-07-29T22:57:40.000Z (3 months ago)
- Last Synced: 2024-10-12T21:28:07.219Z (25 days ago)
- Topics: r, rcpp, simple-features
- Language: R
- Homepage: https://dcooley.github.io/sfheaders/
- Size: 11.6 MB
- Stars: 74
- Watchers: 7
- Forks: 5
- Open Issues: 14
-
Metadata Files:
- Readme: README.Rmd
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#",
fig.path = "man/figures/README-",
out.width = "100%"
)```
[![R build status](https://github.com/dcooley/sfheaders/workflows/R-CMD-check/badge.svg)](https://github.com/dcooley/sfheaders/actions)
[![Coverage status](https://codecov.io/gh/dcooley/sfheaders/branch/master/graph/badge.svg)](https://app.codecov.io/github/dcooley/sfheaders?branch=master)
![downloads](http://cranlogs.r-pkg.org/badges/grand-total/sfheaders)
[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/sfheaders)](https://CRAN.R-project.org/package=sfheaders)## Another spatial library?
Yep. In a few of my other libraries I've made use of `sf` objects, but without importing the `sf` library itself. This is by design because `sf` is quite a 'heavy' library.
Therefore I've written / copied these methods for constructing the `sf` objects across a few different libraries.
So I thought it would be useful to have these in one place. And here they are.
## Does it really make `sf` objects?
Yes and No.
These functions do not perform any validity checks on the geometries. Nor do they set Coordinate Reference Systems, EPSG, PROJ4 or precision attributes.
What they do is convert R and Rcpp objects (vectors, matrices and data.frames) into the correct `sf` class structure, so you can then assign these values yourself.
## Are there any catches?
Yes. Your data has to be ordered before coverting to `sf`.
## Where are the examples?
They're on the [website](https://dcooley.github.io/sfheaders/articles/examples.html). GO NOW!
(however, here's a taster)
```r
df <- data.frame(
id = c(1,1,1,1,1,2,2,2,2,2)
, x = c(1,2,2,1,1,3,4,4,3,3)
, y = c(1,1,2,2,1,3,3,4,4,3)
)df$val <- letters[df$id]
sfheaders::sf_linestring( df, x = "x", y = "y", linestring_id = "id", keep = TRUE )
# Simple feature collection with 2 features and 2 fields
# geometry type: LINESTRING
# dimension: XY
# bbox: xmin: 1 ymin: 1 xmax: 4 ymax: 4
# epsg (SRID): NA
# proj4string: NA
# id val geometry
# 1 1 a LINESTRING (1 1, 2 1, 2 2, ...
# 2 2 b LINESTRING (3 3, 4 3, 4 4, ...sfheaders::sf_polygon( df, x = "x", y = "y", polygon_id = "id" , keep = TRUE )
# Simple feature collection with 2 features and 2 fields
# geometry type: POLYGON
# dimension: XY
# bbox: xmin: 1 ymin: 1 xmax: 4 ymax: 4
# epsg (SRID): NA
# proj4string: NA
# id val geometry
# 1 1 a POLYGON ((1 1, 2 1, 2 2, 1 ...
# 2 2 b POLYGON ((3 3, 4 3, 4 4, 3 ...```