Permalink
Browse files

* added basic spatial views \n * fixed formatting bug in geojson.js l…

…ist \n * extended readme \n * extended license information
  • Loading branch information...
1 parent 6632cc0 commit b48412c90656525eca50bb50874915f362237990 @berb committed Jan 7, 2011
Showing with 191 additions and 9 deletions.
  1. +6 −1 LICENSE
  2. +141 −5 README.md
  3. +10 −3 couchapp/lists/geojson.js
  4. +11 −0 couchapp/spatial/points.js
  5. +8 −0 couchapp/spatial/pointsFull.js
  6. +8 −0 couchapp/spatial/pointsOnly.js
  7. +7 −0 couchapp/views/all/map.js
View
@@ -1,6 +1,11 @@
# This software is licensed under the MIT License.
#
-# Copyright (c) 2011 Volker Mische (http://vmx.cx/), Benjamin Erb (http://www.benjamin-erb.de)
+# Copyright (c) 2011
+#
+# Volker Mische (http://vmx.cx/)
+# Benjamin Erb (http://www.benjamin-erb.de)
+# Max Odgen (http://www.maxogden.com/)
+# David Thompson (http://davidmichaelthompson.com/)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
View
146 README.md
@@ -12,6 +12,120 @@ The folder `couchapp/` is a CouchApp that provides useful spatial functions. Fol
* Push to your GeoCouch: couchapp push http://*yourcouch*/*db*
* The CouchApp is then available at http://*yourcouch*/*db*/_design/gc-utils
+The document structure is used consistently within all views and examples, assuming that location information is provided in `doc.geo` containing a GeoJSON struct.
+If your document structure differs, don't forget to adapt the (spatial) views.
+
+Example:
+
+ {
+ "_id": "c0c048ad2770bb836a10f164cc0a3fc0",
+ "_rev": "1-e2d2130da93ca435965d6d3efca22380",
+ "geo": {
+ "type": "Point",
+ "coordinates": [
+ 48.417,
+ 9.983
+ ]
+ },
+ "etc" : "..."
+ }
+
+### spatial
+
+#### points.js
+
+A spatial view that additionally emits the original GeoJSON value (doc.geo)
+
+Example:
+
+ $ curl 'http://localhost:5984/gc-utils/_design/gc-utils/_spatial/points?bbox=80,88,90,90'
+ {
+ "update_seq":203,
+ "rows":[
+ {
+ "id":"c0c048ad2770bb836a10f164cc08a3e5",
+ "bbox":[
+ 81.0876957164146,
+ 89.14168435614556,
+ 81.0876957164146,
+ 89.14168435614556
+ ],
+ "value":{
+ "id":"c0c048ad2770bb836a10f164cc08a3e5",
+ "geo":{
+ "type":"Point",
+ "coordinates":[
+ 81.0876957164146,
+ 89.14168435614556
+ ]
+ }
+ }
+ }
+ ]
+ }
+
+#### pointsFull.js
+
+A spatial view that emits both GeoJSON and the full document (as value).
+
+Example:
+
+ $ curl 'http://localhost:5984/gc-utils/_design/gc-utils/_spatial/pointsFull?bbox=80,88,90,90'
+ {
+ "update_seq":203,
+ "rows":[
+ {
+ "id":"c0c048ad2770bb836a10f164cc08a3e5",
+ "bbox":[
+ 81.0876957164146,
+ 89.14168435614556,
+ 81.0876957164146,
+ 89.14168435614556
+ ],
+ "value":{
+ "_id":"c0c048ad2770bb836a10f164cc08a3e5",
+ "_rev":"1-0e087449742a73b5ce0df1415b1af3f3",
+ "geo":{
+ "type":"Point",
+ "coordinates":[
+ 81.0876957164146,
+ 89.14168435614556
+ ]
+ }
+ }
+ }
+ ]
+ }
+
+#### pointsOnly.js
+
+A spatial view that only emits GeoJSON and no additional value.
+
+Example:
+
+ $ curl 'http://localhost:5984/gc-utils/_design/gc-utils/_spatial/pointsOnly?bbox=80,88,90,90'
+ {
+ "update_seq":203,
+ "rows":[
+ {
+ "id":"c0c048ad2770bb836a10f164cc08a3e5",
+ "bbox":[
+ 81.0876957164146,
+ 89.14168435614556,
+ 81.0876957164146,
+ 89.14168435614556
+ ],
+ "value":null
+ }
+ ]
+ }
+
+### views
+
+#### all
+
+A simple map function that returns all documents. It's like _all_docs, but you can use it as a regular view.
+
### lists
#### geojson.js
@@ -23,10 +137,32 @@ 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"}}
+ {
+ "ok":true,
+ "id":"myfeature",
+ "rev":"1-2eeb1e5eee6c8e7507b671aa7d5b0654"
+ }
+
+
+ $curl -X GET 'http://localhost:5984/gc-utils/_design/gc-utils/_spatiallist/geojson/points?bbox=80,88,90,90'
+ {
+ "type":"FeatureCollection",
+ "features":[
+ {
+ "type":"Feature",
+ "geometry":{
+ "type":"Point",
+ "coordinates":[
+ 81.0876957164146,
+ 89.14168435614556
+ ]
+ },
+ "properties":{
+ "id":"c0c048ad2770bb836a10f164cc08a3e5"
+ }
+ }
+ ]
+ }
## Helper Scripts
@@ -38,7 +174,7 @@ In the folder `misc` you can find helpful scripts or snippets for GeoCouch.
This node.js script can be handy for generating test data. It creates random documents within given value ranges. The script expects the following parameters:
* The URI of the database to fill
- * A bounding box of the area to fill
+ * A bounding box of the area to fill (as bbox JSON array)
* The number of documents to generate
Example call:
View
@@ -1,3 +1,10 @@
+/**
+ * This function outputs a GeoJSON FeatureCollection (compatible with
+ * OpenLayers). The geometry is stored in the geometry property, all other
+ * properties in the properties property.
+ *
+ * @author Volker Mische
+ */
function(head, req) {
var row, out, sep = '\n';
@@ -9,12 +16,12 @@ function(head, req) {
send('{"type": "FeatureCollection", "features":[');
while (row = getRow()) {
- out = '{"type": "Feature", "geometry": ' + JSON.stringify(row.value.geometry);
- delete row.value.geometry;
+ out = '{"type": "Feature", "geometry": ' + JSON.stringify(row.value.geo);
+ delete row.value.geo;
out += ', "properties": ' + JSON.stringify(row.value) + '}';
send(sep + out);
sep = ',\n';
}
- return "\n]}";
+ send("]}");
};
View
@@ -0,0 +1,11 @@
+/**
+ * A simple spatial view that emits GeoJSON plus the original GeoJSON value and document id.
+ */
+function(doc){
+ if(doc.geo){
+ emit(doc.geo, {
+ id: doc._id,
+ geo: doc.geo
+ });
+ }
+}
@@ -0,0 +1,8 @@
+/**
+ * A simple spatial view that emits the GeoJSON plus the complete documents.
+ */
+function(doc){
+ if(doc.geo){
+ emit(doc.geo, doc);
+ }
+}
@@ -0,0 +1,8 @@
+/**
+ * A simple spatial view that emits only the GeoJSON object further values.
+ */
+function(doc){
+ if(doc.geo){
+ emit(doc.geo, null);
+ }
+}
@@ -0,0 +1,7 @@
+/**
+ * A simple map function mocking _all, but allows usage with lists etc.
+ *
+ */
+function(doc) {
+ emit(doc.id, doc);
+}

0 comments on commit b48412c

Please sign in to comment.