Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sort by 2 fields? is there any hacks or with index.yaml? or geoPT?

q = WorldObject.all()
# define boundaries
# left
q.filter('x >=', x)
# right
q.filter('x <', x + width)
# top
q.filter('y >=', y)
# bottom
q.filter('y <', y + height)

#q.filter('world', world_key)

wobjects = q.fetch(1000)

I got an error saying I can't use multiple sorts

q = WorldObject.all()

q.filter('xy >=', db.GeoPt(1, 1))
q.filter('xy <', db.GeoPt(4, 4))

wobjects = q.fetch(1000)

I've found this http://www.spatialdatabox.com/ it might be interesting as it uses the Amazon EC3 for retriving geo data.

this query gives me wrong world objects: with lat=9 why? if i limit between 1 and 4? thanks


Blockquote

like image 767
Totty.js Avatar asked Jan 28 '26 06:01

Totty.js


2 Answers

App Engine does not currently support the type of querying you are trying to do. Although they have mentioned that a solution is in the works.

But Google does have a nice walk through on how to build something like what you are asking about. Also see one of Nick Johnson's blog posts for some interesting discussion on the general topic.

like image 140
Robert Kluin Avatar answered Jan 29 '26 19:01

Robert Kluin


google's datastore indexes are sequential. furthermore, the datastore refuses to satisfy range queries that require more than one index. You can either implement a GiS index on top of the datastore (hard) or just do the range query on one axis and exclude out of range results in your application code (easy).

So if you want to go the hard way, you can get that using geohash

Example of the easy way:

myquery = MyModel.all()
myquery.filter("x >=" x)
myquery.filter("x <" x+delta_x)

resultset = [result for result in myquery.fetch(1000) if y <= result.y < y+delta_y]
like image 36
SingleNegationElimination Avatar answered Jan 29 '26 19:01

SingleNegationElimination



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!