Skip to main content

Query and access Microsoft Planetary Computer Data Catalogs using geopandas and xarray.

Project description

pcxarray

A Python package for easy querying and access to Microsoft Planetary Computer Data Catalogs using geopandas and xarray.

Features

  • Query Microsoft Planetary Computer STAC API using shapely geometries
  • Retrieve results as GeoDataFrames for easy inspection and filtering
  • Download and preprocess raster data into xarray DataArrays
  • Utilities for creating spatial grids and loading US Census TIGER shapefiles

Installation

pcxarray can be installed via pip.

python -m pip install pcxarray

Alternatively, you can install the development version directly from GitHub:

git clone https://github.com/gcermsu/pcxarray
cd pcxarray
python -m pip install -e ".[dev]"

Usage

See naip_demo.ipynb for a complete example of querying NAIP imagery.

from pcxarray import pc_query, prepare_data, query_and_prepare
from pcxarray.utils import create_grid, load_census_shapefile

# Load US state boundaries
states_gdf = load_census_shapefile(level="state")

# Select a state (e.g., Mississippi)
ms_gdf = states_gdf[states_gdf['STUSPS'] == 'MS']
ms_gdf = ms_gdf.to_crs(epsg=3814) # Reproject to a projected CRS (e.g., EPSG:3814 for Mississippi)

# Create a grid over the state
grid_gdf = create_grid(
    ms_gdf.iloc[0].geometry,
    crs=ms_gdf.crs,
    cell_size=1000 # each cell will be 1000 meters square (units depend on the CRS)
)
selected_geom = grid_gdf.iloc[10000].geometry # Select a single geometry for demonstration

# Query NAIP imagery for a grid cell
items_gdf = pc_query(
    collections='naip',
    geometry=selected_geom,
    crs=grid_gdf.crs,
    datetime='2023'
)

# Download and load NAIP data as an xarray DataArray - imagery is clipped to the 
# geometry of the given geometry, and a mosaic is created if the geometry spans 
# multiple indiviudual items.
imagery = prepare_data(
    geometry=selected_geom,
    crs=grid_gdf.crs,
    items_gdf=items_gdf,
    target_resolution=1.0
)

# Or combine query and load in one step
imagery = query_and_prepare(
    collections='naip',
    geometry=selected_geom,
    crs=grid_gdf.crs,
    datetime='2023',
    target_resolution=1.0
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pcxarray-0.1.0.tar.gz (1.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pcxarray-0.1.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file pcxarray-0.1.0.tar.gz.

File metadata

  • Download URL: pcxarray-0.1.0.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for pcxarray-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3224ff52d62078d2bac229da6da9aeca19b519ebc58fde9502487c87f8abd2d8
MD5 8ab026e6d54a6f55620e1912ff1dacc2
BLAKE2b-256 cada8dddee055f4ee0f1bdc3a814d7306271363fe49473ee071a36790055f508

See more details on using hashes here.

File details

Details for the file pcxarray-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pcxarray-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for pcxarray-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b54636257d2eee0a8d07f1a66e65335ac38ee74e2059b42e9aa496546b328312
MD5 f4436e6d70045e71b24a840af0b33db1
BLAKE2b-256 9f40bac137a2c75314b1425ed64ee309be661dec09b3bc489abe0c459571ece9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page