Skip to content

Instantly share code, notes, and snippets.

@hcarvalhoalves
Created May 6, 2014 23:24
Show Gist options
  • Select an option

  • Save hcarvalhoalves/2d4529d1502db87131a6 to your computer and use it in GitHub Desktop.

Select an option

Save hcarvalhoalves/2d4529d1502db87131a6 to your computer and use it in GitHub Desktop.
geoalchemy Geometry wrapper for simple "lat,lon" fields
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