-
Notifications
You must be signed in to change notification settings - Fork 4
BDMS 111: location updates & other #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
ea5a07b
feat: add LU tables to transfers for mapping to lexicon
jacob-a-brown 84654ae
Merge branch 'jab-lexicon-updates' into jab-lexicon-lookup-tables
jacob-a-brown 25627e3
Merge branch 'pre-production' into jab-lexicon-lookup-tables
jacob-a-brown cfd88ff
feat: make LU to lexicon mapper for data transfer
jacob-a-brown 34705aa
Merge branch 'pre-production' into jab-lexicon-lookup-tables
jacob-a-brown dd970d3
refactor: move utils to services for use throughout API
jacob-a-brown dc89117
feat: set location state/county/quad from point
jacob-a-brown 6c0e314
feat: set elevation from national map if none in nma
jacob-a-brown afd6261
Merge branch 'staging' into jab-lexicon-lookup-tables
jacob-a-brown 948b17b
feat: map lu tables to lexicon for transfer
jacob-a-brown db3a857
fix: delete LU tables locally - get from cloud
jacob-a-brown 8bedd14
refactor: use variable for WGS84 SRID throughout
jacob-a-brown 3556584
Merge branch 'jab-lexicon-lookup-tables' into jab-location-transfer-u…
jacob-a-brown 9251bb8
WIP: apply LU-lexicon mapper
jacob-a-brown 965f563
feat: prepend mapper key with LU table name for uniqueness
jacob-a-brown 237e52a
Merge branch 'jab-lexicon-lookup-tables' into jab-location-transfer-u…
jacob-a-brown b3cc66f
refactor: remove name from location until future decision is made
jacob-a-brown 97ea48f
feat: skip record if error, not stop process
jacob-a-brown 22394a0
refactor: increase timeout for location geographic requests
jacob-a-brown 8fccdf4
refactor: decrease limit for development
jacob-a-brown 16ab98a
fix: skip and log records with duplicates
jacob-a-brown bf58bb6
refactor: use pointid not index in log statement
jacob-a-brown 4040a54
WIP: work on location and dt transfers
jacob-a-brown 6fef249
feat: convert times from mst/mdt to utc
jacob-a-brown c885ef5
note: remove duplicative note
jacob-a-brown ff98139
refactor: wait for AMP feedback before transfering coord accuracy values
jacob-a-brown 1b8af65
refactor: made elevation separate from point field
jacob-a-brown dbfef6c
fix: run tests for update branch names
jacob-a-brown 96dbff8
fix: run tests on new branch names
jacob-a-brown File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| from shapely.wkt import loads | ||
| from pydantic import BaseModel | ||
| from sqlalchemy.orm import Session | ||
|
|
||
| from db.location import Location | ||
| from services.util import ( | ||
| get_state_from_point, | ||
| get_county_from_point, | ||
| get_quad_name_from_point, | ||
| ) | ||
|
|
||
|
|
||
| def set_geographic_attributes( | ||
| session: Session, payload: BaseModel, location: Location | ||
| ) -> None: | ||
| """ | ||
| Set geographic attributes for a location based off of the point. This function | ||
| is to be used for both POST and PATCH requests. | ||
| """ | ||
| if payload.point is not None: | ||
| point = loads(payload.point) | ||
| longitude = point.x | ||
| latitude = point.y | ||
| location.state = get_state_from_point(longitude, latitude) | ||
| location.county = get_county_from_point(longitude, latitude) | ||
| location.quad_name = get_quad_name_from_point(longitude, latitude) | ||
| session.commit() |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| from shapely.ops import transform | ||
| import pyproj | ||
| import httpx | ||
|
|
||
| from constants import SRID_WGS84 | ||
|
|
||
| TRANSFORMERS = {} | ||
|
|
||
|
|
||
| def transform_srid(geometry, source_srid, target_srid): | ||
| """ | ||
| geometry must be a shapely geometry object, like Point, Polygon, or MultiPolygon | ||
| """ | ||
| transformer_key = (source_srid, target_srid) | ||
| if transformer_key not in TRANSFORMERS: | ||
| source_crs = pyproj.CRS(f"EPSG:{source_srid}") | ||
| target_crs = pyproj.CRS(f"EPSG:{target_srid}") | ||
| transformer = pyproj.Transformer.from_crs( | ||
| source_crs, target_crs, always_xy=True | ||
| ) | ||
| TRANSFORMERS[transformer_key] = transformer | ||
| else: | ||
| transformer = TRANSFORMERS[transformer_key] | ||
| return transform(transformer.transform, geometry) | ||
|
|
||
|
|
||
| def get_tiger_data( | ||
| lon: float, lat: float, layer: int, outfields: str = "*" | ||
| ) -> dict | None: | ||
| url = f"https://tigerweb.geo.census.gov/arcgis/rest/services/TIGERweb/State_County/MapServer/{layer}/query" | ||
| params = { | ||
| "f": "json", | ||
| "where": "1=1", | ||
| "geometry": f"{lon},{lat}", | ||
| "geometryType": "esriGeometryPoint", | ||
| "inSR": f"{SRID_WGS84}", | ||
| "spatialRel": "esriSpatialRelIntersects", | ||
| "outFields": outfields, | ||
| "returnGeometry": "false", | ||
| } | ||
| resp = httpx.get(url, params=params, timeout=30) | ||
| data = resp.json() | ||
| if not data.get("features"): | ||
| return None | ||
|
|
||
| return data["features"][0]["attributes"] | ||
|
|
||
|
|
||
| def get_state_from_point(lon: float, lat: float) -> str: | ||
| attrs = get_tiger_data(lon, lat, layer=0, outfields="BASENAME") | ||
| return attrs["BASENAME"] | ||
|
|
||
|
|
||
| def get_county_from_point(lon: float, lat: float) -> str: | ||
| """ | ||
| Look up county for a given longitude/latitude | ||
| using the US Census TIGERWeb REST API. | ||
| """ | ||
|
|
||
| attrs = get_tiger_data(lon, lat, layer=1, outfields="BASENAME") | ||
| return attrs["BASENAME"] | ||
|
|
||
|
|
||
| def get_quad_name_from_point(lon: float, lat: float) -> str: | ||
| url = "https://carto.nationalmap.gov/arcgis/rest/services/map_indices/MapServer/10/query" | ||
| params = { | ||
| "f": "json", | ||
| "geometry": f"{lon},{lat}", | ||
| "geometryType": "esriGeometryPoint", | ||
| "inSR": f"{SRID_WGS84}", | ||
| "spatialRel": "esriSpatialRelIntersects", | ||
| "outFields": "CELL_NAME,CELL_MAPCODE", | ||
| "returnGeometry": "false", | ||
| } | ||
|
|
||
| resp = httpx.get(url, params=params, timeout=30) | ||
| data = resp.json() | ||
|
|
||
| if data["features"]: | ||
| attrs = data["features"][0]["attributes"] | ||
| return attrs["CELL_NAME"] | ||
| else: | ||
| print(f"No quad name found for POINT ({lon} {lat})") | ||
| return None | ||
|
|
||
|
|
||
| def get_epqs_elevation_from_point(lon: float, lat: float) -> float: | ||
| url = "https://epqs.nationalmap.gov/v1/json" | ||
| params = { | ||
| "x": lon, | ||
| "y": lat, | ||
| "units": "Meters", | ||
| "wkid": f"{SRID_WGS84}", | ||
| "includeDate": False, | ||
| } | ||
|
|
||
| resp = httpx.get(url, params=params) | ||
| data = resp.json() | ||
|
|
||
| return data["value"] | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| x = -106.904107 | ||
| y = 34.068198 | ||
|
|
||
| print(get_state_from_point(x, y)) | ||
| print(get_county_from_point(x, y)) | ||
| print(get_quad_name_from_point(x, y)) | ||
| print(get_epqs_elevation_from_point(x, y)) |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to region_of_interest (?)