-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
120 lines (83 loc) · 3.76 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
---
output: github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
<!-- badges: start -->
[![Travis-CI Build Status](https://travis-ci.org/mdsumner/spex.svg?branch=master&env=BUILD_NAME=xenial_release&label=linux)](https://travis-ci.org/mdsumner/spex)
[![Build Status](https://travis-ci.org/mdsumner/spex.svg?branch=master&env=BUILD_NAME=osx_release&label=osx)](https://travis-ci.org/mdsumner/spex)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/mdsumner/spex?branch=master&svg=true)](https://ci.appveyor.com/project/mdsumner/spex)
[![Coverage status](https://codecov.io/gh/mdsumner/spex/branch/master/graph/badge.svg)](https://codecov.io/github/mdsumner/spex?branch=master)
[![lifecycle](https://img.shields.io/badge/lifecycle-stable-green.svg)](https://www.tidyverse.org/lifecycle/#stable)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/spex)](https://cran.r-project.org/package=spex)
[![CRAN_Download_Badge](http://cranlogs.r-pkg.org/badges/spex)](https://cran.r-project.org/package=spex)
[![R build status](https://github.com/mdsumner/spex/workflows/R-CMD-check/badge.svg)](https://github.com/mdsumner/spex/actions)
<!-- badges: end -->
## spex
Spex provides a small set of functions for working with spatial data. These are
* `spex()` - a spatial extent with projection metadata
* `polygonize()` - a fast quadmesh-based pixel-to-polygon translation
* `buffer_extent` - a convenience function for tidy extents
* `xlim`, `ylim` - convenience functions for the axes of an extent
* `extent()` - convenience functions for sf objects
* `latmask()` - mask a raster based on a latitude
* `latitudecircle()` - create a spatial region based on a latitude
Create a fully-fledged SpatialPolygonsDataFrame *extent* from any object understood
by the 'raster' package function 'extent()'. If the input has projection metadata it
will be carried through to the output. The intention is to support any object from packages `sp`, `raster` and `sf`. If you want this to work on other types, [create an issue and get in touch to discuss!](https://github.com/mdsumner/spex/issues).
The polygonization approach is faster than `rasterToPolygons`, and multi-layer rasters are converted to multi-column spatial data frames. This only does the pixel-to-polygon case. It provides an `sf` POLYGON data frame, but there is a version `qm_rasterToPolygons_sp` that returns a Spatial version.
The "buffered extent" is used to create cleanly aligned extents, useful for generating exacting grid structures
as raster or vector.
## Installation
Install 'spex' from CRAN.
```{r,eval=FALSE}
install.packages("spex")
```
## Examples
Create a Spatial object as a single extent polygon from a raster.
```{r}
library(spex)
library(raster)
data(lux)
(exlux <- spex(lux))
## put an extent and a CRS together
spex(extent(0, 1, 0, 1), crs = "+proj=laea +ellps=WGS84")
```
Create a simple features POLYGON data frame from a raster.
```{r}
library(spex)
library(raster)
r <- raster(volcano)
tm <- system.time(p <- qm_rasterToPolygons(r))
p1 <- polygonize(r)
identical(p, p1)
p3 <- qm_rasterToPolygons_sp(r)
class(p3)
nrow(p)
class(p)
class(p$geometry)
print(tm)
```
Create a buffered extent with whole-number aligned edges.
```{r}
library(spex)
(ex <- extent(lux))
buffer_extent(ex, 10)
buffer_extent(ex, 2)
```
There are convenience functions for sf objects.
```{r}
class(psf)
extent(psf)
spex(psf)
```
---
Please note that this project is released with a [Contributor Code of Conduct](https://hypertidy.github.io/reproj/CODE_OF_CONDUCT.html). By participating in this project you agree to abide by its terms.