fix(waterdata): attach EPSG:4326 CRS to OGC GeoDataFrames#343
Merged
Conversation
The waterdata getters build their GeoDataFrame via gpd.GeoDataFrame.from_features(...) without a crs= argument, so the returned object has .crs is None even though the coordinates are published in EPSG:4326 (WGS84) and the get_monitoring_locations docstring says so. That makes CRS-aware ops like to_crs and spatial joins fail on an otherwise valid result, and it's inconsistent with the nldi (EPSG:4326) and nwis (EPSG:4269) modules, which already tag their frames. Pass the documented CRS at both build sites (ogc/shaping.py and waterdata/stats.py) via a shared _CRS constant. Fixes DOI-USGS#342 Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
Collaborator
|
thanks @arpitjain099, @matinguku @mikemahoney218-usgs, before I merge this, could you confirm whether or not EPSG:4326 is unversal. If not, we might assign the crs with a warning. |
|
Universal unless a user provides the |
Replace the hand-built mock.MagicMock response in test_get_resp_data_attaches_wgs84_crs with the file's existing _resp_ok() helper, which produces the same 200-OK feature payload. Drops duplicated mock scaffolding and matches the convention used by the other tests in this module. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes #342. The waterdata getters build their GeoDataFrame with gpd.GeoDataFrame.from_features(...) but never pass a crs, so the result comes back with .crs of None even though the coordinates are published in EPSG:4326 and the get_monitoring_locations docstring says as much. That leaves the frame CRS-naive, so to_crs and spatial joins raise on an otherwise valid result, and it's out of step with the nldi (EPSG:4326) and nwis (EPSG:4269) modules that already tag theirs.
I added a shared _CRS constant in ogc/shaping.py and pass it at both build sites (shaping and waterdata/stats), mirroring how nldi/nwis do it. I confirmed the fix with new offline regression tests that fail before the change (crs is None) and pass after (crs is EPSG:4326) for both the sites path and the stats path; the rest of the waterdata suite and ruff stay green. Thanks for taking a look.