Best Workaround for Geopoint SubQuery - parse-platform

I have a class with objects that contain a geopoint type. Each object also has a boolean entitled "goodPoint".
I need to return these objects sorted from distance to user's location.
I have been using the "near" function to accomplish this.
I would also like to only grab the objects who have the boolean "goodPoint" set to "true".
I would typically use "isEqual" or "wherekey".
However, it is my understanding that parse does not support combinational queries when a geopoint query (like "near") is also used.
What is the best workaround for effectively achieving my desired result without the use of the unsupported combinational query?
Possible thoughts:
I would like to get all 1000 points. I could filter out client side, but am afraid this will not be scalable in the long run as I anticipate around 10%-20% of my points to be "bad" (goodPoint=false) where worst cast case would limit me to 800 points.
I could create a "graveyard" to send bad points so that they don't list in the nearest 1000, but I'm not sure where exactly to put the points for latitude and longitude.
I could move the "bad" points to another class, but parse doesn't seem to allow you to move objects across classes.
I also could just delete the points, but I need to keep them for user feedback purposes.

Related

Calculate surrounding index keys

I'm attempting to retrieve H3 index keys directly adjacent to my current location. I'm wondering if this can be done by mutating/calculating the coordinate directly or if I have to use the library bindings to do this?
Take this example:
./bin/geoToH3 --resolution 6 --latitude 43.6533055 --longitude -79.4018915
This would return the key 862b9bc77ffffff. I now want to retrieve all relevant 6 neighbors keys (the values of the kRing I believe is how to describe it?).
A tangent though equally curious question might render the above irrelevant: if I were attempting to query entries that have all 7 indexes is there a better way than using an OR statement seeking all 7 values out? Since the index is numeric I'm wondering if I could just check for a range within the numeric representation?
The short answer is that you need to use kRing (either through the bindings or the command-line tools) to get the neighbors. While there are some limited cases where you could get the neighbors through bit manipulation of the index, in many cases the numeric index of a neighbor might be distant. The basic rule is that while indexes that are numerically close are geographically close, the reverse is not necessarily true.
For the same reason, you generally can't use a range query to look for nearby hexagons. The general lookup pattern is to find the neighboring cells of interest in code, using kRing, then query for all of them in your database.

Fuzzy matching a list of coordinates (Golang)

I'm trying to create a simple tool which will allow a user to specify two places around Seattle.
I'm working with the WSDOT traffic data set. An example of the output can be found here: https://gist.github.com/jaxxstorm/0ab818b300f65cf3a46cc01dbc35bf60
What I'd like to be able to do is specify two locations like:
Bellevue
Seattle
and then lookup all traffic times for those locations.
I'm considering doing a reverse geocode like this answer but I want it to be "fuzzy" in that I don't want people to have to specify exact locations. I also suspect the processing time for this might be long as I'd have to loop through the list, and reverse lookup all the coordinates which could take a short while
Is there any better alternatives for processing this data in this way? I'm writing the tool in Go
You have two problems for each set of points (start and end):
Convert locations to lat lon
Fuzzy match lat,lon to this traffic data (which contains lat,lon)
The location to lat,lon conversion is pretty straightforward using a reverse geocoding api like the one available from google.
To match lat,lon fuzzily, you could either truncate lat lon and store that as a hash (so that you're storing approximate matches), then lookup data that way, or you could do a radius calc and pick results within that radius (this requires some math involving the radius of the earth which you can look up easily enough, it can be done in sql if your data is in a db for example).

How to structure an efficient GeoLocation and Time query

Hey rethinkers!
i've got a query optimization question that i cant quite figure out. It deals with geoLocation and time. I've got a ton of events, that all have a startTime, endTime (indexed), and location (indexed). If i want to get the events that are happening nearby by a certain location that haven't happend yet, i can do one of two ways:
I can get and filter all the events that haven't happend yet based on the end time, then calculate the location of all those events and only return the ones with the specified radius.
I can use the getNearest() command (which would return all the expired events) and then filter out the events that haven't happend yet. My one worry with this apporach is that getNearest() specifies how many to return, but I essentially need all of them within the given radius so i don't miss any events that haven't happend yet.
Im just unsure how i can figure out the fastest/most effecient query for this.
The best option to me would seem to be to filter and get all events that haven't happend yet, then use getNearest() to take advatage of the indexes. But i can call a get nearest on a filtered set. Please help!?!?!
For getting all events within a radius, I recommend using getIntersecting() together with r.circle.
That is not only more efficient than getNearest, but also doesn't have any limit on the number of returned documents.
You might need to make the radius you pass into r.circle slightly larger, to account for the fact that the generated polygon will be slightly smaller than the specified radius between the vertices.

MongoDB geospacial query

I use mongo's "$near" query, it works as expected and saves me a lot of time.
Now I need to perform something more complicated. Imagine, we have a collection of "checkins" (let's use foursquare notation), that contains the geospacial information (nothing unusual: just lat and lng) and time. Given the checkins by two people, how do I find their "were near to each other" checkins? I mean, e.g.: "1/23/12 you've been 100 meters away"
The easiest solution is to select all the checkins by the first user and find nearest checkin for each first user's checkin on the framework side (I use ruby). But is it the most efficient solution?
Do you have better ideaas? May be I need some kind of a special index?
Best,
Roman
The MongoDB GeoSpatial indexes provide two types of queries: $near and $within. The $near query returns all points in the database that are within a certain range of a requested point, while the $within query lists all points in the database that are inside of a particular area (box, circle, or arbitrary polygon).
MongoDB does not currently provide a query that will return all points that are within a certain distance of any member of another set of points, which is what you seem to want.
You could conceivably use the point data from user1 to build a polygon describing the "area of interest" and then use the $within query to see if there were any checkins by other people inside of that area. If you use a compound index on location & date, you could even restrict the query to folks who were inside of that area on a particular day.
References:
http://docs.mongodb.org/manual/core/indexes/#geospatial-indexes
http://docs.mongodb.org/manual/reference/operators/#geospatial

ObjectMapper: Find geo places within a certain square, sorted by proximity

I am building a Ruby app on Heroku using Sinatra and a PostgreSQL database interfaced with ObjectMapper. I need to run a query which returns a list of all locations in a database (which each have latitude and longitude attributes) within a certain rectangle (corresponding to the visible map region).
I can do this by searching for latitudes which fall within the map bounds, same for longitude. My question however is, how do I return these results sorted by proximity? I could get all results matching the query and then sort them once they are out of the database, but I want to run this query in batches and return only say the nearest 5 places, then places 6-10, then 11-15, etc.
Can this be done?
EDIT: I have not decided yet whether to use PostgreSQL for sure, I might use MongoDB if it is appropriate.
The immediate question is proximity to what? You need to define a point to use as the basis for the proximity. You can then use st_distance from the ORDER BY clause to sort by distance between the geometry objects. This can be combined with LIMIT and OFFSET to do exactly what you want.

Resources