Get the list of cities, suburbs with relations from Overpass-turbo - openstreetmap

I'm struggling to build a mini database set for with the following structure
{countryId, governorateId, cityId}
The idea is:
I need to find all admin_level=4 for Egypt, then for each result, get the cities|suburb|town
Example:
Cairo: ['Nasr City', 'Fifth Sattelment',...etc.]
Where Cairo = Governorate, 'Nasr City' = Suburb
What i have so far:
[out:csv(::id, 'place', 'name:ar', 'name:en')][timeout:25];
// fetch area “Egypt” to search in
{{geocodeArea:Egypt}}->.searchArea;
// gather results
(
node[place~"city|town|suburb"](area.searchArea);
);
// print results
out body;
>;
out skel qt;
which gives me the list, but without relations, so i have no clue which suburb is inside which city

When you write that query without filtering the columns it should return it will return a node like such:
<node id="21320911" lat="-33.9783333" lon="25.5874001">
<tag k="is_in" v="Port Elizabeth,Eastern Cape, South Africa"/>
<tag k="name" v="Walmer"/>
<tag k="place" v="suburb"/>
<tag k="sagns_id" v="62090"/>
<tag k="source" v="sagns"/>
<tag k="wikidata" v="Q61356595"/>
</node>
So, to extract the relations you can add the "is_in" column to the query so that it can look something like so...
[out:csv(::id, 'name', 'is_in', 'place')][timeout:25];
// fetch area “South Africa” to search in
{{geocodeArea:South Africa}}->.searchArea;
// gather results
(
node[place~"city|town|suburb|street"](area.searchArea);
);
// print results
out body;
>;
out skel qt;
and that should show your suburb and the city including the country. Eg:
#id name is_in place
21320910 Newton Park "Port Elizabeth, Eastern Cape, South Africa" suburb
21320911 Walmer "Eastern Cape, South Africa" suburb
21320912 Mill Park "Eastern Cape, South Africa" suburb
On my result set, it sometimes returns the city and sometimes doesn't...Hopefully this helps out.

Related

Overpass-turbo: add city name to a specific node

I'm requesting some drinking_water nodes by id:
node(id:1560728638,
1560728638,
1835271176,
1844271135
); out body;
I'd like to request the name of the city where the nodes are, for example:
osm_id
city
1560728638
city A
1560728638
city A
1835271176
city B
1844271135
city C
Is it possible?
In your case, the nodes already have a city tag: "addr:city"
You can ask and search question about overpass, OSM and various geographic queries on gis.stackexchange.com, it might be more focused that here.
Anyway, you can run the following query on overpass turbo:
// output to .csv file, with columns
[out:csv(::type,::id,amenity, name, "addr:city")];
// list of nodes
node(id:1560728638,
1560728638,
1835271176,
1844271135
);
//for each node:
// print the node,
// then get the surrounding (is_in),
// filter that for cities (admin_level 8),
// and return they city
foreach->.d(
.d out;
.d is_in;
area._[admin_level~"[8]"];
out;
);
So you get a list of your original nodes (in a different order), and the city they're in.
They you can just extract the data from the file o put in in the format you want:
#type
#id
amenity
name
addr:city
node
1835271176
drinking_water
Privas
area
3600087515
Privas
node
1560728638
drinking_water
Privas
area
3600087515
Privas
node
1844271135
drinking_water
Saint-Etienne-de-Serre
area
3602084772
Saint-Étienne-de-Serre

I need to extract street name and corresponding area name data from OSM using overpass-turbo

I'm using overpass-turbo to extract street names data from OSM. Here's the code I've been using:
[out:csv ("name")][timeout:2500];
{{geocodeArea:Ouagadougou}}->.searchArea;
(
way["highway"]["name"](area.searchArea);
);
for (t["name"])
{
make street name=_.val;
out;
}
How should I modify the code so the output is street names with the corresponding area name?
[out:csv ("name")][timeout:2500];
{{geocodeArea:Ouagadougou}}->.searchArea;
(
way["highway"]["name"](area.searchArea);
);
for (t["name"])
{
make street name=_.val;
out;
}
Output is street names only.

Flutter how to get province and cities?

I am searching for plugin from which I can get province and cities for one country only. Mean I dont want to select country.
I have found this plugin which is good but issue is its asking for country pick.
https://pub.dev/packages/restcountries
From the examples at this link
List cities = await api.getCities(
countryCode: 'id', region: 'Jawa Timur', keyword: 'mal');
Since you already know which country you want to get the cities from, just assign that country's code to countryCode,
For example, if you want cities of United States with keyword ar,
List<City> cities = await api.getCities(
countryCode: 'us', keyword: 'ar');
I have to agree with the above answer. Given a County you could make a series of calls to get the data set you want.
countries = await api.getCountries(); -- Will return the countries the service has, then search through the list to find the one you want.
regions = await api.getRegions(countryCode: 'id'); -- Will then get you the regions for the country, I'm assuming you'll get the code from the first call, otherwise a good place to start with the code would be to use the the IEEE country codes.
Check Them Out Here
Finally use the regions you got to get the cities;
await api.getCities(countryCode: 'id', region: 'Jawa Timur');
Bringing it all together you'd have something like this... (I have not looked at the API specification so the guess at a memeber in that loop "region.name" is likely incorrect)
import 'package:restcountries/restcountries.dart';
void main() async {
var api = RestCountries.setup(Platform.environment['API_KEY']);
List<Country> countries;
List<Region> regions;
List<City> cities;
countries = await api.getCountries();
// Search here for your country
regions = await api.getRegions(countryCode: '*YOUR COUNTRY CODE HERE*');
// Now we loop to get cities in every region.
regions.forEach((region){
cities += await api.getCities(countryCode: '*YOUR COUNTRY CODE HERE*', region: region.name);
});
print(regions);
print(cities);
}

How to get shape country (without maritime limit...only terrain) in Overpass?

I am trying to get the shape of country in Overpass API without the maritime limit in http://overpass-turbo.eu
And I have this query but it shows the maritime:
relation
["boundary"="administrative"]
["admin_level"="2"]
["name:en"="Spain"];
(._;>;);
out body;
I found it, thanks to OpenStreetmap spanish mailing list and the doc (it is in spanish) https://iceosm2016.readthedocs.io/en/latest/ .
area["name"="España"]->.country;
rel["name"="España"]["type"="boundary"]["admin_level"="2"];
(
way(r)["maritime" != "yes"]({{bbox}});
way(area.country)["natural"="coastline"]({{bbox}});
);
out geom;
You could try to use a dedicated relation for Península ibérica instead:
relation
["wikidata"="Q12837"];
(._;>;);
out body;

Force query to match more than one attribute

I have an index that includes these attributes: Name, Address, City, State, Zip
I want to do a allOptional search but I don't want city, state, or zip to match without name or address also matching. So a search query of McDonalds would match all McDonalds in every city/state, McDonalds Chicago would return all McDonalds in Chicago and McDonalds 60007 would return all McDonalds in the zip code 60007.
But a search query of Chicago or Chicago IL would return 0 results.
I've been reading the filters and facets documentation and I think this should be possible with a filter but I can't seem to figure out how.
You can solve this issue by post processing results after you have received them, before rendering them.
You can use the _highlightResult data in the hits response to filter out hits in which the query isn't matched in certain attributes.
For instance to remove hits where the query isn't matched in either the name or address attribute:
var displayedResults = response.hits.filter(hit => {
return hit._highlightResult.name.matchLevel !== 'none' || hit._highlightResult.address.matchLevel !== 'none';
});