-
-
Notifications
You must be signed in to change notification settings - Fork 265
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
BBOX for Postgres returning unwanted results #1666
Comments
cc @KoalaGeo Upon further inspection (thanks @webb-ben for the test data) I'm able to reproduce. In the PostgreSQL provider, the intersects query differs in CQL mode vs bbox mode. CQL query (via pygeofilter)
bbox query (via SQLAlchemy direct)
The query is slightly different, and more importantly pygeofilter is setting SRID=4326 for the bbox/geometry. Updating the PostgreSQL provider per below gives consistent results with the CQL code path for bbox/geometry: def _get_bbox_filter(self, bbox):
if not bbox:
return True # Let everything through
# Convert bbox to SQLAlchemy clauses
geom_column = getattr(self.table_model, self.geom)
envelope = ST_MakeEnvelope(*bbox, 4326)
bbox_filter = ST_Intersects(geom_column, envelope)
return bbox_filter Resulting SQL:
We could hardcode 4326 for the incoming Perhaps the best way to determine and set the srid of the bbox is to set it to the srid of the geometry column as follows: def _get_bbox_filter(self, bbox):
if not bbox:
return True # Let everything through
# Convert bbox to SQLAlchemy clauses
geom_column = getattr(self.table_model, self.geom)
geom_column_srid = TODO
envelope = ST_MakeEnvelope(*bbox, geom_column_srid)
bbox_filter = ST_Intersects(geom_column, envelope)
return bbox_filter Any ideas on how to derive would be valuable ( |
@volcan01010 & @ximenesuk ideas/suggestions? |
Description
Using the bbox intersection with a postgres backend results in items being returned that do not match the filter
Steps to Reproduce
Steps to reproduce the behavior:
Go to https://reference.geoconnex.us/collections/mainstems/items?bbox=-109.448547,36.611118,-107.668762,37.322120&properties=uri&limit=1000
Notice that https://geoconnex.us/ref/mainstems/29559 is included in the result although it does not intersect the bbox. It seems the bbox of the feature might intersect with the input bbox.
Expected behavior
Only items that intersect with the input bbox are returned as in returned for the CQL request:
https://reference.geoconnex.us/collections/mainstems/items?filter=INTERSECTS(geom,%20POLYGON((-109.448547%2036.611118,%20-109.448547%2037.322120,%20-107.668762%2037.322120,%20-107.668762%2036.611118,%20-109.448547%2036.611118)))&limit=1000
Screenshots/Tracebacks
Environment
Additional context
Related to DOI-USGS/nhdplusTools#386
The text was updated successfully, but these errors were encountered: