knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
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.
You can install the released version of crsmeta from CRAN with:
install.packages("crsmeta")
Install the development version of crsmeta from Github.
## install.packages("remotes") remotes::install_github("hypertidy/crsmeta")
This is a basic example which shows you how to obtain the PROJ string from spatial objects (raster, or silicate):
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:
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)
Please note that the crsmeta project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.