Skip to main content

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

Project description

pcxarray

PyPI version License: MIT

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.2.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.2-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pcxarray-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4662dab6e95de9ba489e1eb0918093d512e16db3c5749b3e29fb1eef7960ba52
MD5 eb4440b9478098f964049604c1f3a923
BLAKE2b-256 e6c90e274c6505cf4eba186d987ee4f7f4cb2dde57a240011f0ca518deb6e710

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pcxarray-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 31fc828cb1abcf4572fcb1cb50af82f997a4d946dd0d1f407d5eb142b13555dd
MD5 426eb48cb104cfc1a8d55c555b7df34c
BLAKE2b-256 c55ea4c695223367f7eb290e3168df5bc0df24dc8a22efb141605edee3d09b69

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