Sticking bicycle paths in CouchDB

In this installment of How To Stick Anything In CouchDB, I'll take some bicycle path data released by the municipality of Copenhagen and stick them in CouchDB. As always I'm working in Terminal under Mac OS X.

Bicycle paths in Copenhagen, served live by CouchDB:

The data is in shape format, so it's almost too easy using shp2geocouch. First download the data.

wget http://www.kk.dk/Borger/ByOgTrafik/CyklernesBy/~/media/B12983F7B5E3451F8716F7C072A5B101.ashx
mv B12983F7B5E3451F8716F7C072A5B101.ashx bikepaths.zip
unzip bikepaths.zip

What have we downloaded?

$ ls *.shp
Cykelmidter_2006_r2_ETRS89zone32N.shp	Cykelmidter_2006_r2_WGS84.shp

Create a CouchDB database to hold the data. I'm using my CouchDB installation. You should use yours:

curl -X PUT username:password@gd.iriscouch.com/bikepathscph

Use shp2geocouch to upload the data. It shouldn't matter which one of the shape files we use, because shp2geocouch does reprojection:

shp2geocouch Cykelmidter_2006_r2_WGS84.shp http://username:password@gd.iriscouch.com/bikepathscph

Notes

There is a problem with encoding. If you click on one of the street features on the map above, streets that contain the danish letters [æ,ø,å] are missing those letters. I tried testing a conversion to GeoJSON from the shapefiles with ogr2ogr and it's the same. God I hate encoding!

By the way, this is how to convert to GeoJSON from Shape using ogr2ogr:

ogr2ogr -f "GeoJSON" cykelmidter.json Cykelmidter_2006_r2_WGS84.shp

If you don't have shp2geocouch, it's really easy to install (at least it was on my Mac):

sudo gem install shp2geocouch

There is a "Ruby gem" install home page here, and github here.

6 thoughts on “Sticking bicycle paths in CouchDB”

  1. Great article, again!
    Encoding

    Regarding encoding, check out the ESRI shapefile driver page:

    http://www.gdal.org/ogr/drv_shapefile.html

    You can specify the encoding of the .dbf file.

    I had no problems on windows

    shp2geocouch

    Is it possible to use ogr2ogr options like – a_srs, -s_srs, -t_srs ?

    If not, it would be nice to add the feature. Of course, the nice preview map wouldn’t work because it uses EPSG:4326 or EPSG:900913.

    /Martin

  2. Hi Kostas, use qgis to convert your SHP to UTF-8 encoding, set environment variable SHAPE_ENCODING=UTF-8 and use ogr2ogr -f couchdb… you’ll get your letters correctly into CouchDB.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.