Hi mclovin,

This query can't be executed efficiently with standard indexes on _any_
database. A relational database using standard indexes will satisfy this
query by doing an index scan on one inequality (eg, the latitude), then
filtering by the other (eg, the longitude). In the worst case, this entails,
for example, retrieving and filtering a slice of the entire west cost of the
US, or everything near the equator, just to get a few points in one city!
You can, of course, do this in App Engine if you want, but there's a better
solution...

The solution - both for relational databases and App Engine - is to use
spatial indexing. There are a number of Python libraries that provide
spatial indexing for App Engine. The best is undoubtedly Roman Nurik's
geomodel: http://code.google.com/p/geomodel/

-Nick Johnson

On Thu, Jun 18, 2009 at 6:58 PM, mclovin <[email protected]> wrote:

>
> Hey,
>
> I have entities stored with x and y values. What I want to do in one
> of my views is to filter them out by their x and y values.
>
> so I have
>
> agents = Agent.all()
>
> neighbors = agents.filter("x >",  user.agent.x-10).filter("x <",
> user.agent.x+10).filter("y >",  user.agent.y-10).filter("y <",
> user.agent.y+10)
>
> which would give me all the other agents within 10 spaces of the
> user's agent making the request.
>
> However When I run it I get a "relational operator" error so I have to
> do this:
> agents.filter("x >",  user.agent.x-10).filter("x <", user.agent.x+10)
> and then iterate through them to filter out the y values manually.
> or this:
> agents.filter("y >",  user.agent.y-10).filter("y <", user.agent.y+10)
> and then iterate through them to filter out the x values manually.
>
>
> So my question is, why cant i filter out both x and y values at the
> same time on a single query?
> >
>


-- 
Nick Johnson, App Engine Developer Programs Engineer
Google Ireland Ltd. :: Registered in Dublin, Ireland, Registration Number:
368047

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to