[ckan-dev] use Data Api for querying individual records in dataset

Alice Heaton a.heaton at nhm.ac.uk
Tue Apr 7 08:58:36 UTC 2015


Hello,

> with the datastore and Ckanext-spatial.

ckanext-spatial is about providing geospatial metadata for datasets. It does not provide geospatial datastore queries, which is what you are looking for.

There is another extension that provides this: ckanext-dataspatial

https://github.com/NaturalHistoryMuseum/ckanext-dataspatial

Note that this will require you to setup your database and dataset:

1. You have to enable PostGis (http://postgis.net/) for your datastore database. Presumably you have already done this for the ckan database, the process is the same;
2. ckanext-dataspatial does not work directly on latitude/longitude columns, but on PostGis columns. So you have to create those columns, and then populate them based on your latitude/longitude fields. ckanext-dataspatial provides an API to perform those tasks, so you can embed these in your workflow (see the github page for documentation).

Once this is done, you can then use WKT (http://en.wikipedia.org/wiki/Well-known_text) polygons as part of your search filters. For instance a bounding box would look something like this:

POLYGON(36 114, 36 115, 37 115, 37 114, 36 114)

And all you need is to set the '_tmgeom' filter. For example the following URL will query all items that match the word 'ufo' within the above defined bounding box:

http://.../api/action/datastore_search?resource_id=...&q=ufo&filters=_tmgeom%3APOLYGON+((36+114%2C36+115%2C37+115%2c36+114))

There are more examples in the github page.

Don't expect this plugin to be a simple drop-it-in-and-it-works plugin. We've developed this for our own needs, and so far we're probably the only people using it (it's been recently refactored out of a larger code base), so there will be probably be a bit of work before this becomes stable and easy for everyone. We'll fix any issue you report of course :-)

Cheers,
Alice




More information about the ckan-dev mailing list