Commit 146da4dc authored by Aurelien Campeas's avatar Aurelien Campeas
Browse files

add geography support (closes #3276542)

parent b1d7b85765c4
......@@ -4,6 +4,7 @@ Test for postgis
"""
_GEOM_PARAMETERS = ('srid', 'geom_type','coord_dimension')
_GEOG_PARAMETERS = ('geom_type','coord_dimension')
def _update_postgis_metadata(session, rtype, subject, srid, geom_type, coord_dimension):
""" This fonction update the postgis metadata columns
......
# -*- coding: utf-8 -*-
# copyright 2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# copyright 2012-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr -- mailto:contact@logilab.fr
#
# This program is free software: you can redistribute it and/or modify it under
......@@ -20,3 +20,8 @@ from yams.buildobjs import make_type
Geometry = make_type('Geometry')
# Example of use:
# Geometry(geom_type='POINT', srid=-1, coord_dimension=2)
Geography = make_type('Geography')
# Example of use:
# Geography(geom_type='POINT', coord_dimension=2)
......@@ -15,10 +15,11 @@ from yams import register_base_type
from rql.utils import register_function
from cubes.postgis import _GEOM_PARAMETERS
from cubes.postgis import _GEOM_PARAMETERS, _GEOG_PARAMETERS
# register new base type
register_base_type('Geometry', _GEOM_PARAMETERS)
register_base_type('Geography', _GEOG_PARAMETERS)
# Add the datatype to the helper mapping
pghelper = get_db_helper('postgres')
......@@ -26,6 +27,9 @@ sqlitehelper = get_db_helper('sqlite')
pghelper.TYPE_MAPPING['Geometry'] = 'geometry'
sqlitehelper.TYPE_MAPPING['Geometry'] = 'text'
pghelper.TYPE_MAPPING['Geography'] = 'geography'
sqlitehelper.TYPE_MAPPING['Geography'] = 'text'
# Add a converter for Geometry
def convert_geom(x):
if isinstance(x, (tuple, list)):
......@@ -35,11 +39,16 @@ def convert_geom(x):
# We just give the Geometry
return SQLExpression('ST_GeomFromText(%(geo)s, %(srid)s)', geo=x, srid=-1)
def convert_geog(x):
# takes only a Geometry type, assumes GPS srid
return SQLExpression('ST_GeogFromText(%(geo)s)', geo=x)
# Add the converter function to the known SQL_CONVERTERS
pghelper.TYPE_CONVERTERS['Geometry'] = convert_geom
pghelper.TYPE_CONVERTERS['Geography'] = convert_geog
# actually don't care of sqlite, it's just to make it possible to test
sqlitehelper.TYPE_CONVERTERS['Geometry'] = str
sqlitehelper.TYPE_CONVERTERS['Geography'] = str
......
......@@ -17,7 +17,11 @@
"""cubicweb-postgis views/forms/actions/components for web ui"""
from cubicweb import uilib
from cubicweb.web import formfields
# StringField is probably not the worst default choice
formfields.FIELDS['Geometry'] = formfields.StringField
uilib.PRINTERS['Geometry'] = uilib.print_string
formfields.FIELDS['Geography'] = formfields.StringField
uilib.PRINTERS['Geography'] = uilib.print_string
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