Skip to content

Commit

Permalink
34 - Support raster query with MultiPolygons (#39)
Browse files Browse the repository at this point in the history
* Update raster.py - Support multipolygons for raster download.

* Update linux-test.yml - Change to fix breaking issue in mamba.

* Update package version
  • Loading branch information
rosepearson authored Jan 17, 2023
1 parent 1152fc1 commit 048796b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
17 changes: 12 additions & 5 deletions .github/workflows/linux-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
shell: bash -el {0}
strategy:
fail-fast: false
matrix:
Expand All @@ -21,6 +21,7 @@ jobs:
- name: Checkout github repo
uses: actions/checkout@v2


- name: Cache conda
uses: actions/cache@v2
env:
Expand All @@ -29,41 +30,47 @@ jobs:
path: ~/conda_pkgs_dir
key: ${{ runner.os }}-conda-${{ env.cache-name }}-${{ hashFiles('environment.yml') }}


- name: Install package dependencies with setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v2
with:
python-version: ${{ matrix.python-version }}
miniforge-variant: Mambaforge
channels: conda-forge
channel-priority: true
activate-environment: geoapis
environment-file: environment.yml
auto-activate-base: false
channels: conda-forge
channel-priority: strict
use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly!
python-version: ${{ matrix.python-version }}
mamba-version: "*"
- run: |
conda info
conda list
conda config --show-sources
conda config --show
printenv | sort
- name: Install test dependencies
run: |
mamba install flake8 pytest
- name: Create .env file with API keys
env:
ENV_BASE64: ${{ secrets.ENV_BASE64 }}
run: |
echo import .env file contents stored in a GitHub secret and regenerate the expected .env file
echo $ENV_BASE64 | base64 -d > .env
- name: Run lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run tests with pytest
run: |
pytest
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "geoapis"
version = "0.3.1"
version = "0.3.2"
description = "A package for downloading geospatial data from web APIs."
readme = "README.md"
authors = [{ name = "Rose pearson", email = "[email protected]" }]
Expand Down
2 changes: 1 addition & 1 deletion src/geoapis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
@author: pearsonra
"""
__version__ = "0.3.1"
__version__ = "0.3.2"
28 changes: 22 additions & 6 deletions src/geoapis/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,28 @@ def _set_up(self):
self.bounding_polygon.to_crs(self.crs)
# Enforce the bounding_polygon must be a single geometry if it exists
if self.bounding_polygon is not None:
assert (
len(self.bounding_polygon) == 1
), "The bounding polygon must be a single geometry"
assert (
len(numpy.array(self.bounding_polygon.exterior.loc[0].coords)) < 1000
), "The bounding polygon must be lass than 1000 points"
self.bounding_polygon = self.bounding_polygon.explode(index_parts=False)
if not (self.bounding_polygon.type == "Polygon").all():
logging.warning(
"All bounding_polygon parts aren't Polygon's. Ignoring"
f" those that aren't {self.bounding_polygon.geometry}"
)

self.bounding_polygon = self.bounding_polygon[
self.bounding_polygon.type == "Polygon"
]
number_of_coords = sum(
[
len(polygon.coords)
for polygon in self.bounding_polygon.explode(
index_parts=False
).exterior
]
)
assert number_of_coords < 1000, (
"The bounding polygon must be less than 1000 points. Consider using the"
" bbox to simplify the geometry"
)

def run(self, layer: int) -> pathlib.Path:
"""Query for a specified layer and return a geopandas.GeoDataFrame of the vector
Expand Down

0 comments on commit 048796b

Please sign in to comment.