Global Positioning System Reference
In-Depth Information
1
shp2geocouch ./pois/pois.shp
Fig. 4. Importing a shapefi le into CouchDB.
As a result, GeoCouch builds a spatial index. The status of the indexer
can be checked by visiting the URL: http://localhost:5984/_utils/status.
html.
In CouchDB, operations to create, read, update and delete are performed
using HTTP requests. The GET request is used to retrieve documents. PUT or
POST requests are used to create new documents. Updates are done through
a PUT request. The HTTP DELETE is used to delete documents. As CouchDB
implements MVCC to prevent blocks, when a GET query is performed the
last version of the document is returned. CouchDB also provides a way
to refer to older versions of the document by adding the parameter “&
rev=version_value” in the URL.
CouchDB (and GeoCouch) is not able to perform a multi-dimension
spatial query. In other words, CouchDB cannot perform a bounding-box
(bbox) query with the addition of fi ltering by a specifi c fi eld. One way to
work around this limitation is to execute the bbox query and then perform
an additional search in the query result.
Therefore, in order to execute query Q1 (retrieve all the restaurants in
New York) it is necessary to request all PoIs in New York City and then fi lter
the results by restaurants. The URL of the HTTP request of the fi rst part of
Q1 (retrieve all PoIs in New York City) is presented in Fig. 5. Then the query
result must be refi ned by the type of PoI (restaurants).
The URL contains the address (IP and port) of the machine where
CouchDB is running, the database name (POIS) and the parameters needed
to apply the bbox fi lter. The values of the bbox for New York City were
obtained through a query on the Municipalities database by a temporary view
with the map function (Fig. 6). The function is applied by CouchDB for each
document of the database. The documents that fulfi ll the query condition
are exhibited in the query result. The query result contains documents in
GeoJSON increased by the bbox geometry presented in the document.
1
2
http://localhost:5984/pois/_design/geo/_spatial/basic?bbox=-
74.2557,-40.4957,-73.6895,-40.9176
Fig. 5. URL that performs Q1 in CouchDB.
1
2
3
4
5
function(doc) {
if (doc.name == “New York”) {
emit(doc.id, doc)
}
}
Fig. 6. Map function that retrieves the city of New York stored in the CouchDB.
Search WWH ::




Custom Search