odc-tools
odc-tools copied to clipboard
Add area limit to `select_on_map` function
Problem
The select_on_map
function would be a great replacement for the clunky manually defined query bounds we have in most of our notebooks.
However, the biggest limitation to interactive map selection in notebooks is nudging users to select reasonable-sized query areas: the first inclination is generally to select a huge area (e.g. all of Sydney or Queensland or Australia etc), which crashes memory and causes a poor user experience.
Proposed solution
By adding a size limit for the interactive area selection, users can have the flexibility of interactively selecting a study area without having it crash their memory. Including a param called area_limit
in the select_on_map
function could work:
from odc.ui import select_on_a_map
from datacube.utils.geometry import CRS
area_limit = 10000
geopolygon = select_on_a_map(height='600px',
center=(-33, 152),
zoom=12)
# Convert to a CRS with metre units and calculate area
area_ha = geopolygon.to_crs(crs = CRS('epsg:3577')).area / 10000
# Only return data if geopolygon is smaller than X
if area_limit is not None and area_ha < area_limit:
print('Do the thing')
else:
print('Your selection is greater than the maximum {area_limit) ha. Please re-run the function and select a smaller region')
How precise this needs to be? Would using epsg:3857
suffice or do we need user configurable projection? epsg:3577
only works for Australia.
An even more user-friendly alternative (or possibly addition) would be to visually signify that the area is too large by changing the colour of the dragged polygon when it exceeds the size limit. I suspect this probably isn't possible within the ipyleaflet
framework though:
@Kirill888 Not precise at all, I think epsg:3857
would suffice without any problem
I don't think leaflet draw plugin exposes events "while drawing", so no way to limit user input while dragging selection box. But we can certainly indicate that area is not acceptable after it was drawn.
Yeah, I think that would be fine, after all we get the little "54567.21 ha" popup below the rectangle that users can use to select an area < than the limit
This leaflet
documentation seems to suggest you can also customise the area units that are shown (see "PolygonOptions" and "RectangleOptions"). If that translates to ipyleaflet
, showing area in "km2" instead of "ha" would probably be more intuitive for users
http://leaflet.github.io/Leaflet.draw/docs/leaflet-draw-latest.html#RectangleOptions