Spatial Views and Php

Does this exist, yet? (querying a spatial view in php)

I’m going to be really bummed if it doesn’t, as I think I have the perfect test case. Is there a way to use spatial views or can someone show me a good workaround in PHP?

Here’s what I’ve done. I’ve made a spatial view - ListAllUsersSpatial, that returns users with latitude and longitude of their location.

function (doc, meta) { user = meta.id.indexOf("user:xxx"); if(user==0 && doc.Latitude && doc.Longitude) { emit ( {type: "Point", coordinates:[doc.Latitude, doc.Longitude]}, meta.id); } }

Then I use my bbox parameter to find users near me (example from my web console):

…_spatial/ListAllUsersSpatial?bbox=25%2C-100%2C35%2C-90&connection_timeout=60000

And the results are just what I want. However, now I want to actually use this query in my code. I’m using php for couchbase access.

But, code like this doesn’t work:

$BBox = LatLongBBox($Latitude, $Longitude, 6371, 40);
$BBoxString = $BBox[0].",".$BBox[1].",".$BBox[2].",".$BBox[3];

$options = array(
“limit” => 10,
“bbox” => $BBox
);

$result = $Couchbase->view(“user”, “ListAllUsersSpatial”, $options);
foreach ($result[“rows”] as $row)
{
echo “Key:”.$row[‘key’]." Value:".$row[‘value’]."\n";
}

Alas, I’m doing something wrong or spatial views are not supported :frowning:

Here is the error I see:

PHP Warning: Couchbase::view(): Unrecognized view option ‘bbox’ in /var/web/matchclip.retiredastronaut.org/api/test_api_calls.php on line 26
PHP Fatal error: Uncaught exception ‘CouchbaseServerException’ with message '[500, error, Error opening view ListAllUsersSpatial, from set default, design document _design/user: {not_found,
missing_named_view}]

Anyone? Does this board get read? Is there a better place to pose these queries?

No you are at the good place, sorry for the delay…

Hello,

It is currently not possible to access the spacial views from the PHP client.

You have to call the View REST API directly from PHP.

Note an Enhancement Request exists for this:
http://www.couchbase.com/issues/browse/PCBC-207

Regards
Tug
@tgrall

OK, Thanks for the response. The Views are what really sets couch apart from DynamoDB and the location query-able views (bounding box) are something I’d like to use. By ‘calling the REST API directly’ do you mean doing a web query and then parsing the output? (e.g. couchbase.com:8091?bbox=xxx). I’m not sure I’ll be able to do that with my app or I’m just nor sure how.