marinebon / obisindicators

R package for generating indicators from OBIS
https://marinebon.github.io/obisindicators/
Other
6 stars 4 forks source link

export hexagon spatialFeatures for ArcGIS? #43

Open 7yl4r opened 1 year ago

7yl4r commented 1 year ago

@bbest : maybe you will be able to help here...

can we export the H3 hexagon grid as a set of SpatialFeatures (.geojson?) that can be easily imported into ArcGIS?

This is the workflow requested by Mimi D'lorio of the America The Beautiful initiative.

MathewBiddle commented 3 weeks ago

Yup, totally doable. I did it in https://github.com/MathewBiddle/globe/pull/18

make_hex_res returns the geometry as a feature sf object. Simply use geojsonsf::sf_geojson() to return the geojson, and save that to a file. For example:

resolution <- 3

hex <- obisindicators::make_hex_res(resolution)

occ <- occ %>%
      mutate(
        cell = h3::geo_to_h3(
          data.frame(decimalLatitude,decimalLongitude),
          res = resolution
        )
      )

idx <- obisindicators::calc_indicators(occ)

grid <- hex %>%
      inner_join(
        idx,
        by = c("hexid" = "cell")
      )

geojson_string <- geojsonsf::sf_geojson(grid)

fname <- 'all_indicators.geojson'

write(x=geojson_string, file=fname)