Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extent Viewer for collections #63

Open
przell opened this issue May 12, 2021 · 6 comments
Open

Extent Viewer for collections #63

przell opened this issue May 12, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@przell
Copy link
Member

przell commented May 12, 2021

Another convenience function would be to have a function like view_extent(collection_name). It could take the coordinates from the metadata and create a mapview for example. Would be helpful for researchers when prototyping so that they don't select regions outside of the bounding box of the collection. This would reduce the possible error source of going out of extent.

@przell
Copy link
Member Author

przell commented May 12, 2021

Here I gave it a shot. I tested it with a couple of collections on our Eurac Backend and it worked nicely.
If you agree I'd do a pull request. It would add the mapview dependency to the openeo r library (if its not there already anyway).

extent_viewer = function(collection){
  extent = openeo::describe_collection(collection)$extent$spatial
  extent = sf::st_bbox(obj = c(xmin = extent[1], 
                               xmax = extent[3], 
                               ymax = extent[4], 
                               ymin = extent[2]), 
                       crs = sf::st_crs(4326))
  mapview::mapview(extent)}

image

@flahn
Copy link
Member

flahn commented May 13, 2021

I had initially some mapview / leaflet features included, e.g. https://github.com/Open-EO/openeo-r-client/blob/feature/mapview_integration/R/map-functions.R. I removed them, because of the additional dependencies. Also it is not sure that all user want to use mapview, there might be some alternatives as well. However, you included a function to extract the bounding box, that would be something worth adding, in my oppinion. sf is a widely adopted geo package and many other packages reference to it as well. Other sf operations might follow in the future like the different topological operators to use for cropping or masking.

@przell
Copy link
Member Author

przell commented May 14, 2021

Ah right, forgot about that branch. Sorry. Fully understand the dependency issue. On the other hand, the interaction with mapview/mapedit and openEO creates a nice user experience. We can think about how to make this available to the user.
In this case I think it's already great if we have a function as described above to extract the bounding box into a sf object.

get_extent = function(collection){
  extent = openeo::describe_collection(collection)$extent$spatial
  extent = sf::st_bbox(obj = c(xmin = extent[1], 
                               xmax = extent[3], 
                               ymax = extent[4], 
                               ymin = extent[2]), 
                       crs = sf::st_crs(4326))
  return(extent)}

Then the user can decide to use it in mapview(). Could be added to the examples of the function.

mapview(get_extent(collection))

@m-mohr
Copy link
Member

m-mohr commented Jul 2, 2021

extent = sf::st_bbox(obj = c(xmin = extent[1],
xmax = extent[3],
ymax = extent[4],
ymin = extent[2]),
crs = sf::st_crs(4326))

This could fail for bboxes which include a z-axis. Then the 3rd and 6th element are for z and you need to use the 1st, 2nd, 4th and 5th elements.

@m-mohr m-mohr added the enhancement New feature or request label Oct 7, 2021
@benjaminschwetz
Copy link

as a workaround, have you considered limiting the dependency to this fun with requireNamespace(), see e.g. shinydashboardPlus::shinydashboardPlusGallery() https://github.com/RinteRface/shinydashboardPlus/blob/master/R/shinydashboardPlusGallery.R

get_extent = function(collection){
  if (!requireNamespace(package = "mapview"))
    message("Package 'mapview' is required to run this function")
  extent = openeo::describe_collection(collection)$extent$spatial
  extent = sf::st_bbox(obj = c(xmin = extent[1], 
                               xmax = extent[3], 
                               ymax = extent[4], 
                               ymin = extent[2]), 
                       crs = sf::st_crs(4326))
  mapview::mapview(extent)}

@przell
Copy link
Member Author

przell commented Dec 2, 2021

Nice solution! We're still thinking about how to include mapview and other packages with more dependencies into the openeo package without overloading it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants