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
Classes
Interactive polygon drawing tool using ipyleaflet. |
Functions
|
Create an interactive polygon tool with predefined configurations. |
|
Search for satellite data using drawn polygons from the polygon tool. |
Module Contents
- 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
- basemap_layers
Dictionary of available basemap layers
- Type:
Dict
- print_available_basemaps(max_items: int = 10) None[source]
Print the available basemaps in a formatted way.
- _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:
- _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:
- _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
- 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:
- 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]