How to find all ways in an administrative area - openstreetmap

I would like to find all the streets in a suburb. I can find the boundary of the suburb with a query like:
[out:json][timeout:25];
(
relation["boundary"="administrative"]["name"="Crows Nest"](around: 250,-33.8255609,151.1992762);
);
out geom;
What I can't work out is how to use that as the bounding box / search area for streets (or if that should be possible). For example:
way (r) ["highway"~"^(primary|secondary|tertiary|residential)$"];
Doesn't work. Any suggestions?

By using an area, you can restrict the search for highway=* to a given administrative boundary:
area["boundary"="administrative"]["name"="Crows Nest"][wikidata="Q5189586"];
way(area)[highway];
out geom;
I'm using wikidata to make the area unique, because there's another area of that same name in the US.

Related

Use polygon as search area overpass api / overpass turbo

I'm fairly new at using overpass API, I finally managed to generate a query to retrieve all nodes within an area by using overpass-turbo wizard.
Using highway=* in "Paulino Navarro" in the wizard generates me the following query.
/*
This has been generated by the overpass-turbo wizard.
The original search was:
“highway=* in "Paulino Navarro"”
*/
[out:json][timeout:25];
// fetch area “Paulino Navarro” to search in
{{geocodeArea:Paulino Navarro}}->.searchArea;
// gather results
(
// query part for: “highway=*”
node["highway"](area.searchArea);
way["highway"](area.searchArea);
relation["highway"](area.searchArea);
);
// print results
out body;
>;
out skel qt;
However, how could I use a polygon as a search area? maybe something like highway=* in poly([lat,lon],[lat,lon],...,[lat,lon]) or how can I do that on the query itself.
I don't quite understand the documentation in overpass wiki nor overpass-turbo wizard.
The polygon filter is explained in the Overpass QL documentation.
Example:
[out:xml][timeout:30];
way[highway=primary](poly:"50.7 7.1 50.7 7.2 50.75 7.15");
(._;>;);
out;
If the polygon you want to query inside of is an OSM feature, you can also query using an area ID.
Area IDs are generated by the Overpass server to make querying data within existing polygons easier. You can determine the area ID for a way by adding 2400000000 to the way ID and the area ID for a relation by adding 3600000000 to the relation ID (assuming that the way or relation is a valid area feature).
Example:
[out:xml][timeout:30];
way[highway=primary](area:2400000001);
(._;>;);
out;

OSM Overpass: Query within relation

If I want to query for certain objects within an area, it's quite easy:
area(...);
node(area)[natural=peak];
out;
But what if the area is defined as a relation in the OSM database? I could query for the area like this ...
(rel(...);>;);
out;
... but how can I use the area filter on it then?
You can either apply the same filter criteria to area, as you would for your relation - or - use map_to_area to calculate the corresponding area for a relation:
rel(...);map_to_area;
node(area)[natural=peak];
out;
Check out the documentation for more details.

Overpass API way coordinates

I'm trying to query the OSM Overpass API to find any amenities within a bounding box. The actual query in my program will be generic but in my testing I noticed I cannot retrieve the coordinates(latitude, longitude) of any of the ways. Here is my script:
(
node
["amenity"="police"]
(39.235,-76.715,39.373,-76.525);
way
["amenity"="police"]
(39.235,-76.715,39.373,-76.525);
);
(._;>;);
out meta;
I need to use ways because I'm missing a significant amount of data without them. Unfortunately they do not include any coordinate data despite me adding out meta instead of the normal out. This was answered here, overpass-api ways query include coordinates about a year ago but that solution no longer works. Is this a bug? Or am I doing something wrong? I've also tried out center, out geom, and out skel to no success. I'm outputting the data in xml.
ANSWERED, I left on the recursion line on the end by accident. Thanks Tyr.

Getting Streets of a specific postcode using Open Street Maps

I want to write a code that has the Countrycode and Postcode as an input and the ouput are the streets that are in the given postcode using some apis that use GSM.
My tactic is as follows:
I need to get the relation Id of the district. For Example 1991416 is the relation id for the third district in Vienna - Austria. It's provided by the nominatim api: http://nominatim.openstreetmap.org/details.php?place_id=158947085
Put the id in this api url: http://polygons.openstreetmap.fr/get_wkt.py?id=1991416&params=0
After downloading the polygon I can put the gathered polygon in this query on the overpass api
(
way
(poly: "polygone data")
["highway"~"^(primary|secondary|tertiary|residential)$"]
["name"];
);
out geom;
And this gives me the streets of the searched district. My two problems with this solution are
1. that it takes quite a time, because asking three different APIs per request isn't that easy on ressources and
2. I don't know how to gather the relation Id from step one automatically. When I enter a Nominatim query like http:// nominatim.openstreetmap.org/search?format=json&country=austria&postalcode=1030 I just get various point in the district, but not the relation id of the searched district in order to get the desired polygone.
So my questions are if someone can tell my how I can get the relation_Id in order to do the mentioned workflow or if there is another, maybe better way to work this issue out.
Thank you for your help!
Best Regards
Daniel
You can simplify your approach quite a bit, down to a single Overpass API call, assuming you define some relevant tags to match the relation in question. In particular, you don't have to resort to using poly at all, i.e. there's no need to convert a relation to a list of lat/lon pairs. Nowadays the concept of an area can be used instead to query for certain objects in a polygon defined by a way or relation. Please check out the documentation for more details on areas.
To get the matching area for relation 1991416, I have used postal_code=1030 and boundary=administrative as filter criteria. Using that area you can then search for ways in this specific polygon:
//uncomment the following line, if you need csv output
//[out:csv(::id, ::type, name)];
//adjust area to your needs, filter critera are the same as for relations
area[postal_code=1030][boundary=administrative]->.a;
// Alternative: {{geocodeArea:name}} -> see
// http://wiki.openstreetmap.org/wiki/Overpass_turbo/Extended_Overpass_Queries
way(area.a)["highway"~"^(primary|secondary|tertiary|residential)$"]["name"];
(._;>;);out meta;
// just for checking if we're looking at the right area
rel(pivot.a);out geom;
Try it on overpass turbo link: http://overpass-turbo.eu/s/6uN
Note: not all ways/relations have a corresponding area, i.e. some area generation rules apply (see wiki page above). For your particular use case you should be ok, however.

An API to get a given city's area size?

I would like to find an API that would return a city's area in square feet, square miles, square meters or any area unit given only the city name.
For example, I query "san francisco" and I get something back like "231.89 sq mi or 600.6 km2".
I need this data for US and Canadian cities for now but it would be nice to have an API that covers any city in the world.
I'd rather avoid scraping wikipedia or any other website and use a proper API if at all possible.
You can use DBpedia to get this information. An example of a SPARQL query to get this information would be:
select ?area where { dbr:San_Francisco dbo:areaTotal ?area }