diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 911617d..faaa6fa 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -51,8 +51,11 @@ jobs: uses: conda-incubator/setup-miniconda@v2 with: auto-update-conda: true + environment-file: environment.yml python-version: ${{ matrix.python-version }} - - name: Update Conda's environemnt - run: conda env update -f environment.yml -n test + - name: update certs so PROJ can download the us_noaa_cshpgn.tif file + run: | + sudo mkdir -p /etc/pki/tls/certs + sudo curl https://curl.se/ca/cacert.pem -o /etc/pki/tls/certs/ca-bundle.crt - name: Execute linters and test suites run: ./scripts/cibuild diff --git a/CHANGELOG.md b/CHANGELOG.md index 70c249a..e86088a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Added + +- Add Projection Extension field proj:centroid ([#38](https://github.com/stactools-packages/naip/pull/38)) + ## [v0.3.1] - 2023-02-24 ### Fixed diff --git a/setup.cfg b/setup.cfg index 06b3f1c..b89e2f6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,6 +31,5 @@ packages = find_namespace: install_requires = stactools >= 0.4.3 pystac >= 1.5 # for GridExtension class - [options.packages.find] where = src diff --git a/src/stactools/naip/stac.py b/src/stactools/naip/stac.py index 8f117bb..0e42ce3 100644 --- a/src/stactools/naip/stac.py +++ b/src/stactools/naip/stac.py @@ -7,6 +7,7 @@ import fsspec import pystac import rasterio as rio +import shapely from lxml import etree from pystac.extensions.eo import EOExtension from pystac.extensions.grid import GridExtension @@ -15,7 +16,6 @@ from pystac.extensions.raster import DataType, RasterBand, RasterExtension from pystac.extensions.scientific import CollectionScientificExtension, Publication from pystac.utils import str_to_datetime -from shapely.geometry import box, mapping, shape from stactools.core.io import read_text from stactools.core.io.xml import XmlElement from stactools.core.projection import reproject_geom @@ -138,7 +138,10 @@ def create_item( original_bbox = list(ds.bounds) transform = list(ds.transform) geom = reproject_geom( - ds.crs, "epsg:4326", mapping(box(*ds.bounds)), precision=6 + ds.crs, + "epsg:4326", + shapely.geometry.mapping(shapely.geometry.box(*ds.bounds)), + precision=6, ) if fgdc_metadata_href is not None: @@ -198,7 +201,9 @@ def create_item( item_id = naip_item_id(state, resource_desc) - bounds = list(shape(geom).bounds) + shapely_shape = shapely.geometry.shape(geom) + bounds = list(shapely_shape.bounds) + centroid = shapely_shape.centroid dt = dt + timedelta(hours=16) # UTC is +4 ET, so is around 9-12 AM in CONUS properties = {"naip:state": state, "naip:year": year} @@ -222,6 +227,7 @@ def create_item( projection.shape = image_shape projection.bbox = original_bbox projection.transform = transform + projection.centroid = {"lat": round(centroid.y, 5), "lon": round(centroid.x, 5)} # Grid Extension grid = GridExtension.ext(item, add_if_missing=True) diff --git a/tests/test_stac.py b/tests/test_stac.py index 5bdda10..84023f7 100644 --- a/tests/test_stac.py +++ b/tests/test_stac.py @@ -1,6 +1,8 @@ import unittest from datetime import datetime +import pytest +from pystac.extensions.projection import ProjectionExtension from pystac.extensions.raster import DataType, RasterExtension from pystac.extensions.scientific import CollectionScientificExtension @@ -38,6 +40,10 @@ def test_create_item_txt(self): self.assertEqual(raster_band.data_type, DataType.UINT8) self.assertEqual(raster_band.unit, "none") + projection = ProjectionExtension.ext(item) + projection.centroid["lat"] == pytest.approx(30.96876) + projection.centroid["lon"] == pytest.approx(-85.90624) + # test stac on year = 2020 def test_create_item_xml(self): item = create_item( @@ -101,7 +107,6 @@ def test_create_item_xml_ext(self): "data-files/m_3211605_ne_11_060_20200415_20200730.xml", "data-files/m_3211605_ne_11_060_20200415_20200730_missing_resource_desc.xml", ]: - item = create_item( "ca", "2020",