Skip to main content

Generate administrative boundaries from OpenStreetMap via Overpass

Project description

99boundaries

PyPI version Python 3.10+ License: MIT

Indonesia Maritime and Land Boundaries

A simple command line utility to generate administrative boundaries from OpenStreetMap via Overpass and OSM Land Polygons.

Features

  • Generate maritime and land boundaries for any country
  • Multiple output formats: GeoJSON, ESRI Shapefile, GeoPackage, CSV (WKT), MapInfo, KML, FlatGeobuf, PostgreSQL dump
  • Batch processing for multiple countries at once
  • Uses OpenStreetMap data via Overpass API
  • High-quality land boundary generation with OSM land polygons

Installation

For Users

Install via pip:

pip install nintynine-boundaries

For Development

Please make sure you have installed poetry locally. Then clone this repository and run poetry install from the root folder.

To activate the virtual environment:

eval $(poetry env activate)

Prerequisites

  • Python 3.10 or higher
  • GDAL/GEOS libraries (installed automatically with geopandas on most systems)
  • Optional: OSM Land Polygons for generating land boundaries
    • Download the WGS84 split variant (~600MB) for faster processing
    • Unzip to a local directory and reference with --land_data_dir flag

Usage & Examples

make_boundary --help
usage: make_boundary [-h] -a ALPHA2 [ALPHA2 ...] -f FORMATS [FORMATS ...] [-l ADMIN_LEVEL] [-d LAND_DATA_DIR]
                     [--debug] [--no-debug]

required arguments:
  -a ALPHA2 [ALPHA2 ...], --alpha2 ALPHA2 [ALPHA2 ...]
                        List of ISO-3166-1 alpha2 country codes, e.g. ES FR DE
  -f FORMATS [FORMATS ...], --formats FORMATS [FORMATS ...]
                        Output formats, one or multiple of shp, gpkg, csv, geojson, mapinfo, kml, fgb, pgdump

optional arguments:
  -l ADMIN_LEVEL, --admin_level ADMIN_LEVEL
                        OSM administrative level, currently only level 2 supported. Read more at
                        https://wiki.openstreetmap.org/wiki/Key:admin_level
  -d LAND_DATA_DIR, --land_data_dir LAND_DATA_DIR
                        Path to the OSM land data polygons folder, read more and download from
                        https://osmdata.openstreetmap.de/data/land-polygons.html
  --debug
  --no-debug

Depending on the selected country the processing time will vary. While the maritime boundaries will take a few seconds to be generated, the land boundaries will take longer due superior spatial detail. Land boundaries for countries with with greater coverage, e.g. the United States, Canada or France, can take up to 45 minutes to be generated and will require up to 8g of memory. The reasons are resource hungry geopandas overlay operations intersecting the maritime boundaries with the OSM land polygons dataset.

Generate the maritime boundary as GeoJSON for Australia:

make_boundary --alpha2 AU --formats geojson

Generate the maritime and land boundary as GeoJSON, GeoPackage and ESRI Shapefile for Spain:

make_boundary --alpha2 ES --formats geojson shp gpkg --land_data_dir /path/to/land-polygons-split-4326

Generate the maritime and land boundaries as CSV (geometry as WKT) for France and Canada:

make_boundary --alpha2 FR CA --formats csv --land_data_dir /path/to/land-polygons-split-4326

The file output formats can be ESRI Shapefile, GeoJSON, CSV, GeoPackage, MapInfo, KML, FlatGeobuf, or PostgreSQL dump and will be saved as archives into the data within this repository.

Output

Generated files are saved as ZIP archives in the data folder with the naming pattern:

  • {country_code}_admin_level_{level}_maritime.{format}.zip - Maritime boundaries only
  • {country_code}_admin_level_{level}_land.{format}.zip - Land boundaries (if --land_data_dir is provided)

Each archive contains the boundary data in the requested format with attributes including country code, name, and administrative level.

Known Limitations

  • Currently only supports admin level 2 (country-level boundaries)
  • Land boundary generation for countries with large territories (US, Canada, France, Russia) can take 30-45 minutes and require up to 8GB of memory
  • Requires active internet connection to query Overpass API

Troubleshooting

Memory errors for large countries:

  • The land boundary intersection process is memory-intensive for countries with extensive coastlines
  • Consider processing one country at a time
  • Ensure you have at least 8GB of available RAM

Missing GDAL/GEOS libraries:

  • On Ubuntu/Debian: sudo apt-get install gdal-bin libgdal-dev libgeos-dev
  • On macOS: brew install gdal geos
  • On Windows: Install via conda or use OSGeo4W

Overpass API timeouts:

  • The Overpass API may be slow or timeout for very large queries
  • Try again later or use the --debug flag to see detailed error messages

Contributing

Contributions are welcome! Please feel free to submit a Pull Request to the GitHub repository.

Future Work

The plan is to include further administrative levels for individual countries at a later stage.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nintynine_boundaries-0.1.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nintynine_boundaries-0.1.1-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file nintynine_boundaries-0.1.1.tar.gz.

File metadata

  • Download URL: nintynine_boundaries-0.1.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.11 Linux/6.17.12-200.fc42.x86_64

File hashes

Hashes for nintynine_boundaries-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fbb6c8aa688ee1518e684c8b0d7601a3da39a200ca01f9853d892ee5b8f79418
MD5 94527c073373123a68adbac3a8d2310b
BLAKE2b-256 d17c4519d14bc6152d9b4b3c69089e03cca0c863c4e3e47b6a8bda3cafb39ca3

See more details on using hashes here.

File details

Details for the file nintynine_boundaries-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: nintynine_boundaries-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.11 Linux/6.17.12-200.fc42.x86_64

File hashes

Hashes for nintynine_boundaries-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3f7fed2eb0769c5bc7684ee41486c4b61fdd5e083a70e22c46ab9f0af5feeb26
MD5 894bd12afbc60f148d6cd90029c531a5
BLAKE2b-256 f9e4f0847ac46bc15dfdf25c6bd6b3d47be9957072b5ac4c1d5a6fe3172556e2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page