Skip to content

Instantly share code, notes, and snippets.

@mrvaldes
Created May 19, 2017 17:35
Show Gist options
  • Save mrvaldes/6cb0f4d66c7c29100bf41533726a1e5d to your computer and use it in GitHub Desktop.
Save mrvaldes/6cb0f4d66c7c29100bf41533726a1e5d to your computer and use it in GitHub Desktop.
Example of GeoAlchemy2 to filter query by spatial type (ST) functions
from geoalchemy2 import Geography, Geometry
from sqlalchemy import cast
...
class Node(db.Model):
....
def get_area(self, type_key):
try:
return Area.query.filter(Area.type_key == type_key).filter(
cast(Area.polygon, Geometry).ST_Contains(
cast(self.point, Geometry))).first() or None
except Exception as ex:
pass
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment