Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmx committed Jan 6, 2011
0 parents commit 7570319
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.couchapprc
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This software is licensed under the MIT License.
#
# Copyright (c) 2011 Volker Mische (http://vmx.cx/)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Helper Functions for GeoCouch
=============================

This is a small CouchApp that contains some helper functions for GeoCouch. Licensed under the MIT License.

lists
-----

### geojson.js ###

This function outputs a GeoJSON FeatureCollection (compatible with
OpenLayers). The geometry is stored in the `geometry` property, all
other properties in the `properties` property.

Examples:

$ curl -X PUT -d '{"type":"Feature", "color":"orange" ,"geometry":{"type":"Point","coordinates":[11.395,48.949444]}}' 'http://localhost:5984/gc-utils/myfeature'
{"ok":true,"id":"myfeature","rev":"1-2eeb1e5eee6c8e7507b671aa7d5b0654"}

$ curl -X GET 'http://localhost:5984/vmxch/_design/gc-utils/_list/geojson/all'
{"type": "FeatureCollection", "features":[{"type": "Feature", "geometry": {"type":"Point","coordinates":[11.395,48.949444]}, "properties": {"_id":"myfeature","_rev":"1-2eeb1e5eee6c8e7507b671aa7d5b0654","type":"Feature","color":"orange"}}
1 change: 1 addition & 0 deletions _id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_design/gc-utils
20 changes: 20 additions & 0 deletions lists/geojson.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function(head, req) {
var row, out, sep = '\n';

// Send the same Content-Type as CouchDB would
if (req.headers.Accept.indexOf('application/json')!=-1)
start({"headers":{"Content-Type" : "application/json"}});
else
start({"headers":{"Content-Type" : "text/plain"}});

send('{"type": "FeatureCollection", "features":[');
while (row = getRow()) {
out = '{"type": "Feature", "geometry": ' + JSON.stringify(row.value.geometry);
delete row.value.geometry;
out += ', "properties": ' + JSON.stringify(row.value) + '}';

send(sep + out);
sep = ',\n';
}
return "\n]}";
};

0 comments on commit 7570319

Please sign in to comment.