Using SQLAlchemy 0.8, Flask-SQLAlchemy and Geoalchemy 2:
from app import db from geoalchemy2.types import Geometry class Point(db.Model): """represents an x/y coordinate location.""" __tablename__ = 'point' id = db.Column(db.Integer, primary_key=True) geom = db.Column(Geometry(geometry_type='POINT', srid=4326))
Request example:
from geoalchemy2.elements import WKTElement from app import models def get_nearest(lat, lon):
One way to convert the result to x and y coordinates (convert to GeoJSON and extract coordinates):
import geoalchemy2.functions as func import json from app import db def point_geom_to_xy(pt):
bananafish
source share