2011-04-11 19:04:28 +02:00
|
|
|
import sys
|
|
|
|
|
2019-12-11 13:22:28 +01:00
|
|
|
import logging
|
2011-04-11 19:04:28 +02:00
|
|
|
from ckan.lib.cli import CkanCommand
|
2019-12-11 13:22:28 +01:00
|
|
|
|
|
|
|
import ckanext.spatial.util as util
|
|
|
|
|
|
|
|
|
2011-09-29 16:40:49 +02:00
|
|
|
log = logging.getLogger(__name__)
|
2011-04-11 19:04:28 +02:00
|
|
|
|
2011-04-13 13:05:59 +02:00
|
|
|
class Spatial(CkanCommand):
|
|
|
|
'''Performs spatially related operations.
|
2011-04-11 19:04:28 +02:00
|
|
|
|
|
|
|
Usage:
|
2011-04-13 13:05:59 +02:00
|
|
|
spatial initdb [srid]
|
|
|
|
Creates the necessary tables. You must have PostGIS installed
|
|
|
|
and configured in the database.
|
2011-09-29 16:40:49 +02:00
|
|
|
You can provide the SRID of the geometry column. Default is 4326.
|
2011-04-11 19:04:28 +02:00
|
|
|
|
2011-04-13 13:05:59 +02:00
|
|
|
spatial extents
|
2011-10-03 14:39:18 +02:00
|
|
|
Creates or updates the extent geometry column for datasets with
|
2011-09-29 16:40:49 +02:00
|
|
|
an extent defined in the 'spatial' extra.
|
2019-12-11 13:22:28 +01:00
|
|
|
|
2011-04-11 19:04:28 +02:00
|
|
|
The commands should be run from the ckanext-spatial directory and expect
|
|
|
|
a development.ini file to be present. Most of the time you will
|
|
|
|
specify the config explicitly though::
|
|
|
|
|
|
|
|
paster extents update --config=../ckan/development.ini
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
summary = __doc__.split('\n')[0]
|
|
|
|
usage = __doc__
|
2019-12-11 13:22:28 +01:00
|
|
|
max_args = 2
|
2011-04-11 19:04:28 +02:00
|
|
|
min_args = 0
|
|
|
|
|
|
|
|
def command(self):
|
|
|
|
self._load_config()
|
|
|
|
print ''
|
|
|
|
|
|
|
|
if len(self.args) == 0:
|
|
|
|
self.parser.print_usage()
|
|
|
|
sys.exit(1)
|
|
|
|
cmd = self.args[0]
|
2011-04-13 13:05:59 +02:00
|
|
|
if cmd == 'initdb':
|
2019-12-11 13:22:28 +01:00
|
|
|
self.initdb()
|
2011-04-13 13:05:59 +02:00
|
|
|
elif cmd == 'extents':
|
2011-04-11 19:04:28 +02:00
|
|
|
self.update_extents()
|
|
|
|
else:
|
|
|
|
print 'Command %s not recognized' % cmd
|
|
|
|
|
2011-04-13 13:05:59 +02:00
|
|
|
def initdb(self):
|
|
|
|
if len(self.args) >= 2:
|
2019-12-11 13:22:28 +01:00
|
|
|
srid = self.args[1]
|
2011-04-13 13:05:59 +02:00
|
|
|
else:
|
|
|
|
srid = None
|
2019-12-11 13:22:28 +01:00
|
|
|
return util.initdb(srid)
|
2011-04-13 13:05:59 +02:00
|
|
|
|
2011-04-11 19:04:28 +02:00
|
|
|
def update_extents(self):
|
2019-12-11 13:22:28 +01:00
|
|
|
return util.update_extents()
|