polyfill: Get all hexagons with centers contained in a given polygon

Description Usage Arguments Value Examples

View source: R/h3_polyfill.R

Description

Get all hexagons with centers contained in a given polygon

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
polyfill(coords, res = 7, is_geojson = TRUE)

## S3 method for class 'matrix'
polyfill(coords, res = 7, is_geojson = TRUE)

## S3 method for class 'data.frame'
polyfill(coords, res = 7, is_geojson = TRUE)

## S3 method for class 'list'
polyfill(coords, res = 7, is_geojson = TRUE)

## S3 method for class 'sf'
polyfill(coords, res = 7, is_geojson = TRUE)

Arguments

coords

numeric vector, matrix or data.frame with [lat, lng] or [lng, lat] pairs if is_geojson = TRUE; object of class sf (geom type POLYGON or MULTIPOLYGON)

res

resolution; number between 0 and 15

is_geojson

boolean; expect [lng, lat] pairs instead of [lat, lng]?

Value

h3 indexes; character vector or list of character vectors if multiple polygons are supplied

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
library(sf)

list(greater_manchester) %>%
  st_polygon() %>%
  st_sfc(crs = 4326) %>%
  plot()

polyfill(greater_manchester, 6) %>%
  h3_to_geo_boundary() %>%
  geo_boundary_to_sf() %>%
  plot(add = TRUE)

nc <- system.file("shape/nc.shp", package = "sf") %>%
  st_read(quiet = TRUE)

st_geometry(nc) %>%
  plot(border = "red")

polyfill(nc, 5) %>% unlist() %>%
  h3_to_geo_boundary() %>%
  geo_boundary_to_sf() %>%
  plot(add = TRUE)

crazycapivara/h3forr documentation built on Dec. 6, 2020, 5:21 a.m.