[ckan-changes] commit/ckanext-spatial: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Wed Nov 30 17:19:53 UTC 2011
2 new commits in ckanext-spatial:
https://bitbucket.org/okfn/ckanext-spatial/changeset/d165f8750097/
changeset: d165f8750097
user: amercader
date: 2011-11-30 18:11:29
summary: [doc] Update README with migration issues
affected #: 1 file
diff -r b13bda7c935dff51bfa415fcd084fb86310d9ae4 -r d165f8750097057a079bf544f548108f3fccc31b README.rst
--- a/README.rst
+++ b/README.rst
@@ -12,7 +12,7 @@
Dependencies
============
-You will need CKAN installed. The present module should be installed at least
+You will need CKAN installed. The present module should be installed at least
with `setup.py develop` if not installed in the normal way with
`setup.py install` or using pip or easy_install.
@@ -29,13 +29,16 @@
Configuration
=============
-Once you have PostGIS installed and configured, you need to create the necessary
-DB tables running the following command (with your python env activated)::
+You will first need to have have PostGIS installed and configured in your
+database (see the "Setting up PostGIS" section for details)
+
+Once this is done, you need to create the necessary DB tables running the
+following command (with your python env activated)::
paster spatial initdb [srid] --config=../ckan/development.ini
-You can define the SRID of the geometry column. Default is 4326. If you are not
-familiar with projections, we recommend to use the default value.
+You can define the SRID of the geometry column. Default is 4326. If you
+are not familiar with projections, we recommend to use the default value.
Problems you may find::
@@ -49,7 +52,7 @@
::
sqlalchemy.exc.ProgrammingError: (ProgrammingError) permission denied for relation spatial_ref_sys
-The user accessing the ckan database needs to be owner (or have
+The user accessing the ckan database needs to be owner (or have
permissions) of the geometry_columns and spatial_ref_sys tables
@@ -59,10 +62,10 @@
ckan.plugins = wms_preview spatial_query dataset_extent_map
If you are using the spatial search feature, you can define the projection
-in which extents are stored in the database with the following option. Use
-the EPSG code as an integer (e.g 4326, 4258, 27700, etc). It defaults to
+in which extents are stored in the database with the following option. Use
+the EPSG code as an integer (e.g 4326, 4258, 27700, etc). It defaults to
4326::
-
+
ckan.spatial.srid = 4326
Tests
@@ -77,20 +80,20 @@
Command line interface
======================
-The following operations can be run from the command line using the
+The following operations can be run from the command line using the
``paster spatial`` command::
-
+
initdb [srid]
- Creates the necessary tables. You must have PostGIS installed
and configured in the database.
You can privide the SRID of the geometry column. Default is 4326.
-
- extents
+
+ extents
- creates or updates the extent geometry column for datasets with
an extent defined in the 'spatial' extra.
-
+
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
+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
@@ -126,7 +129,7 @@
or::
- { "type": "Point", "coordinates": [-3.145,53.078] }
+ { "type": "Point", "coordinates": [-3.145,53.078] }
.. _GeoJSON: http://geojson.org
@@ -168,39 +171,44 @@
* Install PostGIS::
sudo apt-get install postgresql-8.4-postgis
-
+
* Create a new PostgreSQL database::
-
+
sudo -u postgres createdb [database]
-
+
(If you just want to spatially enable an exisiting database, you can
ignore this point, but it's a good idea to create a template to
make easier to create new databases)
* Many of the PostGIS functions are written in the PL/pgSQL language,
so we need to enable it in our database::
-
+
sudo -u postgres createlang plpgsql [database]
* Run the following commands. The first one will create the necessary
tables and functions in the database, and the second will populate
the spatial reference table::
-
+
sudo -u postgres psql -d [database] -f /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql
- sudo -u postgres psql -d [database] -f /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql
+ sudo -u postgres psql -d [database] -f /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql
+
+ **Note**: depending on your distribution and PostGIS version, the
+ scripts may be located on a slightly different location, e.g.::
+
+ /usr/share/postgresql/8.4/contrib/postgis.sql
* Execute the following command to see if PostGIS was properly
installed::
-
+
sudo -u postgres psql -d [database] -c "SELECT postgis_full_version()"
-
+
You should get something like::
-
- postgis_full_version
+
+ postgis_full_version
------------------------------------------------------------------------------------------------------
POSTGIS="1.5.2" GEOS="3.2.2-CAPI-1.6.2" PROJ="Rel. 4.7.1, 23 September 2009" LIBXML="2.7.7" USE_STATS
(1 row)
-
+
Also, if you log into the database, you should see two tables,
``geometry_columns`` and ``spatial_ref_sys`` (and probably a view
called ``geography_columns``).
@@ -208,7 +216,7 @@
Note: This commands will create the two tables owned by the postgres
user. You probably should make owner the user that will access the
database from ckan::
-
+
ALTER TABLE spatial_ref_sys OWNER TO [your_user];
ALTER TABLE geometry_columns OWNER TO [your_user];
@@ -216,6 +224,23 @@
http://postgis.refractions.net/docs/ch02.html#PGInstall
+Migrating to an existing PostGIS database
+-----------------------------------------
+
+If you are loading a database dump to an existing PostGIS database, you may
+find errors like ::
+
+ ERROR: type "spheroid" already exists
+
+This means that the PostGIS functions are installed, but you may need to
+create the necessary tables anyway. You can force psql to ignore these
+errors and continue the transaction with the ON_ERROR_ROLLBACK=on::
+
+ sudo -u postgres psql -d [database] -f /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql -v ON_ERROR_ROLLBACK=on
+
+You will still need to populate the spatial_ref_sys table and change the
+tables permissions. Refer to the previous section for details on how to do
+it.
Setting up a spatial table
@@ -232,13 +257,13 @@
CREATE TABLE package_extent(
package_id text PRIMARY KEY
);
-
+
ALTER TABLE package_extent OWNER TO [your_user];
-
+
SELECT AddGeometryColumn('package_extent','the_geom', 4326, 'POLYGON', 2);
-
+
This will add a geometry column in the ``package_extent`` table called
-``the_geom``, with the spatial reference system EPSG:4326. The stored
+``the_geom``, with the spatial reference system EPSG:4326. The stored
geometries will be polygons, with 2 dimensions (The actual table on CKAN
uses the GEOMETRY type to support multiple geometry types).
@@ -249,10 +274,10 @@
# \d package_extent
Table "public.package_extent"
- Column | Type | Modifiers
+ Column | Type | Modifiers
------------+----------+-----------
package_id | text | not null
- the_geom | geometry |
+ the_geom | geometry |
Indexes:
"package_extent_pkey" PRIMARY KEY, btree (package_id)
Check constraints:
https://bitbucket.org/okfn/ckanext-spatial/changeset/cb290530e907/
changeset: cb290530e907
branch: feature-output-geojson
user: amercader
date: 2011-11-30 18:19:17
summary: [api] Output GeoJSON (Quick and dirty)
affected #: 2 files
diff -r d165f8750097057a079bf544f548108f3fccc31b -r cb290530e90729647add81c6897854ede5f59b45 ckanext/spatial/controllers/api.py
--- a/ckanext/spatial/controllers/api.py
+++ b/ckanext/spatial/controllers/api.py
@@ -49,6 +49,41 @@
.filter(PackageExtent.the_geom.intersects(input_geometry)) \
.filter(Package.state==u'active')
+ if request.params.get('format','') == 'geojson':
+ return self._output_geojson(extents)
+ else:
+
+ ids = [extent.package_id for extent in extents]
+
+ output = dict(count=len(ids),results=ids)
+
+ return self._finish_ok(output)
+
+ def spatial_feed(self):
+ from ckanext.spatial.model import PackageExtent
+ extents = Session.query(PackageExtent).all()
+
+ return self._output_geojson(extents)
+
+
+ def _output_geojson(self,extents):
+ from ckanext.spatial.model import PackageExtent
+ from ckan.lib.base import response
+ from shapely.wkb import loads
+ from geojson import Feature, FeatureCollection, dumps
+ output = []
+ for extent in extents:
+ geometry = loads(str(extent.the_geom.geom_wkb))
+ feature = Feature(
+ id=extent.package_id,
+ geometry=geometry,
+ properties={
+ 'package_id': extent.package_id
+ })
+ output.append(feature)
+
+ response.content_type = 'application/json'
+ return dumps(FeatureCollection(output))
ids = [extent.package_id for extent in extents]
output = dict(count=len(ids),results=ids)
diff -r d165f8750097057a079bf544f548108f3fccc31b -r cb290530e90729647add81c6897854ede5f59b45 ckanext/spatial/plugin.py
--- a/ckanext/spatial/plugin.py
+++ b/ckanext/spatial/plugin.py
@@ -32,6 +32,11 @@
map.connect('api_spatial_query', '/api/2/search/{register:dataset|package}/geo',
controller='ckanext.spatial.controllers.api:ApiController',
action='spatial_query')
+
+ map.connect('/api/geo/{register:dataset|package}',
+ controller='ckanext.spatial.controllers.api:ApiController',
+ action='spatial_feed')
+
return map
def create(self, package):
Repository URL: https://bitbucket.org/okfn/ckanext-spatial/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the ckan-changes
mailing list