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

https://github.com/paleolimbot/geos

Open Source Geometry Engine ('GEOS') R API
https://github.com/paleolimbot/geos

Last synced: 7 months ago
JSON representation

Open Source Geometry Engine ('GEOS') R API

Awesome Lists containing this project

README

          

---
output: github_document
---

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

# geos

[![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)

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)
```