spatial-d4science/ckanext/spatial/commands/spatial.py

61 lines
1.5 KiB
Python
Raw Normal View History

import sys
2019-12-11 13:22:28 +01:00
import logging
from ckan.lib.cli import CkanCommand
2019-12-11 13:22:28 +01:00
import ckanext.spatial.util as util
log = logging.getLogger(__name__)
class Spatial(CkanCommand):
'''Performs spatially related operations.
Usage:
spatial initdb [srid]
Creates the necessary tables. You must have PostGIS installed
and configured in the database.
You can provide the SRID of the geometry column. Default is 4326.
spatial extents
2011-10-03 14:39:18 +02:00
Creates or updates the extent geometry column for datasets with
an extent defined in the 'spatial' extra.
2019-12-11 13:22:28 +01: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
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]
if cmd == 'initdb':
2019-12-11 13:22:28 +01:00
self.initdb()
elif cmd == 'extents':
self.update_extents()
else:
print 'Command %s not recognized' % cmd
def initdb(self):
if len(self.args) >= 2:
2019-12-11 13:22:28 +01:00
srid = self.args[1]
else:
srid = None
2019-12-11 13:22:28 +01:00
return util.initdb(srid)
def update_extents(self):
2019-12-11 13:22:28 +01:00
return util.update_extents()