Skip to content
Merged

0.9 #48

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
166 commits
Select commit Hold shift + click to select a range
0e3422f
Update for AMPAPI v 0.33.0 - pagination and removal of well from wate…
jacob-a-brown Mar 18, 2025
5e7eab9
Change summary table column name from "location" to "name"
jacob-a-brown Mar 24, 2025
6d77546
Update changelog
jacob-a-brown Mar 27, 2025
29a07fa
started sites only
jirhiker Mar 27, 2025
5f6406c
Use terminal function for most recent record to enable eariest record…
jacob-a-brown Mar 27, 2025
c2169db
Forgot to save a file before previous commit
jacob-a-brown Mar 27, 2025
3510008
sites only
jirhiker Mar 31, 2025
e5ec261
sites only cli
jirhiker Mar 31, 2025
5feace8
sites only cli
jirhiker Mar 31, 2025
b779846
sites only cli
jirhiker Mar 31, 2025
f9b6a87
sites only cli
jirhiker Mar 31, 2025
21c505e
Add earliest records to summary table | rename most_recent latest
jacob-a-brown Mar 31, 2025
f86885c
bump version to 0.8.0
jacob-a-brown Mar 31, 2025
05cae07
Remove old log/warn
jacob-a-brown Mar 31, 2025
c7b1e3d
sites only cli
jirhiker Mar 31, 2025
a9d671f
sites only cli
jirhiker Mar 31, 2025
49e4f68
sites only cli
jirhiker Mar 31, 2025
60eadaf
sites only cli
jirhiker Mar 31, 2025
5ddf814
sites only cli
jirhiker Mar 31, 2025
9ad78f8
sites only cli
jirhiker Mar 31, 2025
e175447
sites only cli
jirhiker Mar 31, 2025
deae8d3
sites only cli
jirhiker Mar 31, 2025
12e6d07
sites only cli
jirhiker Mar 31, 2025
c29e12b
change logging.py to logger.py
jacob-a-brown Mar 31, 2025
79b6512
Remove sites outside of NM
jacob-a-brown Mar 31, 2025
f6e6f75
Add nmbgmr well data back after testing
jacob-a-brown Mar 31, 2025
1bb59b5
Update changelog
jacob-a-brown Mar 31, 2025
358aebb
added wqp to config_agency when parameter = 'waterlevels'
jirhiker Mar 31, 2025
664519b
Merge pull request #38 from DataIntegrationGroup/jir-sites-only
jacob-a-brown Mar 31, 2025
e40c9b5
Merge branch 'dev/jab' into v-0-8-0
jacob-a-brown Apr 1, 2025
3b64348
Sort sources alphabetically
jacob-a-brown Apr 1, 2025
cf5a3bb
Report sources for a given parameter
jacob-a-brown Apr 1, 2025
d68e273
Remove sites further than 25km from NM border
jacob-a-brown Apr 1, 2025
23976e7
Removed NMED DWB from waterlevels sources
jacob-a-brown Apr 1, 2025
a04dea3
fixed all_site_sources
jirhiker Apr 1, 2025
11e6a77
fixed all_site_sources
jirhiker Apr 1, 2025
2cbf406
added pods
jirhiker Apr 1, 2025
d9bdd29
added pods
jirhiker Apr 1, 2025
c237a60
added pods
jirhiker Apr 1, 2025
27491c2
added pods
jirhiker Apr 1, 2025
ef08db7
added pods
jirhiker Apr 1, 2025
104ae3c
added pods
jirhiker Apr 1, 2025
88fb0b3
added pods
jirhiker Apr 1, 2025
b0a62db
Merge pull request #39 from DataIntegrationGroup/jir-sites-only
jacob-a-brown Apr 1, 2025
723b3f9
Formatting changes
jacob-a-brown Apr 1, 2025
f8d3b31
Merge branch 'pre-production' into dev/jab
jacob-a-brown Apr 1, 2025
0f12535
Formatting changes
jacob-a-brown Apr 1, 2025
2cc2c77
Merge pull request #40 from DataIntegrationGroup/dev/jab
jirhiker Apr 1, 2025
5a478d5
Further document NMOSE POD & Update README/CHANGELOG
jacob-a-brown Apr 1, 2025
b9df8a8
Merge pull request #41 from DataIntegrationGroup/dev/jab
jirhiker Apr 1, 2025
6436be4
Fix logger for persister and unifier
jacob-a-brown Apr 2, 2025
3e71a59
Remove USGS records where value is "-999999"
jacob-a-brown Apr 2, 2025
5a66814
Update change log
jacob-a-brown Apr 2, 2025
40f3b9b
Work on updating and maintaining tests
jacob-a-brown Apr 2, 2025
2ad8ecf
Work on fixing chunk sizes
jacob-a-brown Apr 2, 2025
86d63fa
Formatting changes
jacob-a-brown Apr 2, 2025
11c8a1a
Remove duplicative variable for clarity
jacob-a-brown Apr 3, 2025
4f57d46
Intermediate step for this debug
jacob-a-brown Apr 3, 2025
2e19085
Ensure that no more sites than site_limit are returned
jacob-a-brown Apr 3, 2025
1580343
Make tests more efficient and clearer
jacob-a-brown Apr 3, 2025
d4c0155
site_limit exceedance calculation simplification
jacob-a-brown Apr 3, 2025
656596b
Formatting changes
jacob-a-brown Apr 3, 2025
cf350b4
Clearer site limit communication
jacob-a-brown Apr 4, 2025
7b12e8e
Archive old/outdated tests but keep for records
jacob-a-brown Apr 4, 2025
8045586
Archive - but keep - old/outdated tests for reference
jacob-a-brown Apr 4, 2025
4f894a0
Setup BaseTestClass for reusability for all sources and tests
jacob-a-brown Apr 4, 2025
49b5e9c
test NMBGMR
jacob-a-brown Apr 4, 2025
a94c102
Fix NMED DWB health check
jacob-a-brown Apr 4, 2025
0451649
Fix my fix
jacob-a-brown Apr 4, 2025
1781261
Initial setup for source tests
jacob-a-brown Apr 4, 2025
302ecba
Merge branch 'dev/jab' of https://github.com/DataIntegrationGroup/Dat…
jacob-a-brown Apr 4, 2025
ef9de1a
Fix site_limit trimming
jacob-a-brown Apr 4, 2025
4ad367e
Trim for site_limit at end of for loop for when site_limit < chunk_size
jacob-a-brown Apr 4, 2025
29b5863
Formatting changes
jacob-a-brown Apr 4, 2025
1c9f864
Work on mypy linting from CICD
jacob-a-brown Apr 4, 2025
2f4432c
Work on mypy changes
jacob-a-brown Apr 4, 2025
2155fbd
type hint BaseTestClass class attributes
jacob-a-brown Apr 7, 2025
f90a1c4
mypy typing
jacob-a-brown Apr 7, 2025
91af8ca
Formatting changes
jacob-a-brown Apr 7, 2025
bcfdaf7
added additional fields to pods site export
jirhiker Apr 9, 2025
53e29a1
Work on mypy type checking
jacob-a-brown Apr 9, 2025
d8546f1
Merge branch 'dev/jab' of https://github.com/DataIntegrationGroup/Dat…
jacob-a-brown Apr 9, 2025
82eaf53
Work on mypy type checking
jacob-a-brown Apr 9, 2025
761e4ed
Formatting changes
jacob-a-brown Apr 9, 2025
d90479b
mypy.ini configuration file
jacob-a-brown Apr 10, 2025
ccc5cad
Comment out debugging print statements
jacob-a-brown Apr 10, 2025
6492874
remove debugging print statements
jacob-a-brown Apr 10, 2025
f359dc2
mypy type checking
jacob-a-brown Apr 10, 2025
1ff9d6e
mypy type hinting
jacob-a-brown Apr 10, 2025
dad5e50
Finished mypy type checking for tests in GitHub Actions
jacob-a-brown Apr 11, 2025
fbd9b75
mypy fix
jacob-a-brown Apr 11, 2025
b6b368b
rename BaseTestClass to BaseSourceTestClass for clarity
jacob-a-brown Apr 11, 2025
76f77dc
Update pytest skip messages for clarity
jacob-a-brown Apr 11, 2025
d4cd969
reararnge testing folder
jacob-a-brown Apr 11, 2025
6cef8c4
Work on CLI tests
jacob-a-brown Apr 11, 2025
4adafb1
Comment out test dev in progress
jacob-a-brown Apr 11, 2025
d2b6d6c
Formatting changes
jacob-a-brown Apr 11, 2025
b4f4f2d
fix import error
jacob-a-brown Apr 14, 2025
cae4227
put cleanup function in base dir for reuse
jacob-a-brown Apr 14, 2025
1b42e2d
rename nmbgmr to nmbgmr_amp for clarity/consistency
jacob-a-brown Apr 14, 2025
685f242
CLI tests for all sources and ways to set config
jacob-a-brown Apr 14, 2025
22c3be0
keep bbox str to be consistent with other geographic filters
jacob-a-brown Apr 14, 2025
c4e0d29
add wkt spatial option
jacob-a-brown Apr 14, 2025
a1bc4d0
code cleanup
jacob-a-brown Apr 14, 2025
08525c2
mypy fix
jacob-a-brown Apr 14, 2025
ea23c47
Formatting changes
jacob-a-brown Apr 14, 2025
3620df4
bump version to 0.8.2
jacob-a-brown Apr 14, 2025
0cf98b4
PR 43 review changes
jacob-a-brown Apr 14, 2025
647054e
Merge pull request #43 from DataIntegrationGroup/dev/jab
jirhiker Apr 15, 2025
6cc5a15
Implement GeoJSON for sites & summary
jacob-a-brown Apr 15, 2025
60ef303
geojson output for sites and summary
jacob-a-brown Apr 16, 2025
0f1d727
Formatting changes
jacob-a-brown Apr 16, 2025
34eeddc
Comment out cache because of errors
jacob-a-brown Apr 16, 2025
944fdcc
Merge branch 'dev/jab' of https://github.com/DataIntegrationGroup/Dat…
jacob-a-brown Apr 16, 2025
a047ba1
add well depth units to sites table output
jacob-a-brown Apr 16, 2025
0edebcd
mypy fixes
jacob-a-brown Apr 16, 2025
dd47369
Formatting changes
jacob-a-brown Apr 16, 2025
a4ace42
Merge branch 'main' into dev/jab
jacob-a-brown Apr 16, 2025
1a0511d
work on caching in workflow
jacob-a-brown Apr 16, 2025
d498f65
add geoserver persister
jirhiker Apr 16, 2025
dec648e
refactored geoserver persister
jirhiker Apr 16, 2025
6d9ea6f
Bulk well retrieval
jacob-a-brown Apr 16, 2025
1bf8f3c
added orm
jirhiker Apr 16, 2025
fe5600b
added summary stats
jirhiker Apr 21, 2025
1778dee
fixed most_recent_time
jirhiker Apr 21, 2025
d62447d
changed most_recent to latest, added earliest
jirhiker Apr 21, 2025
b30251b
Merge branch 'pre-production' into jir-auto-worker
jirhiker Apr 21, 2025
75250a0
Merge pull request #44 from DataIntegrationGroup/jir-auto-worker
jirhiker Apr 21, 2025
3c8a751
fixed backend.logging->logger refactor
jirhiker Apr 21, 2025
f3552a4
added convex hull to geoserver
jirhiker Apr 21, 2025
7c20ce8
Merge branch 'pre-production' into dev/jab
jacob-a-brown Apr 23, 2025
d25716e
fixes and updates after merging pre-production
jacob-a-brown Apr 23, 2025
8ce5bb9
Formatting changes
jacob-a-brown Apr 23, 2025
cf2c0b3
integration and unification of dev branches
jacob-a-brown Apr 25, 2025
7fe0fa0
remove dirs made by tests
jacob-a-brown Apr 25, 2025
2c09d46
Formatting changes
jacob-a-brown Apr 25, 2025
3ba04ee
rearranged requirements to be alphabetical
jacob-a-brown Apr 25, 2025
0aee4e7
updated CHANGELOG
jacob-a-brown Apr 25, 2025
c73c7e1
Merge branch 'dev/jab' of https://github.com/DataIntegrationGroup/Dat…
jacob-a-brown Apr 25, 2025
8cb66d2
Merge branch 'ampapi-v-0-34-0' into dev/jab
jacob-a-brown Apr 25, 2025
acf680a
NMBGMR water level pagination
jacob-a-brown Apr 25, 2025
ad8b0f1
Formatting changes
jacob-a-brown Apr 25, 2025
de46920
mypy fixes
jacob-a-brown Apr 25, 2025
0c9a228
Merge pull request #45 from DataIntegrationGroup/jir-convex-hulls
jacob-a-brown Apr 25, 2025
a8ef53a
Merge branch 'pre-production' into dev/jab
jacob-a-brown Apr 25, 2025
d7457a7
Merge branch 'dev/jab' of https://github.com/DataIntegrationGroup/Dat…
jacob-a-brown Apr 25, 2025
ec4689e
populate nmbgmr well fields
jacob-a-brown Apr 25, 2025
8322949
Formatting changes
jacob-a-brown Apr 25, 2025
f0c7973
mypy fix
jacob-a-brown Apr 25, 2025
e05ef53
variable name clarity
jacob-a-brown Apr 25, 2025
dab407b
Formatting changes
jacob-a-brown Apr 25, 2025
8bcd789
Merge branch 'dev/jab' of https://github.com/DataIntegrationGroup/Dat…
jacob-a-brown Apr 25, 2025
074f62e
Formatting changes
jacob-a-brown Apr 25, 2025
93a3878
skip well data retrieval for NMBGMR until it can be retrieved in batches
jacob-a-brown Apr 25, 2025
1ca1de4
Merge branch 'dev/jab' of https://github.com/DataIntegrationGroup/Dat…
jacob-a-brown Apr 25, 2025
373cc9d
Formatting changes
jacob-a-brown Apr 25, 2025
87e2225
mypy fix
jacob-a-brown Apr 25, 2025
a5d0b59
default 'yes' to False to enable prompt
jacob-a-brown Apr 28, 2025
a23d1d8
add agency to nwis site numbers
jacob-a-brown Apr 28, 2025
89042a9
ose pods are false agencies for all parameters
jacob-a-brown Apr 28, 2025
ada99cb
bump to 0.9.1
jacob-a-brown Apr 28, 2025
08a0aeb
update documentation
jacob-a-brown Apr 29, 2025
9c533d3
bump to 0.9.2
jacob-a-brown Apr 29, 2025
330f1d4
use requirements.txt for setup.py
jacob-a-brown Apr 29, 2025
382c68c
Merge pull request #46 from DataIntegrationGroup/dev/jab
jirhiker Apr 29, 2025
25a12a9
Merge pull request #47 from DataIntegrationGroup/dev/jab
jacob-a-brown Apr 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "pip"
Expand Down
28 changes: 27 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,41 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased: 0.8.0
## 0.9.2

### Added
- `--sites-only` flag to only retrieve site data
- `--output-format` flag to write out sites/summary tables as csv or geojson.
- options are `csv` or `geojson`
- timeseries data is always written to a csv
- NM OSE POD data for sites.
- can be removed from output with `--no-nmose-pod`
- `--output-dir` to change the output directory to a location other than `.` (the current working directory)

### Changed
- `output` to `output-type` for CLI

### Fixed
- a bug with `--site-limit`. it now exports the number of sets requested by the user

## 0.8.0

### Added
- water level for WQP
- `earliest_date`, `earliest_time`, `earliest_value`, and `earliest_units` to the summary table
- `die wells` to get all wells for which the DIE reports observations
- `die source {parameter}` to list sources that report a particular parameter
- NM OSE PODs, though its information is only currently available for the invocation of `die wells`

### Changed
- NM OSE Roswell data is now pulled from ST2 and not CKAN
- renamed the column `location` to `name` in the summary table to match the format of the `sites` table when timeseries data are exported
- renamed the columns `most_recent_date`, `most_recent_time`, `most_recent_value`, and `most_recent_units` to `latest_date`, `latest_time`, `latest_value`, and `latest_units` respectively for succinctness and juxtaposition with the newly added `earliest` columns.
- This naming schema also enables the development of datetime filters as the descriptor will apply to the latest datetime within the provided time frame filter, whereas most recent indicates np filters.
- removed sites that are not in New Mexico

