Query from OpenStreetMap - openstreetmap

At the moment I'm using the Overpass API to query from OpenStreetMap using https://overpass-turbo.eu/ but when I use the following code, not all the schools in the area appear on the map (e.g. Holy Cross College doesn't appear).
area[name = "Council of the City of Ryde"];
node(area)[amenity = school];
out;
Anyone know why this might be the case?
Thanks for any help!

OpenStreetMap data consists of three basic elements: nodes, ways and relations. Your query searches only for nodes. Some schools will be mapped as ways and a few others as relations.
You have to change your query in order to search for all three elements:
area[name = "Council of the City of Ryde"];
(
node(area)[amenity = school];
way(area)[amenity = school];
relation(area)[amenity = school];
);
out;
Alternatively just use the keyword nwr to search for all three elements:
area[name = "Council of the City of Ryde"];
nwr(area)[amenity = school];
out;
If there are still missing schools then either they are mapped with a different tag or they are missing in OSM. In the second case feel free to add them yourself.

Related

Overpass API: query for counting amenity of specified type around set of lat lons

I'm trying to query data from the OSM Overpass API. Specifically I'm trying to determine the count of amenities of a given type around a point (using the 'around' syntax). When running this for many locations (lat, lons) I'm running into a TooManyRequests error.
I have tried to work around by setting sleep time pauses and playing with the timeout header and retry time, but I'm running into the same issue. I'm trying to find a way to adapt the query so that it just returns the count of amenities (of specified type) around each point, rather than the full json of nodes which is more data intensive. My current script is as follows;
# Running Overpass query for each point
results = {}
for n in range(0, 200):
name = df.loc[n]['city']
state = df.loc[n]['state_name']
rad = df.loc[n]['radius_m']
lat = df.loc[n]['lat']
lon = df.loc[n]['lng']
# Overpass query for amenities
start_time = time.time()
api = overpy.Overpass(max_retry_count=None, retry_timeout=2)
r = api.query(f"""
[out:json][timeout:180];
(node["amenity"="charging_station"](around:{rad}, {lat}, {lon});
);
out;
""")
print("query time for "+str(name)+", number "+str(n)+" = "+str(time.time() - start_time))
results[name] = len(r.nodes)
time.sleep(2)
Any help is much appreciated from other Overpass users!
Thanks
In general, you can run out count; to return a count from an overpass API query.
It's hard to say without knowing how your data is specifically structured, but you might have better luck using area to look at specific cities, or regions.
Here is an example that returns the count of all nodes tagged as charging station in Portland, Oregon:
/* charging stations in portland */
area[name="Oregon"]->.state;
area[name="Portland"]->.city;
(
node["amenity"="charging_station"](area.state)(area.city);
);
out count;

Google Places Search AutoComplete filter results by Country in Swift 4

I am trying to filter the results from the API (Google Places) country wise.
I am aware I can do it, using code such as this:
let filter = GMSAutocompleteFilter()
filter.type = .establishment
filter.country = "SG"
SG is for Singapore but the thing is, where shall I place the code so that the results are filtered as per the country?

OrientDB create edge between two nodes with the same day of year

I'm interested in creating an edge (u,v) between two nodes of the same class in a graph if they share the same day of year and v.year = u.year+1.
Say I have vertices.csv:
id,date
A,2014-01-02
B,2015-01-02
C,2016-01-02
D,2013-06-01
E,2014-06-01
F,2016-06-01
The edge structure I'd like to see would be this:
A --> B --> C
D --> E
F
Let's set the vertex class to be "myVertex" and edge class to be "myEdge"? Is it possible to generate these edges using the SQL interface?
Based on this question, I started trying something like this:
BEGIN
LET source = SELECT FROM myVertex
LET target = SELECT from myVertex
LET edge = CREATE EDGE myEdge
FROM $source
TO (SELECT FROM $target WHERE $source.date.format('MM-dd') = $target.date.format('MM-dd')
AND $source.date.format('yyyy').asInteger() = $target.date.format('yyyy').asInteger()-1)
COMMIT
Unfortunately, this isn't correct. So I got less ambitious and wanted to see if I can create edges just based on matching day-of-year:
BEGIN
LET source = SELECT FROM myVertex
LET target = SELECT from myVertex
LET edge = CREATE EDGE myEdge FROM $source TO (SELECT FROM $target WHERE $source.date.format('MM-dd') = $target.date.format('MM-dd'))
COMMIT
Which still has errors... I'm sure it's something pretty simple to an experienced OrientDB user.
I thought about putting together a JavaScript function like Michela suggested on this question, but I'd prefer to stick to using the SQL commands as much as possible for now.
Help is greatly appreciated.
Other Stack Overflow References
How to print or log on function javascript OrientDB
I tried with OSQL batch but I think that you can't get what you want.
With whis OSQL batch
begin
let a = select #rid, $a1 as toAdd from test let $a1 = (select from test where date.format("MM") == $parent.$current.date.format("MM") and date.format("dd") == $parent.$current.date.format("dd") and #rid<>$parent.$current.#rid and date.format("yyyy") == sum($parent.$current.date.format("yyyy").asInteger(),1))
commit
return $a
I got this
but the problem is that when you create the edge you can not cycle on the table obtained in the previous step.
I think the best solution is to use an JS server-side function.
Hope it helps.

How can I access an attribute of a selected parameter in Tableau?

I have a list of Companies with a ROIC measure. Each Company belongs to a Segment.
I created a parameter to select a Company: [SelectedCompany], and I want to create a SET which includes all the companies except the [SelectedCompany], which are in the same [Segment] as [SelectedCompany].
My set is currently defined by this formula:
[Company] != [SelectedCompany]
I should add something like:
[Company] != [SelectedCompany]
AND
[Segment] = [SelectedCompany].[Segment]
But I don't know how to access the [Segment] attribute of the [SelectedCompany].
Just for clarification, I'm making this because I want to compare the [SelectedCompany] ROIC against the average ROIC of the other Companies in the same Segment.
I would appreciate any help on this.
Thanks a lot!
Here's a bit of a hacky way to get what you're looking for. Keep your original definition for the set:
[Company] != [SelectedCompany]
Create a calculated field:
{ FIXED [Segment] : MAX( IIF([Company] = [Parameters].[SelectedCompany], 1, 0) ) }
Then drag that field into the Filters card and filter to allow only 1's. This will filter out all Segments except for the selected company's Segment.

MongoDB geoNear multiple coordinates

I want to order my results based on their proximity to MULTIPLE points in a 2D space.
I assume this would be done by querying against the first point and then re-querying/checking those results against the second point?
Maybe the code below explains what I am trying to achieve a bit better?
db.runCommand({
geoNear:"places",
near:[ [52.5243, 13.4063], [48.1448, 11.5580] ]
})
Solution: Incase anyone is interested, this is how I achieved this (thanks to the answer below)
a = Trip.geo_near([52.5243, 13.4063], :max_distance => 40, :unit => :mi).uniq
b = Trip.geo_near([48.1448, 11.5580], :max_distance => 40, :unit => :mi).uniq
#results = a & b
MongoDB has a whole section in their documentation on Geospacial indexing. http://www.mongodb.org/display/DOCS/Geospatial+Indexing
I think what you're looking for is a bounding box query. This is directly from their code examples.
box = [[40.73083, -73.99756], [40.741404, -73.988135]]
db.places.find({"loc" : {"$within" : {"$box" : box}}})
What do you intend the query above to return? Places that are near one OR the other location? In that case, you should run two queries, then union the results in your application code.