- "text": "STAC\nIn the examples above, we have looked at single images or relatively small areas. In the past years the amount of data that we are capturing has been growing. Web services are not suitable for sharing very large quantities of multimodal or multidimensional data. Searching and accessing these volumes of data can be done using the Spatial Temporal Asset Catalogue (STAC).\nThis is a short (and incomplete) description of what STAC is and how to use it. For a more elaborate tutorial visit the dedicated STAC tutorial.\nSTAC is a standard with a strong community working on enabling easier access to data about our planet. It provides a standardized structure for accessing spatiotemporal datasets. The starting point is usually a STAC catalog, for example https://stac.ecodatacube.eu/. This website is a visual representation of a catalog.json file, that can be accessed by clicking on the source button in the top right. It is possible to search the catalog programmatically, and is discussed in the STAC Tutorial. An alternative is to browse through the viewer and find relevant datasets there.\nA STAC catalog consists of a links to collections, items or other catalogs. A STAC collection is a collection of STAC items with similar traits. For example https://s3.ecodatacube.eu/arco/stac/oc_iso.10694.1995.mg.cm3/collection.json (that can be found through the ecodatacube catalog). This collection, is a collection of STAC items regarding the soil organic carbon density (SOCD). In this case it links to datasets at different depths, at different timeframes.\nGenerally these separate datasets can be found by a url stored in the items. These urls point, in the case of raster data, to a Cloud Optimized GeoTiff (COG). This is a Tiff file as we know it, it also ends at .tiff, but it contains some indexing and other metadata that makes the file searchable remotely instead of having to download the entire file before being able to for example mask a part of it.\n\nimport rasterio\nfrom rasterio.mask import mask\nfrom shapely import box\nimport matplotlib.pyplot as plt\n\n# Redefine the bounding box in the available crs (see before), now in EPSG:3035 to match the raster\nx, y = 4024900, 3215843.5\nbbox = box(x - 3579, y - 2134.5, x + 3579, y + 2134.5) # In EPSG:3035 - same as raster\n\n# get url from item asset link\nasset_url = 'https://s3.ecodatacube.eu/arco/ndvi_glad.landsat.ard2.seasconv.m.yearly_p25_30m_s_20220101_20221231_eu_epsg.3035_v20231127.tif'\n\n# open raster directly from S3 (requires rasterio with HTTP enabled, which is default)\nwith rasterio.open(asset_url) as src:\n # crop the raster with the polygon\n out_image, out_transform = mask(src, [bbox], crop=True)\n\n# plot the cropped raster\nplt.imshow(out_image[0], cmap=\"viridis\")\n\n<matplotlib.image.AxesImage object at 0x00000225280D4410>\n\nplt.title(\"Cropped raster over Wageningen\")\n\nText(0.5, 1.0, 'Cropped raster over Wageningen')\n\nplt.colorbar(label=\"Value\")\n\n<matplotlib.colorbar.Colorbar object at 0x00000225282C4790>\n\nplt.show()"
0 commit comments