8

enter image description here

I'm really just looking to get borders for cities and regions around the world. Ideally in a shapefile format.

Does anyone know how I can do that from OpenStreetMap?

5
  • Using overpass queries you can extract specific elements from the openstreetnap database wiki.openstreetmap.org/wiki/Overpass_API
    – Hans Erren
    Commented May 17, 2019 at 21:29
  • 2
    overpass-turbo.eu/s/J7l (admin level 4) for New Delhi then use the export tab and save to GeoJSON this will load in QGIS and save as shapefile.
    – Mapperz
    Commented May 18, 2019 at 3:11
  • Actually, in the download data pack from Geofabrik, it doesn't include the boundary data
    – Bella Chen
    Commented Jan 25, 2022 at 4:11
  • Are you completely sure? Commented Jan 25, 2022 at 4:14
  • There is this tool now: osm-boundaries.com
    – four-eyes
    Commented Oct 13, 2022 at 17:58

2 Answers 2

7

If it's for specific cities and regions, you can use Overpass Turbo to create queries like admin_level=6 to find border ways. You'll want to consult the Tag:boundary=administrative wiki page to make sure that you're using the right admin level for the country you're looking at.

If, however, you want to just extract those borders for the whole planet, you'll need to download a local copy of the OSM database from https://planet.openstreetmap.org/, then use a tool like Osmosis to extract the particular objects you're looking for. In Osmosis, you'd need to use the --tag-filter command, among other things.

I don't personally have experience working with OSM data directly with GDAL, but it does have the capability of reading and filtering OSM files, which you can read about here. The added benefit of GDAL is that you can also use it in conjunction with ogr2ogr to export directly to shapefile.

Finally, perhaps you're really just looking for shapefiles of those boundaries, and don't want to fiddle around with these commands. In that case, you have a couple options.

  1. Download regions and countries individually from Geofabrik, which come as shapefiles. This is ill-advised, as the extracts will contain everything, and will require some work to filter out the boundaries and bring them all together from disparate layers. And that's not to mention that it would eat up a lot of storage space unnecessarily.

  2. You can always just go to an alternate source like Natural Earth, which provides global coverage of boundaries as shapefiles, among many other things.

If, for whatever reason, the data must come from OSM, then I would suggest getting familiar with GDAL and/or Osmosis.

1
1

It depends how many boundaries you would like to extract from OSM. For single city shape osmnx would be easiest option.

If you need to get admin boundaries for whole country, processing OSM data dump for country is the only viable option.

Here is a complete example in Python how to do it

https://medium.com/p/9f108c34f86

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.