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
- Host: GitHub
- URL: https://github.com/paleolimbot/geos
- Owner: paleolimbot
- License: other
- Created: 2020-01-29T07:29:40.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2025-03-19T14:46:22.000Z (8 months ago)
- Last Synced: 2025-04-30T21:09:23.907Z (7 months ago)
- Language: R
- Homepage: https://paleolimbot.github.io/geos/
- Size: 2.42 MB
- Stars: 62
- Watchers: 8
- Forks: 7
- Open Issues: 9
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- Awesome-Geospatial - geos - Open Source Geometry Engine ('GEOS') R API. (R)
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
[](https://cran.r-project.org/package=geos)
[](https://app.codecov.io/gh/paleolimbot/geos?branch=master)
[](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)
```