osm overpass query by country - openstreetmap

I am using this Overpass query to extract all coworking amenities in Italy.
( area["ISO3166-1"="IT"];) ->.a;
node["amenity"="coworking_space"]
(area.a);
(._;>;);
out body;
If I try to do the same for France using FR as ISO3166 country code
( area["ISO3166-1"="FR"];) ->.a;
node["amenity"="coworking_space"]
(area.a);
(._;>;);
out body;
I get no results while I am sure there are nodes like that in France (i tested with a separate query using automatic bbox).
Question:
Am I getting wrong the ISO3166 country code of France?
In general, there is a better way to extract osm data from overpass by country?
Thanks,
Jacopo

You should query for the key ISO3166-1:alpha2 or ISO3166-1:alpha3 and use ISO3166-1 only as a fallback. These keys are explained in the country code wiki page.
The relation for the state of Italy has tag ISO3166-1 while the relation for the state of France doesn't. But both have the value you are looking for in the ISO3166-1:alpha2 key.

Related

For `America`, why doesn't OpenStreetmap return the country `USA` at all? How to add such an alias to the Nominatim server?

As per title,
I do not understand why searching for America does not return the country USA at all, even up to the top 50 results.
What can I do to change this (I think we should return the country USA at least within the top 30 results)? Is there some alias I can add to the database?
Openstreetmap API: https://www.openstreetmap.org/search?query=america
Nominatim search API: https://nominatim.openstreetmap.org/search?q=america&format=jsonv2&addressdetails=1&namedetails=1&dedupe=1&extratags=1&limit=50
This is because so far no one thought about "America" as an alternative name for the United States of America in English. E.g. you got the colloquial name "Amerika" added for some languages as a place name or alternative name, but so far not "America".
So if you do think that "America" is used in English as an alternative for the USA, you might add the alt_name:en=America tag to this relation:
https://www.openstreetmap.org/relation/148838

How to filter house numbers of a city in OSM map

Does anyone have any documentation or know how to get all the house numbers of a city available on OpenStreetMap or Nominatim?
I've searched some documentation but it doesn't seem to work.
Or anyone have api documentation that can do it please help me.
Thanks,
There's no direct API for this that would just spit out all the addresses, or even just all the house numbers, for a specific city, at least not that I'd know off.
If you can import an OSM planet extract containing your city of choice into an osm2pgsql database it would be easy to run:
SELECT DISTINCT "addr:housenumber"
FROM planet_osm_point
WHERE "addr:city=..."
UNION
SELECT DISTINCT "addr:housenumber"
FROM planet_osm_polygon
WHERE "addr:city=..."
Overpass API could also be used, esp. with the OverPass Turbo frontend it can be given queries like "addr:housenumber=* in City_name", but by default it will return full object data and not just a single field like house number.
Raw Overpass API queries can probably do just that, but I'm not that deep into its query syntax. Maybe the examples can give you a hint towards what may work.
But the Overpass API query language is not necessarily for those faint at heart ... :O

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;

OpenstreetMap Overpass API - Validate tag if present

I have this query
[out:json];
(
way['addr:street'='Kurzenmoor']['addr:housenumber'='12']['addr:postcode'='25370']['addr:country'='DE'];
node(around:700)['highway'='bus_stop'][!'ref'];
);
out;
This does not return a result due to the fact that the country has not been specified at the API.
This works:
[out:json];
(
way['addr:street'='Kurzenmoor']['addr:housenumber'='12']['addr:postcode'='25370'];
node(around:700)['highway'='bus_stop'][!'ref'];
);
out;
Is there a way to combine these? If there is no country present, I want the result, if there is a country present it should match the desired one (in this example "DE", if it matches, I want the result, otherwise I do not want it.
Overpass API is not a geocoder.
A better approach is to first determine the location via geocoding, e.g. by using Nominatim, Photon or one of the other OSM-based geocoders. In the second step use Overpass API to find bus stops near this location.

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.