Skip to contents

Returns the h3 indexes for the input GeoJSON-like data structure

Usage

polygonToCells(polygons, resolution, isLatLng = TRUE)

Arguments

polygons

A list of polygons. Each polygon is list of matrices.

resolution

The resolution of the output cells

isLatLng

TRUE (default) if the coordinates are in lat / lng order. FALSE otherwise

Value

h3 indexes for the input GeoJSON-like data structure

Examples


## single polygon
polygon <- list(
  list(
  matrix(
    c(
    37.813318999983238, -122.4089866999972145,
    37.7198061999978478, -122.3544736999993603,
    37.8151571999998453, -122.4798767000009008
    )
    , ncol = 2
    , byrow = TRUE
  )
  )
)

polygonToCells(polygon, resolution = 7L)
#> [[1]]
#> [1] "87283082bffffff" "872830870ffffff" "872830820ffffff" "87283082effffff"
#> [5] "872830828ffffff" "87283082affffff" "872830876ffffff"
#> 

## poylgon with a hole
polygon <- list(
list(
  matrix(
    c(
    37.813318999983238, -122.4089866999972145,
    37.7198061999978478, -122.3544736999993603,
    37.8151571999998453, -122.4798767000009008
    )
    , ncol = 2
    , byrow = TRUE
  ),
  matrix(
    c(
    37.813318999983238, -122.4089866999972145,
    37.7198061999978478, -122.3544736999993603,
    37.8151571999998453, -122.4498767000009008
    )
    , ncol = 2
    , byrow = TRUE
  )
)
)

polygonToCells(polygon, resolution = 7L)
#> [[1]]
#> [1] "872830870ffffff" "872830828ffffff" "872830876ffffff"
#> 

## Many polygons
polygon <- list(
  list(
    matrix(
      c(
      37.813318999983238, -122.4089866999972145,
      37.7198061999978478, -122.3544736999993603,
      37.8151571999998453, -122.4798767000009008
      )
      , ncol = 2
      , byrow = TRUE
    )
   ),
 list(
  matrix(
    c(
    37.813318999983238, -122.4089866999972145,
    37.7198061999978478, -122.3544736999993603,
    37.8151571999998453, -122.4498767000009008
    )
    , ncol = 2
    , byrow = TRUE
    )
  )
)

polygonToCells(polygon, resolution = c(7L, 7L))
#> [[1]]
#> [1] "87283082bffffff" "872830870ffffff" "872830820ffffff" "87283082effffff"
#> [5] "872830828ffffff" "87283082affffff" "872830876ffffff"
#> 
#> [[2]]
#> [1] "87283082bffffff" "87283082affffff" "872830820ffffff" "87283082effffff"
#>