### Fixed
- removed records from USGS where the value is "-999999"


## 0.7.0
Expand Down
43 changes: 28 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Data comes from the following sources. We are continuously adding new sources as
- Available data: `water levels`, `water quality`
- [New Mexico Environment Department Drinking Water Bureau (NMED DWB)](https://nmenv.newmexicowaterdata.org/FROST-Server/v1.1/)
- Available data: `water quality`
- [New Mexico Office of the State Engineer Points of Diversions (NMOSEPODs)](https://services2.arcgis.com/qXZbWTdPDbTjl7Dy/ArcGIS/rest/services/OSE_PODs/FeatureServer/0)
- Available data: `None`
- [New Mexico Office of the State Engineer ISC Seven Rivers (NMOSE ISC Seven Rivers)](https://nmisc-wf.gladata.com/api/getMonitoringPoints.ashx)
- Available data: `water levels`, `water quality`
- [New Mexico Office of the State Engineer Roswell District Office (NMOSE Roswell)](https://catalog.newmexicowaterdata.org/dataset/pecos_region_manual_groundwater_levels)
Expand Down Expand Up @@ -63,27 +65,28 @@ where `{parameter}` is the name of the parameter whose data is to be retrieved,
| **nmbgmr-amp** | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X |
| **nmed-dwb** | - | X | X | X | - | X | X | X | X | X | X | X | X | X | X | X |
| **nmose-isc-seven-rivers** | X | - | X | X | - | X | X | X | X | X | X | X | X | X | X | - |
| **nmose-pod** | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| **nmose-roswell** | X | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| **nwis** | X | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| **pvacd** | X | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| **wqp** | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X | X |

### Output
The `--output` option is required and used to set the output type:
### Output Type
The `--output-type` option is required and used to set the output type:

```
--output summary
--output-type summary
```
- A summary table consisting of location information as well as summary statistics for the parameter of interest for every location that has observations.

```
--output timeseries_unified
--output-type timeseries_unified
```
- A single table consisting of time series data for all locations for the parameter of interest.
- A single table of site data that contains information such as latitude, longitude, and elevation

```
--output timeseries_separated
--output-type timeseries_separated
```
- Separate time series tables for all locations for the parameter of interest.
- A single table of site data that contains information such as latitude, longitude, and elevation
Expand All @@ -98,7 +101,7 @@ A log of the inputs and processes, called `die.log`, is also saved to the output
| :----------- | :---------- | :-------- | :------------- |
| source | the organization/source for the site | string | Y |
| id | the id of the site. The id is used as the key to join the site and timeseries tables | string | Y |
| location | the colloquial name for the site | string | Y |
| name | the colloquial name for the site | string | Y |
| usgs_site_id | USGS site id | string | N |
| alternate_site_id | alternate site id | string | N |
| latitude | latitude in decimal degrees | float | Y |
Expand All @@ -114,10 +117,14 @@ A log of the inputs and processes, called `die.log`, is also saved to the output
| min | the minimum observation | float | Y |
| max | the maximum observation | float | Y |
| mean | the mean value of the observations | float | Y |
| most_recent_date| date of most recent record in YYYY-MM-DD | string | Y |
| most_recent_time | time of most recent record in HH:MM:SS or HH:MM:SS.mmm | string | N |
| most_recent_value | value of the most recent record | float | Y |
| most_recent_units | units of the most recent record | string | Y |
| earliest_date| date of the earliest record in YYYY-MM-DD | string | Y |
| earliest_time | time of the earliest record in HH:MM:SS or HH:MM:SS.mmm | string | N |
| earliest_value | value of the earliest recent record | float | Y |
| earliest_units | units of the earliest record | string | Y |
| latest_date| date of the latest record in YYYY-MM-DD | string | Y |
| latest_time | time of the latest record in HH:MM:SS or HH:MM:SS.mmm | string | N |
| latest_value | value of the latest recent record | float | Y |
| latest_units | units of the latest record | string | Y |

<sup>*CABQ elevation is calculated as [elevation at top of casing] - [stickup height]; if stickup height < 0 the measuring point is assumed to be beneath the ground surface</sup>

Expand All @@ -139,6 +146,7 @@ A log of the inputs and processes, called `die.log`, is also saved to the output
| formation | geologic formation in which the well terminates | string | N |
| aquifer | aquifer from which the well draws water | string | N |
| well_depth | depth of well | float | N |
| well_depth_units | units of well depth. Defaults to ft | string | N |

<sup>**CABQ elevation is calculated as [elevation at top of casing] - [stickup height]; if stickup height < 0 the measuring point is assumed to be beneath the ground surface</sup>

Expand Down Expand Up @@ -167,12 +175,13 @@ The Data Integration Engine enables the user to obtain groundwater level and gro
- `--no-nmbgmr-amp` to exclude New Mexico Bureau of Geology and Mineral Resources (NMBGMR) Aquifer Mapping Program (AMP) data
- `--no-nmed-dwb` to exclude New Mexico Environment Department (NMED) Drinking Water Bureau (DWB) data
- `--no-nmose-isc-seven-rivers` to exclude New Mexico Office of State Engineer (NMOSE) Interstate Stream Commission (ISC) Seven Rivers data
- `--no-nmose-pod` to exclude New Mexico Office of State Engineer (NMOSE) Point of Diversion (POD) data (though none except for well information is currently available)
- `--no-nmose-roswell` to exclude New Mexico Office of State Engineer (NMOSE) Roswell data
- `--no-nwis` to exclude USGS NWIS data
- `--no-pvacd` to exclude Pecos Valley Artesian Convservancy District (PVACD) data
- `--no-wqp` to exclude Water Quality Portal (WQP) data

### Geographic Filters
### Geographic Filters [In Development]

The following flags can be used to geographically filter data:

Expand All @@ -184,7 +193,11 @@ The following flags can be used to geographically filter data:
-- bbox 'x1 y1, x2 y2'
```

### Date Filters
```
-- wkt {wkt polygon or multipolygon}
```

### Date Filters [In Development]

The following flags can be used to filter by dates:

Expand All @@ -206,12 +219,12 @@ die sources {parameter}

to print the sources that report that parameter to the terminal.

### Wells [In Development]
### Sites

Use

```
die wells
die sites
```

to print wells to the terminal.
to export site information only
11 changes: 11 additions & 0 deletions auto_worker_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
flask
gunicorn
httpx
pandas
geopandas
frost_sta_client
google-cloud-storage
pytest
urllib3>=2.2.0,<3.0.0
Geoalchemy2
sqlalchemy
16 changes: 16 additions & 0 deletions backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from enum import Enum
from os import environ


class OutputFormat(str, Enum):
GEOJSON = "geojson"
CSV = "csv"
GEOSERVER = "geoserver"


def get_bool_env_variable(var: str) -> bool:
env_var = environ.get(var, None)
if env_var is None or env_var.strip().lower() not in ["true", "1", "yes"]:
return False
else:
return True
21 changes: 16 additions & 5 deletions backend/bounding_polygons.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
# ===============================================================================
import json
import os
from pprint import pprint

import click
import httpx
from shapely import Polygon, box
from shapely.geometry import shape

from backend.geo_utils import transform_srid, SRID_WGS84, SRID_UTM_ZONE_13N


# polygon retrivial functions
# multiple polygons
Expand Down Expand Up @@ -159,21 +162,28 @@ def get_county_polygon(name, as_wkt=True):
_warning(f"Invalid state. {state}")


def get_state_polygon(state):
def get_state_polygon(state: str, buffer: int | None = None):
statefp = _statelookup(state)
if statefp:
obj = _get_cached_object(
f"{state}.state",
f"{state} state",
f"https://reference.geoconnex.us/collections/states/items/{statefp}?&f=json",
)
geom_gcs = shape(obj["features"][0]["geometry"])

if buffer:
geom_utm = transform_srid(geom_gcs, SRID_WGS84, SRID_UTM_ZONE_13N)
geom_utm = geom_utm.buffer(buffer)
geom_gcs = transform_srid(geom_utm, SRID_UTM_ZONE_13N, SRID_WGS84)

return shape(obj["geometry"])
return geom_gcs


# private helpers ============================
def _make_shape(obj, as_wkt):
poly = shape(obj["geometry"])
poly = poly.simplify(0.1)
if as_wkt:
return poly.wkt
return poly
Expand Down Expand Up @@ -231,8 +241,9 @@ def _get_cached_object(name, msg, url):
return obj


NM_BOUNDARY_BUFFERED = get_state_polygon("NM", 25000)


if __name__ == "__main__":
# w = get_huc_polygon('0101000201')
# print(w)
print(get_state_hucs_boundaries(state="CO", level=4))
print(get_state_polygon("NM"))
# ============= EOF =============================================
Loading