odc-tools icon indicating copy to clipboard operation
odc-tools copied to clipboard

Add area limit to `select_on_map` function

Open robbibt opened this issue 4 years ago • 6 comments

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')

robbibt avatar Feb 28 '20 04:02 robbibt

How precise this needs to be? Would using epsg:3857 suffice or do we need user configurable projection? epsg:3577 only works for Australia.

Kirill888 avatar Feb 28 '20 04:02 Kirill888

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:

image

image

robbibt avatar Feb 28 '20 04:02 robbibt

@Kirill888 Not precise at all, I think epsg:3857 would suffice without any problem

robbibt avatar Feb 28 '20 04:02 robbibt

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.

Kirill888 avatar Feb 28 '20 04:02 Kirill888

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

robbibt avatar Feb 28 '20 04:02 robbibt

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

robbibt avatar Feb 28 '20 04:02 robbibt