Commit 79ce6497 authored by Alexandre Richardson's avatar Alexandre Richardson
Browse files

Add pg_geography_sqltype

Mapping from cubicweb 'Geography'-typed attribute to postgresql column
type, to take the srid and geometry type into account.
parent 7f2ea53ddc8d
...@@ -35,11 +35,16 @@ def pg_geometry_sqltype(rdef): ...@@ -35,11 +35,16 @@ def pg_geometry_sqltype(rdef):
assert rdef.srid assert rdef.srid
return 'geometry(%s, %s)' % (target_geom_type, rdef.srid) return 'geometry(%s, %s)' % (target_geom_type, rdef.srid)
def pg_geography_sqltype(rdef):
"""Return a PostgreSQL column type corresponding to rdef's geom_type and srid
srid = rdef.srid or 4326
return 'geography(%s, %s)' % (rdef.geom_type, srid)
# Add the datatype to the helper mapping # Add the datatype to the helper mapping
pghelper = get_db_helper('postgres') pghelper = get_db_helper('postgres')
pghelper.TYPE_MAPPING['Geometry'] = pg_geometry_sqltype pghelper.TYPE_MAPPING['Geometry'] = pg_geometry_sqltype
pghelper.TYPE_MAPPING['Geography'] = 'geography' # XXX implement a pg_geography_sqlite pghelper.TYPE_MAPPING['Geography'] = pg_geography_sqltype
# Add a converter for Geometry # Add a converter for Geometry
def convert_geom(x): def convert_geom(x):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment