Created
May 19, 2017 17:35
-
-
Save mrvaldes/6cb0f4d66c7c29100bf41533726a1e5d to your computer and use it in GitHub Desktop.
Example of GeoAlchemy2 to filter query by spatial type (ST) functions
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
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