73 custom stac
Searching Geospatial Data Interactively with Custom STAC API Endpoints
Uncomment the following line to install leafmap if needed.
# %pip install -U leafmap
import os
from leafmap import leafmap
Provide custom STAC API endpoints as a dictionary in the format of {"name": "url"}
. The name will show up in the dropdown menu, while the url is the STAC API endpoint that will be used to search for items.
catalogs = {
"Element84 Earth Search": "https://earth-search.aws.element84.com/v1",
"Microsoft Planetary Computer": "https://planetarycomputer.microsoft.com/api/stac/v1",
}
Create an interactive map and click on the catalog button as shown below to open the catalog panel. Be sure to specify the catalog_source
parameter during the map creation.
m = leafmap.Map(center=[40, -100], zoom=4, catalog_source=catalogs)
m
Alternatively, you can also use the Map.set_catalog_source
method to specify the custom API endpoints.
m = leafmap.Map(center=[40, -100], zoom=4)
m.set_catalog_source(catalogs)
m
Another way to specify STAC API endpoints is to set the environment variable STAC_CATALOGS
to a dictionary in the format of {"name": "url"}
.
os.environ["STAC_CATALOGS"] = str(catalogs)
Then, you can create an interactive map as usual and click on the catalog button to open the catalog panel.
m = leafmap.Map()
m
The STAC GUI can also be open directly by calling the stac_gui()
function.
from leafmap.toolbar import stac_gui
stac_gui(m)
Once the catalog panel is open, you can search for items from the custom STAC API endpoints. Simply draw a bounding box on the map or zoom to a location of interest. Click on the Collections button to retrieve the collections from the custom STAC API endpoints. Next, select a collection from the dropdown menu. Then, click on the Items button to retrieve the items from the selected collection. Finally, click on the Display button to add the selected item to the map.
# m.stac_gdf # The GeoDataFrame of the STAC search results
# m.stac_dict # The STAC search results as a dictionary
# m.stac_item # The selected STAC item of the search result