Query Overpass turbo by latitude longitude - gps

How do I ask overpass turbo to give me the way tags corresponding to a set of latitude longitude coordinates?
thanks!
This is what i tried so far:
[out:json][timeout:25];
(way(around:1.0,52.004940, 4.369381));
(._;>;);
out tags;
But there are 2 problems here.
1. I get a list of different nodes and ways. But i actually only want the way where there is a speed limit given
2. I don't know how to write a query for a whole list of coordinates. Not sure if this is even possible.

Here's how the query should look like to return ways with maxspeed tags at a given location with 1m radius:
way[maxspeed](around:1.0,52.004940, 4.369381);
out tags;

Related

Checking if a Coordinate is Within a Range - BigQuery GIS

I'm looking at the freely available Solar potential dataset on Google BigQuery that may be found here: https://bigquery.cloud.google.com/table/bigquery-public-data:sunroof_solar.solar_potential_by_censustract?pli=1&tab=schema
Each record on the table has the following border definitions:
lat_max - maximum latitude for that region
lat_min - minimum latitude for that region
lng_max - maximum longitude for that region
lng_min - minimum longitude for that region
Now I have a coordinate (lat/lng pair) and I would like to query to see whether or not that coordinate is within the above range. How do I do that with BQ Standard SQL?
I've seen the Geo Functions here: https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions
But I'm still not sure how to write this query.
Thanks!
Assuming the points are just latitude and longitude as numbers, why can't you just do a standard numerical comparison?
Note: The first link doesn't work without a google account, so I can't see the data.
But if you want to become spatial, I'd suggest you're going to need to take the border coordinates that you have and turn them into a polygon using one of: ST_MAKEPOLYGON, ST_GEOGFROMGEOJSON, or ST_GEOGFROMTEXT. Then create a point using the coords you wish to test ST_MAKEPOINT.
Now you have two geographies you can compare them both using ST_INTERSECTION or ST_DISJOINT depending on what outcome you want.
If you want to get fancy and see how far aware from the border you are (which I guess means more efficient?) you can use ST_DISTANCE.
Agree with Jonathan, just checking if each of the lat/lon value is within the bounds is simplest way to achieve it (unless there are any issues around antimeridian, but most likely you can just ignore them).
If you do want to use Geography objects for that, you can construct Geography objects for these rectangles, using
ST_MakePolygon(ST_MakeLine(
[ST_GeogPoint(lon_min, lat_min), ST_GeogPoint(lon_max, lat_min),
ST_GeogPoint(lon_max, lat_max), ST_GeogPoint(lon_min, lat_max),
ST_GeogPoint(lon_min, lat_min)]))
And then check if the point is within particular rectangle using
ST_Intersects(ST_GeogPoint(lon, lat), <polygon-above>)
But it will likely be slower and would not provide any benefit for this particular case.

A better way to handle Long Lat distances

OK so I don't have an issue here but I'm just wondering if there's a more standardized way to handle what I'm doing.
Essentially I have a DB table full of locations including longitude and Latitude, there could potentially be thousands of locations. I also have some functionality to search your postcode and you can then see from the stored the locations the closest x amount to you.
Ive read about going off and using the Google Maps api to do this but I don't really want to pull back and send thousands of requests to the google maps api.
So here's what I'm doing. I have a stored procedure where I am passing the users Long and Lat. I am then using this to form a column called distance with which I am then ordering the data. The distance column I am working out using the below logic:
SQRT(SQUARE((CAST(USERSLAT AS decimal(9,6))) - Latitude) + SQUARE((CAST(USERSLONG AS decimal(9,6)))-(Longitude))) AS Distance
Essentially what this is doing is the classic a^2=b^2+c^2 to find the distance between to coords, and then using these results I can theoretically see the closest locations to the user. Once I have this data i can use the google maps api to find the exact distances. Is this an ok way to do things? I have this nagging feeling in the back of my head that im missing something.

CoreData + Magical Record running select query

