NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

Hi ! I have 1000 cities that I want to make a list of bboxes, where they fit in then to generate tiles for them 1 by 1. The problem is that manually to find out and insert in system database the bboxes are very time consuming and annoying. Is there any API that I can find out the city bbox ??

Lets say with geonames.org I can find the center of map, but how to find appropriate bbox ???

Any ideas?

asked 09 Feb '13, 10:58

Gevork's gravatar image

Gevork
234121422
accept rate: 0%

You need to find the "city polygon", which may or may not be tagged as belonging to the city.

I think it is a very hard task to extract city bboxes from a OSM dataset. You could probably do this easier using some sort of national dataset provided by your national geographic agency.

(09 Feb '13, 20:06) gormo

You could extract the boundary=administrative areas for the cities you want with the Overpass API (or XAPI, but that has more limitations on use), convert the .osm file to a shapefile, then use ogr to extract the bounding box. In python, all you'd need would be something like the following, which you could then write to a new file. Note that many of the boundaries will be relations, but you can query for those too.

ds = ogr.Open("DatasourceName")
lyr = ds.GetLayerByName("LayerName")   
lyr.ResetReading()

feat = lyr.GetNextFeature()
while feat is not None:
    env = feat.GetGeometryRef().GetEnvelope()
    ## env returns  [0]=minX,[1]=maxX,[2]=minY,[3]=maxY
permanent link

answered 11 Feb '13, 14:55

neuhausr's gravatar image

neuhausr
7.5k870121
accept rate: 21%

Adding to @neuhausr's answer, here is an example Overpass query to return the bounding box of the AU-NSW admin boundary, then you can see the bounding box in the Data tab at https://overpass-turbo.eu/.

[out:json];
(
relation["ISO3166-2"="AU-NSW"][boundary=administrative];
);
out skel bb qt;
permanent link

answered 22 Dec '17, 01:49

aharvey's gravatar image

aharvey
5232913
accept rate: 21%

If you want to have boundingboxes for ceratin places, there is so far no other way to define them manually, because there is no such information in the OSM data about boundingboxes around cities or places.

BUT you can try to find boundary polygons for many cities that are stores in data relations within the OSM data.

Go to http://nominatim.openstreetmap.org and type in a name of a wanted place. If the result list gives back a place with this special icon: alt text ... then this can be the right boundary. Verify this by hand for some examples.

In theory, now you can create a boundingbox where the boundary polygon is fitting in. Maybe it is even possible to run Nominatim in a kind of batch modus and to create that bboxes automatically.

permanent link

answered 11 Feb '13, 11:53

stephan75's gravatar image

stephan75
12.6k556210
accept rate: 6%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×129
×30

question asked: 09 Feb '13, 10:58

question was seen: 12,127 times

last updated: 22 Dec '17, 01:49

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum