开发者

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 开发者_JAVA技巧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


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.


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]


I got to work it in some way, thanks to GeoModel. What do you think? it might work on large scale? I would like to know how many queries it does under the hood if possible. thanks for all your help:

def get_world_objects_in_area(input):
    try:
        x = input.x
        y = input.y
        width = input.w
        height = input.h
        world_key = input.k
    except:
        return False

    # boundaries
    top = to_map_unit(y)
    bottom = to_map_unit(y-height) # this is "-" because in flash the vertical axis is inverted
    left = to_map_unit(x)
    right = to_map_unit(x+width)

    bounding_box = geo.geotypes.Box(top, right, bottom, left)

    query = WorldObject.all()
    query.filter('world', world_key)

    r = WorldObject.bounding_box_fetch(query,
                                       bounding_box,
                                       max_results=1000)

    return r

def to_map_unit(n):
    if n is not 0:
        divide_by = 1000000000000
        r = Decimal(n) / Decimal(divide_by)
        return float(r)
    else:
        return 0
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