2011-09-29 16:40:49 +02:00
|
|
|
from ckan.lib.base import config
|
2011-04-13 13:05:59 +02:00
|
|
|
from ckan.model import Session
|
2011-09-29 16:40:49 +02:00
|
|
|
from ckan.model.meta import *
|
|
|
|
from ckan.model.domain_object import DomainObject
|
|
|
|
from geoalchemy import *
|
|
|
|
from geoalchemy.postgis import PGComparator
|
2011-04-13 13:05:59 +02:00
|
|
|
|
2011-09-29 16:40:49 +02:00
|
|
|
db_srid = int(config.get('ckan.spatial.srid', '4326'))
|
|
|
|
package_extent_table = Table('package_extent', metadata,
|
|
|
|
Column('package_id', types.UnicodeText, primary_key=True),
|
|
|
|
GeometryExtensionColumn('the_geom', Geometry(2,srid=db_srid)))
|
2011-04-13 13:05:59 +02:00
|
|
|
|
2011-09-29 16:40:49 +02:00
|
|
|
class PackageExtent(DomainObject):
|
|
|
|
def __init__(self, package_id=None, the_geom=None):
|
|
|
|
self.package_id = package_id
|
|
|
|
self.the_geom = the_geom
|
|
|
|
|
|
|
|
mapper(PackageExtent, package_extent_table, properties={
|
|
|
|
'the_geom': GeometryColumn(package_extent_table.c.the_geom,
|
|
|
|
comparator=PGComparator)})
|
|
|
|
|
|
|
|
# enable the DDL extension
|
|
|
|
GeometryDDL(package_extent_table)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_SRID = 4326
|
|
|
|
|
|
|
|
def setup(srid=None):
|
2011-04-13 13:05:59 +02:00
|
|
|
|
|
|
|
if not srid:
|
|
|
|
srid = DEFAULT_SRID
|
2011-09-29 16:40:49 +02:00
|
|
|
|
2011-04-13 13:05:59 +02:00
|
|
|
srid = str(srid)
|
|
|
|
|
|
|
|
connection = Session.connection()
|
2011-09-29 16:40:49 +02:00
|
|
|
connection.execute('CREATE TABLE package_extent(package_id text PRIMARY KEY)')
|
2011-04-13 13:05:59 +02:00
|
|
|
|
2011-09-29 16:40:49 +02:00
|
|
|
connection.execute('SELECT AddGeometryColumn(\'package_extent\',\'the_geom\', %s, \'GEOMETRY\', 2)',srid)
|
2011-04-13 13:05:59 +02:00
|
|
|
|
|
|
|
Session.commit()
|