# include all your imports in this cell
import folium
import requests
Template (Using the raster API)
This notebook is intended to act as a template for the example notebooks that use the raster API. These green cells should all be deleted and in several sections only one of the provided cells should be included in the notebook.
Update the link in the following section.
Run this notebook
You can launch this notbook using mybinder, by clicking the button below.
Fill in the text in italics in the following cells
Approach
- list a few steps that outline the approach
- you will be taking in this notebook
About the data
Optional description of the dataset.
Declare your collection of interest
You can discover available collections the following ways:
- Programmatically: see example in the
list-collections.ipynb
notebook - JSON API: https://openveda.cloud/api/stac/collections
- STAC Browser: http://openveda.cloud
= "https://openveda.cloud/api/stac"
STAC_API_URL = "https://openveda.cloud/api/raster"
RASTER_API_URL
= collection_id
Next step is to get STAC objects from the STAC API. In some notebooks we get the collection and use all the items, and in others we search for specific items.
Fetch STAC collection
We will use requests
to fetch all the metadata about the collection of interest from STAC.
= requests.get(f"{STAC_API_URL}/collections/{collection_id}").json()
collection collection
Fetch STAC item for a particular time
We can use the search API to find the item that matches exactly our time of interest.
= requests.post(
response f"{STAC_API_URL}/search",
={
json"collections": [collection_id],
"query": {"datetime": {"eq": "2021-01-01T00:00:00"}},
"limit": 100,
},
).json()= response["features"] items
The next step is often to define an Area of Interest. Note that it is preferred to get large geojson objects directly from their source rather than storing them in this repository or inlining them in the notebook. Here is an example of what that might look like.
Define an AOI
We can fetch GeoJSON for metropolitan France and Corsica (excluding overseas territories) from an authoritative online source (https://gadm.org/download_country.html).
= requests.get(
response "https://geodata.ucdavis.edu/gadm/gadm4.1/json/gadm41_FRA_0.json"
)
# If anything goes wrong with this request output error contents
assert response.ok, response.text
= response.json()
result print(f"There are {len(result['features'])} features in this collection")
That is the geojson for a feature collection, but since there is only one feature in it we can grab just that.
= result["features"][0] aoi
Let’s take a look at this AOI on a map
= folium.Map(
m =[40, 0],
location=2,
zoom_start
)
="AOI").add_to(m)
folium.GeoJson(aoi, name m
With the STAC object and optionally the AOI in hand, the next step is to do some analysis. The sections in the rest of the notebooks are totally up to you! Here is one idea though :)
Use the STAC Item to get tiles with the RASTER API
We pass the item_id, collection id, and rescale_values
in to the RASTER API /collections/{collection_id}/items/{item_id}/tilejson.json
endpoint and get back a tile. See the tips below for choosing visualization parameters for your tiles.
Colormap Tip:
Find the list of available colormaps at {RASTER_API}/colorMaps
(openveda.cloud/api/raster/colorMaps) and get colormap metadata and/or legend image at {RASTER_API}/colorMaps/{colorMapName}
(See docs at openveda.cloud/api/raster/docs#/ColorMaps/getColorMap)
Tiling schemes Tip:
Find the list of available tile matrix set ids at {RASTER_API}/tileMatrixSets
(openveda.cloud/api/raster/tileMatrixSets) and get tiling scheme metadata at {RASTER_API}/colorMaps/{colorMapName}
(See docs at openveda.cloud/api/raster/docs#/tileMatrixSets/tileMatrixSetId)
Raster rescale range tip:
Get the statistics for item assets at {RASTER_API}/collections/{collection_id/items/{item_id}/statistics
()
# Start with the first item returned = items[0] item # Here is a default tile matrix id = "WebMercatorQuad" tile_matrix_set_id # Adjust these values to find the ideal range for the range of data you will be visualizing = 0 rescale_min = 1 rescale_max # Set the asset key you want to visualize (many STAC Items in the VEDA catalog have a cog_default assets) = "cog_default" asset_key # Choose a colormap = "viridis" colormap_name # Use stac item url with to get tilejson from raster api = f"{RASTER_API_URL}/collections/{collection_id}/items/{item['id']}/{tile_matrix_set_id}/tilejson.json" url = requests.get( tiles url,= { params "assets": asset_key, "colormap_name": colormap_name, "rescale": f"{rescale_min},{rescale_max}" } ).json() tiles
With that tile url in hand we can create a simple visualization using folium
.
folium.Map(=tiles["tiles"][0],
tiles="VEDA",
attr )