phidown.interactive_tools

Interactive polygon drawing tool for geospatial analysis using ipyleaflet.

This module provides the InteractivePolygonTool class for drawing polygons on interactive maps with real-time WKT export functionality, multiple basemap layers, and seamless integration with phidown search capabilities.

Attributes

pandas

Classes

InteractivePolygonTool

Interactive polygon drawing tool using ipyleaflet.

Functions

create_polygon_tool(, zoom, basemap_type, ...)

Create an interactive polygon tool with predefined configurations.

search_with_polygon(→ Optional[pandas.DataFrame])

Search for satellite data using drawn polygons from the polygon tool.

Module Contents

phidown.interactive_tools.pandas = None[source]
class phidown.interactive_tools.InteractivePolygonTool(center: tuple = (45.0, 0.0), zoom: int = 2, basemap=basemaps.OpenStreetMap.Mapnik, show_basemap_switcher: bool = True)[source]

Interactive polygon drawing tool using ipyleaflet.

This class provides functionality to draw polygons on an interactive map, extract coordinates in WKT format, and manage multiple polygons with comprehensive basemap support.

map

The ipyleaflet map widget

Type:

Map

draw_control

Drawing control for the map

Type:

DrawControl

output

Output widget for displaying information

Type:

Output

wkt_output

Text area for WKT output

Type:

Textarea

polygons[source]

List of drawn polygons with metadata

Type:

List[Dict]

basemap_layers

Dictionary of available basemap layers

Type:

Dict

show_basemap_switcher[source]

Whether to show basemap switcher controls

Type:

bool

polygons: List[Dict[str, Any]] = [][source]
show_basemap_switcher = True[source]
current_basemap[source]
_setup_basemap_layers() None[source]

Setup available basemap layers organized by categories.

print_available_basemaps(max_items: int = 10) None[source]

Print the available basemaps in a formatted way.

_setup_map(center: tuple, zoom: int, basemap) None[source]

Setup the main map widget.

Parameters:
  • center (tuple) – Map center coordinates

  • zoom (int) – Initial zoom level

  • basemap – Basemap to use

_get_basemap_name(basemap) str[source]

Get the display name for a basemap object.

Parameters:

basemap – The basemap object

Returns:

The display name of the basemap

Return type:

str

_setup_controls() None[source]

Setup drawing controls for the map.

_setup_ui() None[source]

Setup the user interface widgets.

_change_basemap(change) None[source]

Change the basemap when dropdown selection changes.

Parameters:

change – The change event from the dropdown

_handle_draw(target, action, geo_json: Dict[str, Any]) None[source]

Handle drawing events.

Parameters:
  • target – The draw control target

  • action – The action performed

  • geo_json (Dict) – GeoJSON representation of the drawn feature

_handle_data_change(change) None[source]

Handle changes in the draw control data (edits and deletions).

Parameters:

change – The change event containing new and old data

_add_polygon(geo_json: Dict[str, Any]) None[source]

Add a polygon to the internal storage.

Parameters:

geo_json (Dict) – GeoJSON representation of the polygon

_coordinates_to_wkt(coordinates: List[List[List[float]]]) str[source]

Convert polygon coordinates to WKT format.

Parameters:

coordinates (List) – Polygon coordinates in GeoJSON format

Returns:

WKT representation of the polygon

Return type:

str

_update_wkt_output() None[source]

Update the WKT output textarea with current polygons.

_clear_all(button) None[source]

Clear all drawn polygons.

Parameters:

button – The button widget that triggered this event

_copy_wkt(button) None[source]

Copy WKT to clipboard (display instruction).

Parameters:

button – The button widget that triggered this event

_load_wkt(button) None[source]

Load WKT string and display on map.

Parameters:

button – The button widget that triggered this event

get_wkt_polygons() List[str][source]

Get all drawn polygons as WKT strings.

Returns:

List of WKT strings for all polygons

Return type:

List[str]

display() ipywidgets.VBox[source]

Display the complete polygon tool interface.

Returns:

The complete UI widget

Return type:

VBox

phidown.interactive_tools.create_polygon_tool(center: tuple = (45.0, 0.0), zoom: int = 2, basemap_type: str = 'osm', show_basemap_switcher: bool = True) InteractivePolygonTool[source]

Create an interactive polygon tool with predefined configurations.

Parameters:
  • center (tuple) – Initial map center coordinates (lat, lon)

  • zoom (int) – Initial zoom level

  • basemap_type (str) – Type of basemap to use: - ‘osm’: OpenStreetMap - ‘satellite’: Esri World Imagery - ‘topo’: Esri World Topo - ‘dark’: CartoDB Dark Matter - ‘terrain’: Stadia Terrain - ‘night’: NASA Earth at Night

  • show_basemap_switcher (bool) – Whether to show basemap switcher

Returns:

Configured polygon tool instance

Return type:

InteractivePolygonTool

phidown.interactive_tools.search_with_polygon(polygon_tool: InteractivePolygonTool, collection_name: str = 'SENTINEL-2', product_type: str = 'S2MSI1C', start_date: str = '2024-01-01T00:00:00', end_date: str = '2024-01-31T00:00:00', cloud_cover_threshold: int = 20, top: int = 10) pandas.DataFrame | None[source]

Search for satellite data using drawn polygons from the polygon tool.

Parameters:
  • polygon_tool (InteractivePolygonTool) – The polygon tool instance

  • collection_name (str) – Satellite collection name

  • product_type (str) – Product type to search for

  • start_date (str) – Start date for search

  • end_date (str) – End date for search

  • cloud_cover_threshold (int) – Maximum cloud cover percentage

  • top (int) – Maximum number of results

Returns:

Search results or None if no polygons drawn

Return type:

Optional[pandas.DataFrame]