Created
May 6, 2014 23:24
-
-
Save hcarvalhoalves/2d4529d1502db87131a6 to your computer and use it in GitHub Desktop.
geoalchemy Geometry wrapper for simple "lat,lon" fields
This file contains 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 sqlalchemy import types | |
from sqlalchemy.sql.expression import func, text | |
from geoalchemy2 import functions as geofunc | |
from geoalchemy2.elements import WKTElement | |
class Coordinate(types.TypeDecorator): | |
impl = Geometry | |
def process_bind_param(self, value, dialect): | |
return 'POINT({} {})'.format(*value.split(',', 1)) | |
def bind_expression(self, bindvalue): | |
return func.ST_GeomFromText(bindvalue, self.srid, type_=self) | |
def column_expression(self, bindvalue): | |
return geofunc.ST_Y(bindvalue, type_=types.String) + text("','") + geofunc.ST_X(bindvalue, type_=types.String) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment