-
Notifications
You must be signed in to change notification settings - Fork 7
/
README.Rmd
86 lines (63 loc) · 2.32 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
dpi = 300,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# geos
<!-- badges: start -->
[![CRAN](http://www.r-pkg.org/badges/version/geos)](https://cran.r-project.org/package=geos)
[![Codecov test coverage](https://codecov.io/gh/paleolimbot/geos/branch/master/graph/badge.svg)](https://app.codecov.io/gh/paleolimbot/geos?branch=master)
[![R-CMD-check](https://github.com/paleolimbot/geos/workflows/R-CMD-check/badge.svg)](https://github.com/paleolimbot/geos/actions)
<!-- badges: end -->
The goal of geos is to provide access to the GEOS C API by vectorizing the C functions for use in R. See the [package function reference](https://paleolimbot.github.io/geos/reference/index.html) for which functions are implemented in the R API.
## Installation
You can install the released version of geos from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("geos")
```
And the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("remotes")
remotes::install_github("paleolimbot/geos")
```
If you can load the package, you're good to go!
```{r example}
library(geos)
```
## Example
Buffer a line and plot it!
```{r ex-plot}
line <- as_geos_geometry("LINESTRING (30 10, 10 30, 40 40)")
plot(geos_buffer(line, distance = 4), col = "grey90")
plot(line, add = T)
```
The geos package is designed to work with [dplyr](https://dplyr.tidyverse.org/) package, so you can work with geometry vectors as a data frame column:
```{r}
library(dplyr)
# map data from the maps package via ggplot2
states_df <- as_tibble(ggplot2::map_data("state"))
states_df
states_df %>%
group_by(region, group) %>%
summarise(geometry = geos_make_polygon(long, lat)) %>%
summarise(geometry = geos_make_collection(geometry, "multipolygon"))
```
The easiest way to get data into and out of the package is using the [sf package](https://r-spatial.github.io/sf/).
```{r sf-plot}
library(sf)
nc <- read_sf(system.file("shape/nc.shp", package = "sf")) %>%
st_transform(32119) # North Carolina state plane, m.
nc_geos <- as_geos_geometry(nc)
nc_geos %>%
geos_make_collection() %>%
geos_unary_union() %>%
st_as_sfc(nc_state)
```