eodag icon indicating copy to clipboard operation
eodag copied to clipboard

Possibility to plot a SearchResult?

Open maximlt opened this issue 4 years ago • 1 comments

Most of our tutorials use either ipyleaflet or folium to map the results of a search, and sometimes to play around with those results (e.g. select those that will be downloaded).

It might be interesting to add a method to SearchResult to plot:

  • the searched extent (that requires that we add the search params to SearchResult)
  • the extent of each EOProduct contained in the SearchResult

Its signature in its simplest form could be:

def plot(self, file=None) -> Map:
    ...

It would return the Map object (whatever library we use) and a user would be able to save it directly to a HTML file (useful is used outside of a notebook).

The obvious candidates are folium and ipyleaflet. The one that pulls the less number of heavy dependencies should be favored.

Some interesting features that this method could have:

  • Display a property (e.g. product id) on hover
  • Display all the properties of a product when it's clicker
  • A range timeslider to temporally filter the products

maximlt avatar Mar 25 '21 09:03 maximlt

Here is a suggestion of a method for adjusting the centering and zooming on the selected area:

import folium
from numpy import mean

EOLat = [product.geometry.centroid.y for product in search_results]
EOLong = [product.geometry.centroid.x for product in search_results]

# Create a map zoomed over the search area
fmap = folium.Map([mean(EOLat), mean(EOLong)], control_scale=True)

sw = [min(EOLat), min(EOLong)]
ne = [max(EOLat), max(EOLong)]

fmap.fit_bounds([sw, ne])

# Create a layer that maps the products found
folium.GeoJson(
    data=search_results,  # SearchResult has a __geo_interface__ interface used by folium to get its GeoJSON representation
    tooltip=folium.GeoJsonTooltip(fields=["title"])
).add_to(fmap)
fmap

anesson-cs avatar Sep 13 '22 07:09 anesson-cs