{ "cells": [ { "cell_type": "markdown", "id": "9a817bd5", "metadata": {}, "source": [ "# NAIP\n", "\n", "## Overview\n", "`pcxarray` is a small Python package that provides a simple interface to interact with the Microsoft Planetary Computer Data Catalog. With this package, you can create queries using shapely geometries and retrieve results in GeoDataFrames such that you can examine item metadata and select assets for download, as well as automatically load and preprocess data into xarray DataArray.\n", "\n", "This example demonstrates how to use `pcxarray` to query NAIP imagery and load it into an xarray DataArray. The state of Mississippi is used as an example, but you can modify the code to query other states or regions." ] }, { "cell_type": "code", "execution_count": 1, "id": "6321cea1", "metadata": {}, "outputs": [], "source": [ "from pcxarray import pc_query, prepare_data, query_and_prepare\n", "from pcxarray.utils import create_grid, load_census_shapefile" ] }, { "cell_type": "markdown", "id": "1254cb5a", "metadata": {}, "source": [ "## Creating polygon grids\n", "\n", "You can use the `pcxarray` package to create polygon grids to subdivide a larger area into smaller sections. This is useful for processing large datasets in manageable chunks. The following code creates a grid of polygons over the state of Mississippi:" ] }, { "cell_type": "code", "execution_count": 2, "id": "cc0581da", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | REGION | \n", "DIVISION | \n", "STATEFP | \n", "STATENS | \n", "GEOID | \n", "GEOIDFQ | \n", "STUSPS | \n", "NAME | \n", "LSAD | \n", "MTFCC | \n", "FUNCSTAT | \n", "ALAND | \n", "AWATER | \n", "INTPTLAT | \n", "INTPTLON | \n", "geometry | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 44 | \n", "3 | \n", "6 | \n", "28 | \n", "01779790 | \n", "28 | \n", "0400000US28 | \n", "MS | \n", "Mississippi | \n", "00 | \n", "G4000 | \n", "A | \n", "121534116434 | \n", "3914302814 | \n", "+32.6864714 | \n", "-089.6561377 | \n", "POLYGON ((624275.848 1270567.752, 624241.051 1... | \n", "
| \n", " | geometry | \n", "
|---|---|
| 0 | \n", "POLYGON ((575558.025 1038674.182, 576558.025 1... | \n", "
| 1 | \n", "POLYGON ((576558.025 1038674.182, 577558.025 1... | \n", "
| 2 | \n", "POLYGON ((577558.025 1038674.182, 578558.025 1... | \n", "
| 3 | \n", "POLYGON ((578558.025 1038674.182, 579558.025 1... | \n", "
| 4 | \n", "POLYGON ((579558.025 1038674.182, 580558.025 1... | \n", "
| ... | \n", "... | \n", "
| 126807 | \n", "POLYGON ((636558.025 1577674.182, 637558.025 1... | \n", "
| 126808 | \n", "POLYGON ((637558.025 1577674.182, 638558.025 1... | \n", "
| 126809 | \n", "POLYGON ((638558.025 1577674.182, 639558.025 1... | \n", "
| 126810 | \n", "POLYGON ((639558.025 1577674.182, 640558.025 1... | \n", "
| 126811 | \n", "POLYGON ((640558.025 1577674.182, 641558.025 1... | \n", "
126812 rows × 1 columns
\n", "| \n", " | index | \n", "type | \n", "stac_version | \n", "stac_extensions | \n", "id | \n", "bbox | \n", "properties.gsd | \n", "properties.datetime | \n", "properties.naip:year | \n", "properties.proj:bbox | \n", "... | \n", "assets.tilejson.type | \n", "assets.tilejson.title | \n", "assets.tilejson.roles | \n", "assets.rendered_preview.href | \n", "assets.rendered_preview.type | \n", "assets.rendered_preview.title | \n", "assets.rendered_preview.rel | \n", "assets.rendered_preview.roles | \n", "collection | \n", "geometry | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "0 | \n", "Feature | \n", "1.1.0 | \n", "[https://stac-extensions.github.io/eo/v1.1.0/s... | \n", "ms_m_3008915_nw_16_060_20230701_20240103 | \n", "[-89.253589, 30.809596, -89.183951, 30.877901] | \n", "0.6 | \n", "2023-07-01 16:00:00 | \n", "2023 | \n", "[284556.0, 3410670.0, 291072.0, 3418116.0] | \n", "... | \n", "application/json | \n", "TileJSON with default rendering | \n", "[tiles] | \n", "https://planetarycomputer.microsoft.com/api/da... | \n", "image/png | \n", "Rendered preview | \n", "preview | \n", "[overview] | \n", "naip | \n", "POLYGON ((554157.957 1112863.988, 553974.736 1... | \n", "
| 1 | \n", "1 | \n", "Feature | \n", "1.1.0 | \n", "[https://stac-extensions.github.io/eo/v1.1.0/s... | \n", "ms_m_3008915_ne_16_060_20230701_20240103 | \n", "[-89.191032, 30.809639, -89.121497, 30.877913] | \n", "0.6 | \n", "2023-07-01 16:00:00 | \n", "2023 | \n", "[290538.0, 3410556.0, 297048.0, 3418002.0] | \n", "... | \n", "application/json | \n", "TileJSON with default rendering | \n", "[tiles] | \n", "https://planetarycomputer.microsoft.com/api/da... | \n", "image/png | \n", "Rendered preview | \n", "preview | \n", "[overview] | \n", "naip | \n", "POLYGON ((560133.48 1112897.003, 559950.208 11... | \n", "
| 2 | \n", "2 | \n", "Feature | \n", "1.1.0 | \n", "[https://stac-extensions.github.io/eo/v1.1.0/s... | \n", "ms_m_3008907_se_16_060_20230701_20240103 | \n", "[-89.191074, 30.872095, -89.121492, 30.940371] | \n", "0.6 | \n", "2023-07-01 16:00:00 | \n", "2023 | \n", "[290670.0, 3417480.0, 297180.0, 3424926.0] | \n", "... | \n", "application/json | \n", "TileJSON with default rendering | \n", "[tiles] | \n", "https://planetarycomputer.microsoft.com/api/da... | \n", "image/png | \n", "Rendered preview | \n", "preview | \n", "[overview] | \n", "naip | \n", "POLYGON ((560095.021 1119820.568, 559911.477 1... | \n", "
3 rows × 38 columns
\n", "