overpass-turbo Limit to State? - openstreetmap

I am trying to export all admin_level=6 using OverpassAPI.
However I am noticing a small issue as I can't seem to only show results for 1 state.
Take NT, Australia it's quite small width wise and the map view when I query it seems to grab some results for WA, QLD as well as NT.
Is there anyway to limit to a state?
Query
/*
This has been generated by the overpass-turbo wizard.
The original search was:
“city”
*/
[out:json][timeout:25];
// gather results
(
// query part for: “city”
node["admin_level" = "6"]({{bbox}});
way["admin_level" = "6"]({{bbox}});
relation["admin_level" = "6"]({{bbox}});
);
// print results
out body;
>;
out skel qt;
End result
When you zoom out it shows

You can skip bbox and add area filter. Search all supermarkets in NT:
[out:json][timeout:25];
area["state_code"="NT"]["is_in:country_code"="AU"]->.boundaryarea;
(
nwr["shop"="supermarket"](area.boundaryarea);
);
out meta;
>;
out skel qt;

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;

Query from 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.

How to retrieve all airports around a given osm-ID

I want to retrieve all airports around a city (g.e. Leipzig) within a radius of 50km.
I tried this
[out:csv(::type,name, 'name', ::id; true; ";")];
(
relation["iata"~".*"](around: 50000, 51.3124404, 12.4131075);
node["iata"~".*"](around: 50000, 51.3124404, 12.4131075);
way["iata"~".*"](around: 50000, 51.3124404, 12.4131075);
);
out;
returns
#type;name;name;#id
way;Flughafen Leipzig/Halle;Flughafen Leipzig/Halle;435715317
relation;Leipzig-Altenburg Airport;Leipzig-Altenburg Airport;6116338
But I want to use the osm-id directly.
When I search within Leipzig (admin_level = 8) and a radius
[out:csv(::type,name, 'name', ::id; true; ";")];
area(3600062649) -> .leipzig;
way(around.leipzig:50000)[iata~".*"]({{bbox}});
out;
I retrieve an empty result set
When I search within saxony (admin_level = 4)
area(3600062467) -> .sachsen;
way(area.sachsen)[iata~".*"]({{bbox}});
out;
then I retrieve
#type;name;name;#id
way;Flughafen Leipzig/Halle;Flughafen Leipzig/Halle;435715317
I want to retrieve the same result like I use the lat/lon-information.
Edit:
I get the expected result by retriving the center-lat/lon of a relation (given by an osm-id) and use this lat/lon-information to retrieve all airports within a given radius.
Now I want to skip the step "retrieve center-lat/lon". I want to use the osm-id of a relation and a given radius directly to retrieve all airports within a given radius.
#mmd: I hope it's more understandable.

Missing data for geojson

I made the following query in overpass-turbo
[out:json][timeout:25];
// gather results
(
// query part for: “amenity=hospital”
node["amenity"="hospital"]({{bbox}});
way["amenity"="hospital"]({{bbox}});
relation["amenity"="hospital"]({{bbox}});
);
// print results
out body;
>;
out center;
>;
but unfortunately i do not get all the nodes displayed into geojson.io from extracted geojson data (overpass-turbo).
Any idea that could help me to get all data?
Regards
It looks like http://geojson.io does show nodes but not polygons (= OSM ways). This could be a limitation of http://geojson.io or of the overpass turbo export, I'm not really familiar with the GeoJSON file format.
You can tell overpass to convert ways to nodes with the geometry attribute out center;. Try the following query:
[out:json][timeout:25];
// gather results
(
// query part for: “amenity=hospital”
node["amenity"="hospital"]({{bbox}});
way["amenity"="hospital"]({{bbox}});
relation["amenity"="hospital"]({{bbox}});
);
// print results
out center;
>;

mark specific dataset in filtered grid

i'm just struggling through the following situation -
there's a datasource added to a grid in axapta 2009, filtered by a querybuildrange.
i want to mark a specific dataset by x++ via
datasource_DS.findrecord( specificRecord )
this works as intended, removing the filter, but not having the filter active!
a workaround to remove the filter and add everything ( filtered! )to a temporary table first is not what i want.
i can't imagine there's no way to achieve this task?!
thanks in advance!
edit:
datasources on form:
- ProdRouteJob ( JoinSource: ProdTable, LinkType: InnerJoin )
- ProdTable
only datasets containing a specified ProdStatus should be displayed in the grid.
This is done by the mentioned Range, e.g.:
prodStatusRange = prodTable_ds.query().dataSourceTable( tablenum( ProdTable )).addRange( fieldnum( ProdTable, ProdStatus ));
prodStatusRange.value( "(( ProdStatus == 0) || ( ProdStatus == 1 ))" );
selecting a specified dataset is done by, e.g.:
ProdRouteJob currentProdRouteJob;
;
currentProdRouteJob = ProdRouteJob::findJobId( "JOB_12345" );
info ( currentProdRouteJob.JobId );
prodRouteJob_DS.findRecord( currentProdRouteJob );
the info-function shows the correct JobId.
if i remove the filter, findRecord() selects the dataset, if not - not.
adding the DS.research( true ); does not change this behaviour.
You objective is to redraw the grid and to retain any filtering.
In AX 2009 it is easy:
datasource_DS.research(true);
In AX 4.0 and previous you can research and then refind:
specificRecord = datasource.data();
datasource_DS.research();
datasource_DS.findRecord(specificRecord)
This can sometimes be slow if there are many records in the grid.