SymbolixAU / mapdeck

R interface to Deck.gl and Mapbox
https://symbolixau.github.io/mapdeck/articles/mapdeck.html
362 stars 40 forks source link

H3HexagonLayer support #243

Closed mitchelloharawild closed 10 months ago

mitchelloharawild commented 4 years ago

What do you want the feature to do? Add the H3 hexagon layer. https://github.com/uber/deck.gl/blob/master/docs/layers/h3-hexagon-layer.md

Happy to help with this, I briefly tried to add support for it but the input structure for the geometry is non-standard enough that I wanted to get your opinions before going further.

Some potential nuances for supporting this layer:

  1. Geometry data for h3 is a character vector, and not a recognised sf geometry (expect df data input, not sf)
  2. Computing the bounding box for the h3 hexagons may require converting the hexagons twice. Once in R/Rcpp for computing bbox, second in deck.gl to add it to the map (is this necessary?).

TODO

SymbolixAU commented 4 years ago

Geometry data for h3 is a character vector, and not a recognised sf geometry (expect df data input, not sf)

This should be fine and straight-forward enough, and I think I can re-use the underlying methods for using an encoded polyline (character vector).

Computing the bounding box for the h3 hexagons may require converting the hexagons twice. Once in R/Rcpp for computing bbox, second in deck.gl to add it to the map (is this necessary?).

yeah this could be tricky...

mitchelloharawild commented 4 years ago

This should be fine and straight-forward enough, and I think I can re-use the underlying methods for using an encoded polyline (character vector).

Yep, I expected this might be similar. I may be wrong here, but does the polyline always have the sfencoded data class? For h3 something simpler might suffice (just passing through the specified h3 column?).

yeah this could be tricky...

Could we simply disable the update_view option for add_h3_hexagon() and think about this more later? Is the bbox used for anything else?

SymbolixAU commented 4 years ago

but does the polyline always have the sfencoded data class

No, it also works on a standard data.frame if polyline is defined. So we can pass the 'h3' column in a similar way

Could we simply disable the update_view option for add_h3_hexagon() and think about this more later? Is the bbox used for anything else?

yes - this is what I'm doing for add_trips() at the moment.

SymbolixAU commented 4 years ago

Do you have any example data I can use to start testing this?

mitchelloharawild commented 4 years ago

Sure, here's a small set of h3 indices:

structure(list(h3 = c("85195187fffffff", "8519424bfffffff", "851951bbfffffff", 
"8519518ffffffff", "851951b7fffffff", "8519424ffffffff", "851951a7fffffff", 
"851951b3fffffff", "851951a3fffffff", "8519427bfffffff", "8519426bfffffff", 
"85194243fffffff", "85194247fffffff")), class = c("tbl_df", "tbl", 
"data.frame"), row.names = c(NA, -13L))

I've pushed my start to adding the layer here: https://github.com/mitchelloharawild/mapdeck/commit/9231a869487619232dd53d81538e03114352fcb6

SymbolixAU commented 4 years ago

thanks. If / when you make a PR can you request it into branch issue243 please.

mitchelloharawild commented 4 years ago

Can do. I'll probably have some more questions to come as I work on this more.

SymbolixAU commented 4 years ago

I might also update the underlying mapdeck/src and spatialwidget/api code to replace the 'polyline' in the function names to something more generic, like 'string' / 'character', or something else. I'll also document it here.

mitchelloharawild commented 4 years ago

So your polyline methods essentially pass the input data through to JS without additional processing? If so, using the same methods for h3 may be appropriate.

SymbolixAU commented 4 years ago

yes, exactly.

SymbolixAU commented 4 years ago

You should just be able to call rcpp_point_polyline() in place of this code

SymbolixAU commented 4 years ago

and for the js code you'll need to use the polyline method (without the decode_polyline() call).

mitchelloharawild commented 4 years ago

Is there something I'm missing here?

h3 <- structure(list(h3 = c("85195187fffffff", "8519424bfffffff", "851951bbfffffff",  "851951b7fffffff",  "851951a7fffffff",  "851951a3fffffff", "8519427bfffffff", "8519426bfffffff",  "85194247fffffff")), class = c("tbl_df", "tbl", 
                                                                                                                                                "data.frame"), row.names = c(NA, -13L))
mapdeck() %>% 
    add_h3_hexagon(h3, hexagon = "h3")

The data coming back doesn't include the h3 column, and I'm not sure what is being done in spatialwidget::api::create_polyline.

dcooley commented 4 years ago

Can you make a PR and I'll check it out?

mitchelloharawild commented 4 years ago

PR #244, thanks!

dcooley commented 3 years ago

As per https://github.com/SymbolixAU/mapdeck/pull/247, the basic example works and is on branch issue243. @mitchelloharawild thanks for getting this running. Sorry it took so long to get it pulled in.

dcooley commented 2 years ago

I've merged this in to master