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

Hi, I would like to use the OSM data in my application but I'm not sure if it is feasible in an easy way.

I need to extract country bounding boxes. My use case looks like: user sends his coordinate to my app and the app should return a country name where the user is. The app must run in offline mode, so it's not possible to send request to the OSM. I know that bounding boxes do not give me very good accuracy, but I think it should be enough, because it's a trade off between accuracy and performance. If you have any hints or advices for me, I would be very grateful.

So my question is: Is it possible in an easy way to extract from the OSM country bounding boxes as a set of boxes for each country (including islands and other country areas)?

asked 28 Aug '14, 08:08

ChrisOPL's gravatar image

ChrisOPL
31113
accept rate: 0%

[meta] Why am I not able to convert this answer to a comment to the first answer?? On other threads its works for me here!

(01 Oct '14, 17:00) stephan75
3

@stephan75 Unfortunately OSQA has been updated recently and is now full of bugs ;( Converting answers to comments doesn't always work anymore.

(02 Oct '14, 07:47) scai ♦

This site https://wambachers-osm.website/boundaries/ allows you to download all boundaries (countries, but also other admin levels) in a variety of formats. Is that what you are looking for ? Data is extracted from OSM.

permanent link

answered 01 Oct '14, 16:58

escada's gravatar image

escada
19.0k16166302
accept rate: 21%

edited 05 Jul '17, 08:10

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273

1

yes, it looks good for me. Thank you very much!

(02 Oct '14, 16:38) ChrisOPL

Nominatim returns the bounding box for relations in its XML output, for instance http://nominatim.openstreetmap.org/search?q=United+Kingdom&format=xml. You can make sure you’ve got the relation for the country as it will be tagged as class="boundary" type="administrative".

permanent link

answered 28 Aug '14, 22:31

Wynndale's gravatar image

Wynndale
5651515
accept rate: 7%

Thanks for the answer. You assumed that I have a country name. Unfortunately I'm looking for a solution where I have boundaries for all countries. It means that I need to extract all boundaries, because in my app I have to check if a user coordinate is inside a country.

One more thing here is that "United+Kingdom" query doesn't return for example islands of the UK.

(29 Aug '14, 16:20) ChrisOPL

Does anyone know other solution than Wynndale wrote above? I tried to use data from http://www.naturalearthdata.com/ but it is not good enough for me (e.g. there are missing islands).

permanent link

answered 01 Oct '14, 08:34

ChrisOPL's gravatar image

ChrisOPL
31113
accept rate: 0%

edited 01 Oct '14, 08:38

You can go to your database directly and query for country polygons like so

SELECT name->'name' as name, geometry 
FROM placex 
WHERE class='boundary' AND type='administrative' AND admin_level=2;

(This query will run for a while, add "LIMIT 5" or so to test it without waiting.)

This query returns multipolygons for the countries, but you could further refine the query to use something like

SELECT ... st_astext(st_envelope((st_dump(geometry)).geom)

which would then give you a series of bounding boxes for each country.

permanent link

answered 13 Oct '16, 09:33

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273
accept rate: 23%

edited 13 Oct '16, 09:33

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
×58
×30

question asked: 28 Aug '14, 08:08

question was seen: 13,079 times

last updated: 05 Jul '17, 08:10

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