pouchdb / geopouch

Spatial plugin from PouchDB extracted and supporting N dimentional coordinates.
http://pouchdb.com
Apache License 2.0
85 stars 14 forks source link

complete, browser based example? #11

Closed akosmaroy closed 8 years ago

akosmaroy commented 8 years ago

I wonder if there is a complete, browser based example on how tou use GeoPouch, that would demonstrate:

scubbx commented 8 years ago

Did anyone ever succeed in using GeoPouch in a browser? I also still am not able to get it running?

marten-de-vries commented 8 years ago

I did succeed in using GeoPouch in a browser-like environment, but that's quite a long time ago. No idea if it would still work. Anyway, I used browserify, and this pretty much was my source file: https://git.launchpad.net/python-pouchdb/tree/js/python-pouchdb-js/index.js#n52 .

As for querying, did you look at the test suite for examples? https://github.com/pouchdb/geopouch/blob/master/test/test.js

Hope that helps.

scubbx commented 8 years ago

Thanks for the hints! I'm not even getting to the query part, since the geopouch library does not even attach to any PouchDB database. I'm able to call a "geopouch" object at the root level. I tried browserify and webpack on the dist-version and on the source version. If I use these versions, already the PouchDB.plugin('Spatial',geopouch); command fails. Sadly, I'm far from being an expert with browserify and the likes of ...

calvinmetcalf commented 8 years ago

if you include the dist version via a script tag that would be when you'd then do PouchDB.plugin('Spatial',geopouch);

scubbx commented 8 years ago

The suspicious thing for me is, that the call PouchDB.plugin('Spatial',gepouch); does return a function.

To clearly state my proceeding:

My HTML file looks like this:

pdbspatialquestion1

To visualize the feedback, I excluded any scripts from this code but entered them in the JS console of the browser:

pdbspatialquestion

When I do not use the downloaded version of geopouch, but a browserified one, a message after the command PouchDB.plugin('Spatial',gepouch); is displayed, saying Uncaught ReferenceError: geopouch is not defined(…)'.

I hope this is not due to some misunderstanding or technical shortcoming on my part ... ? Or better: I hope it is! :-)

calvinmetcalf commented 8 years ago

sorry, the syntax should actually be PouchDB.plugin(geopouch)

scubbx commented 8 years ago

This works, the library is loaded and attached to any PouchDB ! :-D But.... while the same query produces results on a CouchDB via its native HTTP API, it does not give any results via PouchDB. Neither on the replicated version of the CouchDB nor on the CouchDB accessed by the PouchDB interface. The query and result via PouchDB look like this:

pdbspatialquestion2

Using the rtree branch makes no difference.

The results via the CouchDB API look like this:

pdbspatialquestion3

vmx commented 8 years ago

@scubbx Try [[0, 180], [0, 90]] instead.

scubbx commented 8 years ago

haha Right!

But nontheless: pdbspatialquestion4

docdb is the CouchDB via PouchDB interface, localdocdb is the replicated version.

Both databases are filled:

pdbspatialquestion5

calvinmetcalf commented 8 years ago

ok this is a different error, can you post graph/roads?

scubbx commented 8 years ago

I took a screenshot, since it has nice code-highliting:

pdbspatialquestion6

Except for the design document, all documents have the entrytype property set to link.

One typical document looks like this:

pdbspatialquestion7

calvinmetcalf commented 8 years ago

can you add a catch(function (err){console.log(err)}) to the end of the chain?

scubbx commented 8 years ago

This does not give more information. Did I use it correctly?

pdbspatialquestion8

calvinmetcalf commented 8 years ago

instead of {limit: 5}, function (resul... you should do {limit: 5}).then(function(resul...

also limit isn't a supported option

scubbx commented 8 years ago

localdocdb.spatial('graph/roads', [[0, 180], [0, 90]]).then( function(resul){console.log(resul);} ).catch(function (err){console.log(err)}); and the same on docdb.spatial did not change anything.

calvinmetcalf commented 8 years ago

it looks like there are 2 errors that top one of the property '0' of undefined, does that have a stack trace?

scubbx commented 8 years ago

This one? pdbspatialquestion9

calvinmetcalf commented 8 years ago

ahaha looks like an invalid geometry, try doing pause on uncaught exception (or caught if that doesn't catch anything)

beckerIGG commented 8 years ago

Hi, i also tried to get some geojson features out of the pouchdb. geopouch is working, but i cannot get the features out of it. I use coudb (without spatial) to store the docs and then replicate to pouch with spatial plugin. I use: evt_db.spatial(function (doc) {emit(doc.geometry);}, [0, 180, 0, 90]).then(function(result){ console.log(result)}).catch(function (err){console.log(err)}); but receive:

Possibly unhandled Error. can't delete it if there is nothing in the tree geopouch.js (Zeile 171 a typical feature looks like that: feature

What am i doing wrong? are the features defined correctly?

calvinmetcalf commented 8 years ago

ok I think there might be a bug related to replication and or error catching, I will investigate further

beckerIGG commented 8 years ago

Hi, thx for keeping in touch. I broke it down to the following. If i load two json files directly into pouchdb (via bulkDocs() it works, but only for the very first time. afterwards it does not work until i delete the database manually. `evt_db.bulkDocs([{ "_id" : "eb46c0cc24eabb6427af7eac2b0012ac", "geometry" : { "type" : "Point", "coordinates" : [13.3971420055456, 52.5296601136334] } }, { "_id" : "eb46c0cc24eabb6427af7eac2b001c9f", "geometry" : { "type" : "Point", "coordinates" : [13.6384082053328, 52.418740058446] } }]);

//evt_db.replicate.from(evt_remoteCouch);

evt_db.spatial( function(doc){ emit(doc.geometry);} , [[13.3971420055456,52.418740058446],[13.6384082053328,52.5296601136334]]).then(function(resp) { resp.length.should.equal(2); console.log(resp); var nr = resp.map(function(i) { console.log(i); return i.properties; }); nr.sort(); }).catch(function(err) { console.log(err) });` The result is: first_try Reloading the page produces the following message (if i comment out the bulkDocs(), since everything should be inside Pouch): second_try

Any ideas or hints? i am not specialist in Javascript, but i need some help. Also i just get back the id. How can i get the properties of my json objects? because emit just allows to give back the geometry property.

THX in advance for any advice ot help

calvinmetcalf commented 8 years ago

ok I'll look into it when I get a chance

calvinmetcalf commented 8 years ago

ok figured it out, there was something wonky in how i was handling temp views, temp ones should now actually be temp in version 2.0.1

calvinmetcalf commented 8 years ago

closing this issue as it somewhat meandered into something new, if there are still problems with the indexing lets start a new issue

akosmaroy commented 8 years ago

thus, is there a complete, browser based example somewhere? :)

calvinmetcalf commented 8 years ago

no but we went over all of your questions in this thread I'm pretty sure, if there are things still stumping you ...

scubbx commented 8 years ago

Thank you for the hints! The examples given on the GeoCouch repository description are working, my big database is not. I will report back when I found the problem.

ryadbkr commented 7 years ago

@akosmaroy any luck finding an example ?

akosmaroy commented 7 years ago

@ryadiv nope :(