earth-osm downloads, filters, cleans and exports infrastructure data from OpenStreetMap (OSM). It provides a Python API and a CLI interface to extract data for various infrastructure types, such as power lines, substations, and more.
- π Extracts infrastructure data from OSM
- π Historical data support (specify target dates)
- π§Ή Cleans and standardizes the data (coming soon)
- π No API rate limits (data served from GeoFabrik)
- π Provides a Python API
- π₯οΈ Supports multiprocessing for faster extraction
- π Outputs data in .csv and .geojson formats
- π Supports planetary data extraction
- π±οΈ Easy-to-use CLI interface
- π Dual data sources: GeoFabrik (default) and live Overpass API
Install earth-osm using pip (recommended):
pip install earth-osmOr with conda:
conda install --channel=conda-forge earth-osmExtract OSM data using the CLI:
earth_osm extract power --regions benin monaco --features substation lineThis command extracts power infrastructure data for Benin and Monaco, focusing on substations and power lines. By default, the resulting .csv and .geojson files are stored in ./earth_data/out.
Load the extracted data using pandas:
import pandas as pd
import geopandas as gpd
# For Pandas
df_substations = pd.read_csv('./earth_data/out/BJ_raw_substations.csv')
# For GeoPandas
gdf_substations = gpd.read_file('./earth_data/out/BJ_raw_substations.geojson')Install aria2c (for example brew install aria2, sudo apt-get install aria2, or choco install aria2) and set EO_PARALLEL_DOWNLOADS greater than 1; earth-osm will then use multiple connections for .osm.pbf downloads and otherwise falls back automatically.
export EO_PARALLEL_DOWNLOADS=8 # fish: set -x EO_PARALLEL_DOWNLOADS 8
earth_osm extract power --regions germany --features lineearth_osm extract <primary> --regions <region1> <region2> ... [options]<primary>: Primary feature to extract (e.g power)
--regions: Specify one or more regions using ISO 3166-1 alpha-2, ISO 3166-2 codes, or full names
Tip: A list of regions is available at regions.md
| Argument | Description | Default |
|---|---|---|
--features |
Specify sub-features of the primary feature | All features |
--update |
Update existing data | False |
--no_mp |
Disable multiprocessing | False (MP enabled) |
--data_dir |
Path to data directory | './earth_data' |
--out_dir |
Path to output directory | Same as data_dir |
--out_format |
Export format(s): csv and/or geojson | ['csv', 'geojson'] |
--agg_feature |
Aggregate outputs by feature | False |
--agg_region |
Aggregate outputs by region | False |
--source |
Data source: geofabrik (default) or overpass | geofabrik |
βΉοΈ When using the Overpass backend, wildcard feature selections such as
ALL_powerare not supported. Specify concrete feature values instead, or switch to the Geofabrik source for wildcard exports.
Use the special earth region to export the full OpenStreetMap planet snapshot.
earth_osm extract power --regions earth --features line For more advanced usage, you can use the Python API:
import earth_osm as eo
eo.save_osm_data(
primary_name='power',
region_list=['benin', 'monaco'],
feature_list=['substation', 'line'],
update=False,
mp=True,
data_dir='./earth_data',
out_format=['csv', 'geojson'],
out_aggregate=False,
data_source='geofabrik' # or 'overpass'
)For historical data, add the target_date parameter:
from datetime import datetime
# Download historical data for a specific date
eo.get_osm_data(
region_str='malta',
primary_name='power',
feature_name='line',
target_date=datetime(2020, 1, 1) # Jan 1, 2020
)To contribute to earth-osm, follow these steps:
-
(Optional) Install a specific version of earth_osm:
pip install git+https://github.com/pypsa-meets-earth/earth-osm.git@<required-commit-hash>
-
(Optional) Create a virtual environment for Python >=3.10:
python3 -m venv .venv source .venv/bin/activate -
Install the development dependencies:
pip install git+https://github.com/pypsa-meets-earth/earth-osm.git pip install -e .[dev]
-
Read the CONTRIBUTING.md file for more detailed information on how to contribute to the project.
Join our Discord community to connect with other users and contributors, ask questions, and get support.
For more detailed information, check out our full documentation.
Made with β€οΈ by the PyPSA meets Earth team