I have an application with a sqlite database that contains 7000+ records in it with city names, longitudes and latitudes.. also these "cities" are connected to relevant city fields on the database too.
What my app doing is, query the current location with core location, fetch the lon and lat values, and then find the closest location from the database.
The result doesn't have to be super accurate (i just want to match cities), so I want to use Hypotenuse formula for finding the closest point:
closest city in db: min((x1-x2)^2 +(y1-y2)^2)^(1/2)
x1, y1: lon and lat for user
x2, y2: lon and lat for points in database.
If I was using ms-sql or sqlite database, I could easily create a query but when it comes to core data, I'm out of ideas.
I don't want to fetch all the data (and fill the memory) then aggregate this formula on all fields so is there a way to create a query and get the result from the db?
Am I overthinking this problem, and missing a simple solution?
If I'm understanding your problem correctly, you're wanting to find the closest "n" cities to your current location.
I had something similar and here's how I approached it.
In essence, you probably need to take each city's lat/lon and hash it into some index. We use a Mercator Projection to convert the lat/lon to x/y, then hash that value in a manner similar to how Google/Bing/Apple Maps hash their map tiles. Fortunately, MapKit has a built-in Mercator Projection function.
In pseudocode:
for each city's lat/lon {
CLLocationCoordinate2D coordinate = (CLLocationCoordinate2D){lat, lon};
MKMapPoint point = MKMapPointForCoordinate(coordinate);
//256 represents the size of a map tile at zoomLevel 20. You can use whatever zoomLevel
//you want here, but we need something to quickly lookup close-by cities.
//this is the formula you can use to determine how granular your index is
//(256 * pow(2, (20 - zoomLevel)))
NSInteger x = point.x/256.0;
NSInteger y = point.y/256.0;
save x & y in a CityHashIndex table
}
Now, you get the current location's lat/lon, hash that into the index as above, and just simply write a query against this CityHashIndex table.
So say that, for simplicity sake, you're current location is indexed at 1000, 1000. So to find close by cities, maybe you search for cities with indexes in the range of `900-1100, 900-1100'.
From there, you're now only pulling in a much smaller set of cities and the memory requirements to process your Hypotenuse Formula isn't so bad.
I can elaborate more if you're interested.
This is directly related to a commonly asked question about Core Data.
Searching for surrounding suburbs based on latitude & longitude using Objective C
Calculate a bounding box around the point you need (min lat/long max lat/long) then use an NSPredicate against those values to find everything within the box. From there you can do a distance calculation on the results that return and sort them.
I would suggest setting this up so that it can search at multiple distances then you can see if a city is within 10 miles, 100 miles, etc. Slowly increasing the bounding box until you get one or more results back.
I would use NSPredicate to define my search criteria it will act as a filter. I'm not sure how optimized is this and if it will pull all your registers but I'm assuming that coreData has some kind of indexing mechanism that will optimize the search.
You can take a look of this document
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/Articles/cdFetching.html
Check the section named
Retrieving Specific Objects

Why does Foursquare search not return venues closest to my specified location?

I'm noticing something odd with foursquare search API. When I specify a latitude and longitude of a location in my city, I'm not getting venues that are closest to me.
For search parameters I'm using:
ll = 47.620918,-122.318455 (a neighborhood in Seattle, WA)
intent = browse
radius = 48 280 (approx 30 miles)
categoryId = 4d4b7105d754a06374d81259 (food), 4d4b7105d754a06376d81259 (nightlife)
venues/search?ll=47.620918,-122.318455&intent=browse&radius=42820&categoryId=4d4b7105d754a06374d81259,4d4b7105d754a06376d81259
I would expect this query to return me venues that are closest to the specified lat+long location and in the food or nightlife categories. This isn't what I'm seeing. Instead, the first venue in the array is a venue that is 768 meters away, the second is 2162 meters, the third is 722 meters.
There are food and nightlife venues that are much closer than 700 meters to that latitude and longitude.
One could argue that I should take the results and sort them myself based on the distance attribute but this seems flawed for 2 reasons:
If the venue list being returned isn't closest to my location, I'm missing out on a lot of venues since they couldn't all fit within the max limit of the query results. So even if I sorted based on distance attribute, I'm only sorting venues that shouldn't be considered nearby.
The reason I specify a lat+long to the search API is to have foursquare do the heavy lifting for me on what is "nearby". If I need to sort then what's the point? There's an argument to be made that foursquare shouldn't return venues that are more relevant to you, but this is why I'm using intent=browse instead of intent=checkin'
For intent=browse, the docs say:
Find venues within a given area. Unlike the checkin intent, browse searches an entire region instead of only finding Venues closest to a point.
what am I doing wrong such that I'm not getting the closest venues return to the specified lat+long?
Just like the docs say, when you use intent=browse, Foursquare doesn't "only [find] Venues closest to a point." When you use intent=browse with a ll/radius, imagine this as setting up a region and asking Foursquare for the "best" results from this region. It is not saying "find me the results starting at this ll growing until the radius."
In general, Foursquare search does not guarantee results in any particular order unless it's specified under the description for the intent, and unfortunately none of these specify that the results will be returned sorted by increasing radius.
I know this is a old thread, just wanted to let people know that you can use sortByDistance=1 as parameter to sort venues the closest to the location.

Foursquare Venue API & Number of Results

Is it possible to get more than 50 results from the Foursquare Venues API? (https://developer.foursquare.com/docs/venues/search.html)
The default limit is 50, but it does not make any mention of pagination or offset to get additional listings.
Please advise.
As answered here
The API docs here can help.
Foursquare searching is very closely linked to the location 'point' (the 'll' param on the query) that you provide. The simple answer is that to find more venues within a given area, you need to simply query again with a different location 'point' within that area.
Two queries, both at points close to one another:
https://api.foursquare.com/v2/venues/search?ll=40.700,-74.000&limit=50
https://api.foursquare.com/v2/venues/search?ll=40.705,-74.005&limit=50
will get you two different sets of venues (that may overlap, depending on how close the points are).
The default intent for the search method is 'checkin', which will return the 50 most popular locations closest to that point. If instead you want to look at all the venues within an area, you can use the 'browse' intent. This takes either a 'radius' parameter, in which case it returns venues inside a circle around the given point with the given radius, or it takes two coordinates representing the 'sw' and 'ne' corners of a rectangle. So, you could do:
https://api.foursquare.com/v2/venues/search?ll=40.705,-74.005&limit=50&intent=browse&radius=50
which will give you 50 venues within the 50m circle around that point. A smaller radius will reduce the number of venues returned. So, by varying the radius and the point at which you search (or the size and position of the rectangle described by the 'sw' and 'ne' parameters), you can get more venues returned.
Hope that helps.
For the record, Foursquare now offers a pagination parameter in their API request:
"offset - Used to page through results."
https://developer.foursquare.com/docs/venues/explore