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).
Related
Scenario: I have a table with location records having a timestamp and a latlng field, I need to find closest points having a max distance of 100 meters between them within a time range of, say, 1 hour.
I've tried to index the latlng field with Solr's LatLonPointSpatialField and then doing some faceting on the timestamp field then taking each point of latlng and doing {!geofilt} with the point and of distance of 0.01, but as you can see this will be very slow since I've to take each point and try it with a range of timestamp. And all what I need to just to find closest points of latlng within a timestamp range. I don't know if there's a better way but I have the feeling that there's something in Solr that could help me out but I missed.
what you are trying to do is some sort of result clustering, Solr does have a contrib to do that, but I suspect it will not work out of the box. Maybe you could fork and customize it for you.
The more promising approach would be creating a Streaming Expression that does all you need. I am pretty confident you have all functions needed to build the whole thing.
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.
I have a set of 900 Latitude and Longitude Coordinates-- I need a relatively simple method for finding the 'State' referred to by these coordinates. If it helps, the data is in excel.
Google provide a Geocoding service. Part of this is reverse geocoding which converts geographic coordinates into a human-readable address including States. This Demo illustrates what can be done. There are limits to what you can do with this service.
Try to use the average values as provided here. With a bit of luck, most of your 900 coordinate pairs belong to the state with the nearest center. Calculation of distances between longitude/latitude locations is explained here.
An alternative would be to use a ZIP table with US postcodes as provided here. Once you know the postcode, you know the state, don't you? I'm not sure, but each state has an interval of ZIP codes. Once you know the ZIP code of a location, you can find the interval and the state it belongs to.
A list of coordinates of US locations could help to get a more exact allocation: http://www.bcca.org/bahaivision/fast/latlong_us.html
Find the nearest location in the list and take its state as result.
Google requires that geocoding / reverse geocoding be used with maps that users can see, so if that isn't an option for you, I think the best way is to use a database with spatial functions. First, you'll need the state boundaries found for free at NationalAtlas.gov. I use SQL Server (need 2008 or 2012 versions) and you can use the STContains() method to find what state it belongs to.
A simpler solution would be to just use the ezcmd.com rest API services.
They provide two APIs:
http://ezcmd.com/apps/app_geo_postal_codes#geo_postal_codes_api
1) All you have to do is just give it a zip code and a country code (for usa you either use US or USA) and optionally you'll pass the distance radius, and units (Miles or Km) and it'll return all other zip codes with state and province that are within the given distance
2) Free search, where you give it any fuzzy search phrase that includes either one of zip / city / state / province and country and it returns the best matches for that search phrase.
Hint: You can use #2 to find the zip code for a fuzzy (human readable) address and pass that zip code to #1 to find nearest places to that zip code.
Also they have another API that returns zip code along with full geo location information for a given IP address here:
http://ezcmd.com/apps/app_ezip_locator#ezip_locator_api
Enjoy ! I hope this helps.
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
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.