leaflet
leaflet copied to clipboard
is it possible to extract an input data layer object from a leaflet map object?
is it possible to extract an input data layer object from a leaflet map object?
I'd like to create a functionality to inspect pixel values using leaflet
& mapedit
where the user would essentially call inspect()
on the leaflet map object which would open mapedit
on the specified leaflet map, they would draw geom(s), and it would pull the input layers objects from the map object for the relevant extraction/join to the geoms (i.e inspect <- function(map)
)
If this is not possible then the function would have to include the actual data object and map (i.e inspect <- function(map, data_layer_ob)
, but I wanted to check because the former option would be smoother if possible.
I am looking into this with the goal to simulate the inspect
functionality in the Google Earth Engine Code Editor
for rgee
objects in particular (https://github.com/r-spatial/rgee/issues/217 , https://github.com/r-earthengine/rgeeInspector).
@zackarno it seems you are talking about raster data added to a leaflet map that you want to access... If so, then I think it can't be done because the raster data is converted to a png object and there is no way ton infer raw values from that png (IINM). You can use mapview to set up the map, which will hold all data present on the map in the @object
slot of the mapview object. One caveat though is that for large rasters it may only point to a file on disk, which may not be available after map creation, depending on where it was stored when the map was created...
thanks @tim-salabim - that is useful to know - i was thinking about raster data generally, but in my use-case, which is a bit specific, they are actually ee$Image
classes. These are stored on the Google Earth Engine
servers and you can interact with them with GEE/rgee
functions without actually downloading them as typical rasters. In leaflet I believe they are displayed as tiles.
These images/pixels in the cloud be queried with GEE
functions like :
pt_ob_drawn<- mapedit::draw_features()
# this uploads the sf ob to the server
pt_ob_ee <- rgee::sf_as_ee(pt_ob_drawn)
# extracts the values (still on server-side)
pt_ob_with_vals_on_ee_server<- image_ob$sampleRegions(collection=pt_ob_ee , scale=numeric_scale_of_img)`
# and then you can download the values as data.frames
pt_ob_val_df <- rgee::ee_as_sf(pt_ob_with_vals_on_ee_server)
The maps are created basically like:
map1<- rgee::Map$addLayer(ee_image,...)
The rgee::Map$addLayer()
function calls leaflet/leafem
internally. If the returned map1
object had an @object
slot like in {mapview} it would be perfect.
So I am guessing you response probably still applies, but I was just wondering if you knew if it might be slightly different in this situation?
If it is the same issue, i wonder if the easiest solutions would be a GEE
mapping function that allows a {mapview} option so that we can access the @object
slot?
I think this is a question for the rgee
people.... @csaybar?