Possibility to plot a SearchResult?
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
EOProductcontained in theSearchResult
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
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