CouchDB + Spatial = Awesome

Overview

What is CouchDB?

A NoSQL document store

Where Does CouchDB fit?

Getting Started with CouchDB

Not Installing CouchDB

Interacting with CouchDB

Simple GET

curl http://sidelab.iriscouch.com/seattle_neighbourhood/c0d5867266787565c510f5a7e20000f2
{
 "lat/lng": "47.612237, -122.290868",
 "_id": "c0d5867266787565c510f5a7e20000f2",
 "_rev": "3-3b75f0b5202e28c14de19addcc2b8d3d",
 "Website": "http://www.seattleschools.org/schools/madrona/",
 "Address": "1121 33rd Ave",
 "Latitude": "47.612237",
 "City Feature": "Alternative Schools",
 "Longitude": "-122.290868",
 "Common Name": "Madrona K-8"
}

NOTE: While this data has lat/lng data it is not in an ideal form, for GeoCouch to use.

Simple PUT

New data can be added through use of the HTTP PUT method:

curl -X PUT http://sidelab.iriscouch.com/test/test -d '{"type":"Feature", "color":"orange" ,"geometry":{"type":"Point","coordinates":[11.395,48.949444]}}'
{
    "ok":true,
    "id":"test",
    "rev":"1-2eeb1e5eee6c8e7507b671aa7d5b0654"
}

So much more

CouchDB and Location Based Services

Why?

From my personal observations, location based data (with particular reference to Point of Interest data) generally contains:

Effectively storing these custom attributes in an RDBMS, is generally painful and ugly.

CouchDB offers an alternative

And you've got options!

Option 1: Hybrid Stack

Hybrid Stack Pros & Cons

PROS

CONS

Options 2: Pure Couch

Pure Couch Pros & Cons

PROS

CONS

Importing Data

Many Options

GDAL Example

Given you lot are spatial types, I'm going to recommend using GDAL (>= 1.9.0), and in particular the ogr2ogr tool.

ogr2ogr -f couchdb "couchdb:http://yourname.iriscouch.com/parking" sourcedata.shp -nln boundaries -overwrite

Credentials can be passed in using the COUCHDB_USERPWD environment variable:

COUCHDB_USERPWD=admin:yourpass ogr2ogr -f couchdb "couchdb:http://yourname.iriscouch.com/parking" sourcedata.shp -nln boundaries -overwrite

More info: http://www.gdal.org/ogr/drv_couchdb.html

NOTE: Use the HTTP API for Updates!

GeoCouch

What is GeoCouch

Using GeoCouch

Using GeoCouch - Writing a CouchApp

CouchApp Uploaders

There are a number of tool available to help with the process of deploying a CouchApp into a CouchDB instance (including IrisCouch, CloudAnt, etc):

Demo

see: https://github.com/DamonOehlman/demo-kanso-geocouch

Summary

Questions?