feat: reverse geolocation per polygon strategy#1318
Merged
Conversation
jcpitre
reviewed
Aug 19, 2025
davidgamez
commented
Aug 19, 2025
| import logging | ||
| import threading | ||
|
|
||
| import google.cloud.logging |
Member
Author
There was a problem hiding this comment.
Moving this import inside the function, as the unit tests can fail when running locally, and the console is not authenticated with Google services
cka-y
approved these changes
Aug 27, 2025
|
|
||
| def get_geopolygons_covers(stop_point: WKTElement, db_session: Session): | ||
| """ | ||
| Get all geopolygons that cover a given point using BigQuery-compatible semantics. |
Contributor
There was a problem hiding this comment.
[question] what does this have to do w big query?
Member
Author
There was a problem hiding this comment.
The fact that we have to cast(Geopolygon.geometry, Geography(srid=4326)) due to the original values from BigQuery tables being Geography instead of geometry
| return abs(area) | ||
|
|
||
|
|
||
| def resolve_same_level_conflicts(items: List[Geopolygon]) -> Geopolygon: |
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.
Summary:
Closes #1301, #1289, #965
Significant changes in this PR:
per_polygonstrategyMinor fixes
Out of scope:
Expected behavior:
Performance results
The performance results were collected for a few feeds without using the geometry cache.
Testing tips:
Local testing
From our AI friend:
This pull request introduces new geospatial utilities and refactors location handling logic to improve reverse geolocation and location grouping features. It adds helper functions for working with geopolygons, enhances enum conversion error reporting, and expands test coverage for location utilities. Several dependencies and configuration files are updated to support these changes.
Geospatial utilities and location logic enhancements
locations.pyfor converting geometry types (to_shapely), selecting geopolygons by admin level (select_highest_level_polygon,select_lowest_level_polygon), extracting country codes from polygons, and querying geopolygons that cover a point with BigQuery-compatible semantics.location_group_utils.py, including functions for extracting location aggregates, creating/updating stop groups, and managing location group entities. These functions leverage the new geopolygon helpers for more robust location assignment and grouping. [1] [2]Test coverage improvements
test_locations.pywith comprehensive tests for the new geospatial helper functions, including edge cases for admin level selection and country code extraction from geopolygons.Dependency and configuration updates
shapelytorequirements.txtto support geometry conversions and spatial operations..coveragercto omit coverage for files in*/shared/common/*, reflecting the new shared helpers.Error handling and logging improvements
transform.py.google.cloud.loggingonly when needed, improving startup reliability.Minor fixes
gcp_utils.py(tasks_executorinstead oftasks-executor).transform.py.logger.py.locations.py.Please make sure these boxes are checked before submitting your pull request - thanks!
./scripts/api-tests.shto make sure you didn't break anything