A Python package for geospatial analysis and interactive mapping in a Jupyter environment.
54
Evaluation — 54%
↓ 0.80xAgent success when using this tile
Integration with major cloud data providers and services including Microsoft Planetary Computer, NASA datasets, Planet Labs, AWS Open Data, and STAC catalogs for accessing large-scale geospatial datasets.
Search and access geospatial data through STAC catalogs with comprehensive filtering and visualization capabilities.
def stac_search(collection, bbox=None, time_range=None, **kwargs):
"""
Search STAC catalog for items matching criteria.
Args:
collection (str): STAC collection ID
bbox (list): Bounding box [minx, miny, maxx, maxy]
time_range (list): Time range ['start_date', 'end_date']
**kwargs: Additional search parameters (limit, query, etc.)
Returns:
list: List of matching STAC items
"""
def stac_assets(item, **kwargs):
"""
Get assets from STAC item.
Args:
item (dict): STAC item dictionary
**kwargs: Asset filtering options
Returns:
dict: Asset dictionary with URLs and metadata
"""
def add_stac_layer(self, url, collection=None, item=None, **kwargs):
"""
Add STAC layer to map.
Args:
url (str): STAC catalog, collection, or item URL
collection (str): Collection ID if using catalog URL
item (str): Item ID if using collection URL
**kwargs: Layer visualization options (assets, bands, rescale, etc.)
"""
def stac_tile(item, assets, **kwargs):
"""
Generate tiles from STAC item assets.
Args:
item (dict): STAC item
assets (list): Asset names to use for tiling
**kwargs: Tile generation options (rescale, colormap, etc.)
Returns:
str: Tile URL template
"""Access Microsoft Planetary Computer datasets including Landsat, Sentinel, MODIS, and other Earth observation data.
def get_pc_collections():
"""
Get list of available Planetary Computer collections.
Returns:
list: Collection names and descriptions
"""
def get_first_item(collection):
"""
Get first item from Planetary Computer collection.
Args:
collection (str): Collection ID
Returns:
dict: First STAC item in collection
"""
def get_bands(collection):
"""
Get available bands for Planetary Computer collection.
Args:
collection (str): Collection ID
Returns:
list: Band names and descriptions
"""
def get_pc_inventory(collection):
"""
Get inventory information for PC collection.
Args:
collection (str): Collection ID
Returns:
dict: Collection inventory metadata
"""
def pc_search(collection, bbox, time_range, **kwargs):
"""
Search Planetary Computer for data.
Args:
collection (str): PC collection name
bbox (list): Bounding box coordinates
time_range (list): Date range for search
**kwargs: Additional search parameters
Returns:
list: Matching STAC items
"""Access NASA Earth observation datasets including MODIS, VIIRS, and other satellite data products.
def nasa_data_search(dataset, bbox=None, time_range=None, **kwargs):
"""
Search NASA datasets.
Args:
dataset (str): NASA dataset identifier
bbox (list): Bounding box for spatial filtering
time_range (list): Time range for temporal filtering
**kwargs: Additional search parameters
Returns:
list: Matching dataset items
"""
def add_nasa_data(self, dataset, **kwargs):
"""
Add NASA dataset to map.
Args:
dataset (str): NASA dataset identifier or URL
**kwargs: Visualization options
"""
def nasa_cmr_search(short_name, **kwargs):
"""
Search NASA Common Metadata Repository.
Args:
short_name (str): Dataset short name
**kwargs: CMR search parameters (temporal, spatial, etc.)
Returns:
list: CMR search results
"""Access Planet Labs satellite imagery and data products including PlanetScope, RapidEye, and SkySat.
def planet_tiles(item_type, **kwargs):
"""
Get Planet Labs tile URLs.
Args:
item_type (str): Planet item type (PSScene4Band, etc.)
**kwargs: Planet API parameters
Returns:
dict: Tile URL templates and metadata
"""
def planet_search(item_types, bbox, date_range, **kwargs):
"""
Search Planet Labs catalog.
Args:
item_types (list): Planet item types to search
bbox (list): Bounding box for search
date_range (list): Date range for search
**kwargs: Planet search parameters (cloud_cover, etc.)
Returns:
list: Matching Planet items
"""
def add_planet_layer(self, item_id, item_type, **kwargs):
"""
Add Planet Labs imagery layer.
Args:
item_id (str): Planet item ID
item_type (str): Planet item type
**kwargs: Layer visualization options
"""Access geospatial datasets hosted on AWS including Landsat, Sentinel, and other public datasets.
def s3_list_objects(bucket, prefix='', **kwargs):
"""
List objects in S3 bucket.
Args:
bucket (str): S3 bucket name
prefix (str): Object key prefix for filtering
**kwargs: S3 listing options (max_keys, delimiter, etc.)
Returns:
list: S3 object keys and metadata
"""
def s3_download(bucket, key, filename, **kwargs):
"""
Download file from S3.
Args:
bucket (str): S3 bucket name
key (str): S3 object key
filename (str): Local output filename
**kwargs: Download options
Returns:
str: Path to downloaded file
"""
def add_s3_layer(self, bucket, key, **kwargs):
"""
Add raster layer from S3.
Args:
bucket (str): S3 bucket name
key (str): S3 object key
**kwargs: Layer visualization options
"""Work with Cloud Optimized GeoTIFFs for efficient web-based raster visualization and analysis.
def cog_tile(url, **kwargs):
"""
Generate tile URL template for COG.
Args:
url (str): COG file URL
**kwargs: Tile generation options (rescale, colormap, etc.)
Returns:
str: Tile URL template
"""
def cog_info(url):
"""
Get information about COG file.
Args:
url (str): COG file URL
Returns:
dict: COG metadata (bands, CRS, bounds, etc.)
"""
def cog_stats(url, **kwargs):
"""
Calculate statistics for COG.
Args:
url (str): COG file URL
**kwargs: Statistics options (bands, percentiles, etc.)
Returns:
dict: Band statistics
"""
def add_cog_layer(self, url, name='Untitled', **kwargs):
"""
Add COG layer to map.
Args:
url (str): COG file URL
name (str): Layer name
**kwargs: Visualization options (bands, rescale, colormap, etc.)
"""Access Overture Maps Foundation data including buildings, transportation, places, and administrative boundaries.
def get_overture_data(bbox, theme, **kwargs):
"""
Get Overture Maps data for bounding box.
Args:
bbox (list): Bounding box [minx, miny, maxx, maxy]
theme (str): Overture theme ('buildings', 'transportation', 'places', 'admins')
**kwargs: Overture query options (type, subtypes, etc.)
Returns:
gpd.GeoDataFrame: Overture data as GeoDataFrame
"""
def add_overture_layer(self, bbox, theme, **kwargs):
"""
Add Overture Maps layer to map.
Args:
bbox (list): Bounding box for data query
theme (str): Overture data theme
**kwargs: Layer styling and filtering options
"""Integration with TiTiler for dynamic tiling of raster data from various sources.
class TitilerEndpoint:
"""TiTiler endpoint for dynamic raster tiling."""
def __init__(self, endpoint='https://titiler.xyz'):
"""
Initialize TiTiler endpoint.
Args:
endpoint (str): TiTiler service URL
"""
def tile_url(self, url, **kwargs):
"""
Generate tile URL for raster.
Args:
url (str): Raster data URL
**kwargs: Tile parameters (rescale, colormap, etc.)
Returns:
str: Tile URL template
"""
def info(self, url):
"""
Get raster information.
Args:
url (str): Raster data URL
Returns:
dict: Raster metadata
"""import leafmap
# Search STAC catalog
items = leafmap.stac_search(
collection='landsat-c2-l2',
bbox=[-122.5, 37.7, -122.3, 37.8], # San Francisco
time_range=['2023-01-01', '2023-12-31'],
query={'eo:cloud_cover': {'lt': 10}}
)
print(f"Found {len(items)} items")
# Create map and add STAC layer
m = leafmap.Map(center=[37.75, -122.4], zoom=10)
if items:
m.add_stac_layer(
url=items[0]['assets']['rendered_preview']['href'],
name='Landsat Image'
)
mimport leafmap
# List available collections
collections = leafmap.get_pc_collections()
print("Available collections:", collections[:5])
# Search for Sentinel-2 data
items = leafmap.pc_search(
collection='sentinel-2-l2a',
bbox=[-74.1, 40.7, -73.9, 40.8], # New York City
time_range=['2023-06-01', '2023-06-30']
)
# Create map and visualize
m = leafmap.Map(center=[40.75, -74.0], zoom=10)
if items:
m.add_stac_layer(
url=items[0]['self_href'],
assets=['B04', 'B03', 'B02'], # RGB bands
rescale='0,3000',
name='Sentinel-2 RGB'
)
mimport leafmap
# Search Planet catalog (requires API key)
items = leafmap.planet_search(
item_types=['PSScene4Band'],
bbox=[-122.5, 37.7, -122.3, 37.8],
date_range=['2023-07-01', '2023-07-31'],
cloud_cover=0.1
)
# Add Planet imagery
m = leafmap.Map(center=[37.75, -122.4], zoom=12)
if items:
m.add_planet_layer(
item_id=items[0]['id'],
item_type='PSScene4Band',
name='Planet Image'
)
mimport leafmap
# COG from public dataset
cog_url = 'https://cloud.sdsc.edu/v1/AUTH_opentopography/Raster/SRTMGL1_Ellip_srtm/SRTMGL1_Ellip_srtm_09_05.tif'
# Get COG information
info = leafmap.cog_info(cog_url)
print("COG info:", info)
# Create map and add COG layer
m = leafmap.Map()
m.add_cog_layer(
url=cog_url,
name='SRTM Elevation',
colormap='terrain',
rescale='0,4000'
)
mimport leafmap
# List objects in public bucket
objects = leafmap.s3_list_objects(
bucket='sentinel-s2-l2a',
prefix='tiles/32/T/NM/2023/7/15/',
max_keys=10
)
# Add S3-hosted raster
m = leafmap.Map()
if objects:
key = objects[0]['Key'] # First object
m.add_s3_layer(
bucket='sentinel-s2-l2a',
key=key,
name='Sentinel-2 from S3'
)
mimport leafmap
# Get building data from Overture Maps
buildings = leafmap.get_overture_data(
bbox=[-122.42, 37.77, -122.41, 37.78], # Small area in SF
theme='buildings',
type='building'
)
print(f"Found {len(buildings)} buildings")
# Visualize on map
m = leafmap.Map(center=[37.775, -122.415], zoom=16)
m.add_gdf(
buildings,
layer_name='Overture Buildings',
style={'fillColor': 'blue', 'fillOpacity': 0.5}
)
mimport os
# Set API keys as environment variables
os.environ['PLANET_API_KEY'] = 'your_planet_api_key'
os.environ['NASA_API_KEY'] = 'your_nasa_api_key'
os.environ['MAPBOX_TOKEN'] = 'your_mapbox_token'
# Or configure in code (not recommended for production)
import leafmap
leafmap.set_api_key('planet', 'your_api_key')# Common STAC endpoints
stac_endpoints = {
'planetary_computer': 'https://planetarycomputer.microsoft.com/api/stac/v1',
'earth_search': 'https://earth-search.aws.element84.com/v1',
'usgs_landsat': 'https://landsatlook.usgs.gov/stac-server',
'copernicus_dataspace': 'https://catalogue.dataspace.copernicus.eu/stac'
}landsat-c2-l2: Landsat Collection 2 Level 2sentinel-2-l2a: Sentinel-2 Level 2Asentinel-1-rtc: Sentinel-1 Radiometric Terrain Correctionmodis: MODIS satellite datanaip: National Agriculture Imagery Programaster-l1t: ASTER Level 1Tcop-dem-glo-90: Copernicus DEM Global 90mPSScene4Band: PlanetScope 4-band imageryPSScene: PlanetScope 3-band imageryREScene: RapidEye imagerySkySatScene: SkySat imageryREOrthoTile: RapidEye ortho tilesInstall with Tessl CLI
npx tessl i tessl/pypi-leafmapdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10