Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hypertidy/crsmeta

Get projection
https://github.com/hypertidy/crsmeta

Last synced: 3 months ago
JSON representation

Get projection

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# crsmeta

[![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing)
[![CRAN status](https://www.r-pkg.org/badges/version/crsmeta)](https://CRAN.R-project.org/package=crsmeta)
[![CRAN\_Download\_Badge](http://cranlogs.r-pkg.org/badges/crsmeta)](https://cran.r-project.org/package=crsmeta)

The goal of crsmeta is to extract *map projection* metadata from in-memory spatial R
objects. The map projection is a set of parameters that describe a *coordinate
reference system* ('crs') and there are various systems that do so with
different sets of aliases and assumptions. With crsmeta we are only obtaining the
value from various formats so that we can develop tools that use them rather
than concern ourselves with format-specific plumbing.

We cannot obtain a crsmeta value from out of memory sources like files, databases, or
URLs. Use another tool for that.

## Installation

You can install the released version of crsmeta from [CRAN](https://CRAN.R-project.org) with:

``` r
install.packages("crsmeta")
```

Install the development version of crsmeta from [Github](https://github.com/hypertidy/crsmeta).

```r
## install.packages("remotes")
remotes::install_github("hypertidy/crsmeta")
```

## Example

This is a basic example which shows you how to obtain the PROJ string from
spatial objects (raster, or silicate):

```{r example, warning=FALSE}
library(crsmeta)
library(raster)

## a spatial object
r <- raster::raster()
r[50:51] <- 10

crs_proj(r)

crs_proj(silicate::SC0(silicate::inlandwaters))
```

This also works for sp, and sf. The function `crs_epsg()` also works
for sf objects, and `crs_wkt2()` for sf and sp objects for later system-level
versions of the PROJ library. The `crs_input()` function will return what the data set's
original coordinate system *was specified with* for new sf objects.

Beware of `crs_input()` it can return EPSG, WKT, PROJ4, or many other variants and aliases.

Now sp or sf objects, note this will give different results depending on the version/s of
R and other software in use:

```{r sf}
print(packageVersion("sf"))
print(sf::sf_extSoftVersion())
north_carolina <- sf::read_sf(system.file("gpkg/nc.gpkg", package = "sf", mustWork = TRUE))
crs_proj(north_carolina)
crs_proj(as(north_carolina, "Spatial"))
crs_wkt2(as(north_carolina, "Spatial"))
crs_epsg(north_carolina)
crs_input(north_carolina)
```

## Code of Conduct

Please note that the crsmeta project is released with a [Contributor Code of Conduct](https://github.com/hypertidy/crsmeta/blob/master/CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms.