{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Create and manipulate SpaceNet Vegas STAC" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This tutorial shows how to create and manipulate STACs using pystac.\n", "\n", "- Create (in memory) a pystac catalog of [SpaceNet 2 imagery from the Las Vegas AOI](https://spacenetchallenge.github.io/AOI_Lists/AOI_2_Vegas.html) using data hosted in a public s3 bucket\n", "- Set relative paths for all STAC object\n", "- Normalize links from a root directory and save the STAC there" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "import sys\n", "\n", "sys.path.append(\"..\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You may need install the following packages that are not included in the Python 3 standard library. If you do not have any of these installed, you can do do with pip:\n", "\n", "[boto3](https://pypi.org/project/boto3/): `pip install boto3` \n", "[botocore](https://pypi.org/project/botocore/): `pip install botocore` \n", "[rasterio](https://pypi.org/project/rasterio/): `pip install rasterio` \n", "[shapely](https://pypi.org/project/Shapely/): `pip install Shapely` \n", "[rio-cogeo](https://github.com/cogeotiff/rio-cogeo): `pip install rio-cogeo`" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "from datetime import datetime\n", "from os.path import basename, join\n", "\n", "import boto3\n", "import rasterio\n", "import pystac\n", "from shapely.geometry import GeometryCollection, box, shape, mapping" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Create SpaceNet Vegas STAC" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Initialize a STAC for the SpaceNet 2 dataset" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "spacenet = pystac.Catalog(id=\"spacenet\", description=\"SpaceNet 2 STAC\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We do not yet know the spatial extent of the Vegas AOI. We will need to determine it when we download all of the images. As a placeholder we will create a spatial extent of null values." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "sp_extent = pystac.SpatialExtent([None, None, None, None])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The capture date for SpaceNet 2 Vegas imagery is October 22, 2015. Create a python datetime object using that date" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "capture_date = datetime.strptime(\"2015-10-22\", \"%Y-%m-%d\")\n", "tmp_extent = pystac.TemporalExtent([(capture_date, None)])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create an Extent object that will define both the spatial and temporal extents of the Vegas collection" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "extent = pystac.Extent(sp_extent, tmp_extent)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a collection that will encompass the Vegas data and add to the spacenet catalog" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "