Skip To Content

Access data on Microsoft Planetary Computer through ArcPy

You can access data on Microsoft Planetary Computer using the STAC API in ArcPy by constructing a search query. Use the query in arcpy.ia.RasterCollection.fromSTACAPI to create a RasterCollection object.

Example: Create a raster collection of NAIP images for the state of California in 2020.

query = { "collections": ["naip"], "query": {"naip:state": {"eq": 'ca'}}, "datetime": "2020-01-01/2020-12-31", "limit": 1000 } 
rc = arcpy.ia.RasterCollection.fromSTACAPI(stac_api="https://planetarycomputer.microsoft.com/api/stac/v1", query=query, attribute_dict={ "Name":"id", "StdTime":"datetime", "Spatial Reference":"proj:epsg", "Extent": "bbox" })

For details on how to construct a search query, see STAC API - Collection Search.

If you know the address of a raster item, you can use arcpy.Raster.fromSTACItem to create a Raster object.

Example: Create a raster of a single NAIP image.

raster = Raster.fromSTACItem(stac_item="https://planetarycomputer.microsoft.com/api/stac/v1/collections/naip/items/tx_m_2609719_se_14_060_20201217")

If the collection requires a token for access, such as Landsat-c2-l2, you must create an AIO object referencing the cloud storage connection file located at C:\AMPC_Resources\ACS_Files. before performing a search operation.

Example: Create an AIO object referencing the cloud storage connection file.

from arcpy import AIO 
a = AIO(r'C:\AMPC_Resources\ACS_Files\esrims_pc_landsat-c2-l2.acs')

Example: Create a RasterCollection object of Landsat-9 images covering the island of Hawaii in 2022.

a = AIO(r'C:\AMPC_Resources\ACS_Files\esrims_pc_landsat-c2-l2.acs') 
query = { "collections": ["landsat-c2-l2"], "bbox": [-156.1271927, 18.8710955, -154.7755921, 20.2990569], "query": {"platform": {"in": ["landsat-9"]}}, "datetime": "2022-01-01/2022-12-31", "limit": 1000 } 
rc = arcpy.ia.RasterCollection.fromSTACAPI(stac_api="https://planetarycomputer.microsoft.com/api/stac/v1", query=query, attribute_dict={ "Name":"id", "Cloud Cover":"eo:cloud_cover", "StdTime":"datetime", "Platform":"platform", "Spatial Reference":"proj:epsg", "Extent": "bbox" })

A number of Python notebook workflows are also available under C:\AMPC_Resources\Notebook_Examples.