Skip to main content

Python tool to extract large-amounts of OpenStreetMap data

Project description

earth-osm

One-command to extract infrastructure data from OpenStreetMap

📚 Overview

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.

🌟 Key Features

  • 🔌 Extracts infrastructure data from OSM
  • 🧹 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 global data extraction
  • 🖱️ Easy-to-use CLI interface

🚀 Getting Started

Installation

Install earth-osm using pip (recommended):

pip install earth-osm

Or with conda:

conda install --channel=conda-forge earth-osm

Basic Usage

Extract OSM data using the CLI:

earth_osm extract power --regions benin monaco --features substation line

This 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')

🛠️ CLI Reference

Extract Command

earth_osm extract <primary> --regions <region1> <region2> ... [options]

Arguments:

  • <primary>: Primary feature to extract (e.g power)

Required Options:

  • --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

Optional Arguments:

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

🐍 Python API

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,
)

🛠️ Development

To contribute to earth-osm, follow these steps:

  1. (Optional) Install a specific version of earth_osm:

    pip install git+https://github.com/pypsa-meets-earth/earth-osm.git@<required-commit-hash>
    
  2. (Optional) Create a virtual environment for Python >=3.10:

    python3 -m venv .venv
    source .venv/bin/activate
    
  3. Install the development dependencies:

    pip install git+https://github.com/pypsa-meets-earth/earth-osm.git
    pip install -e .[dev]
    
  4. Read the CONTRIBUTING.md file for more detailed information on how to contribute to the project.

📄 License

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

🤝 Community

Join our Discord community to connect with other users and contributors, ask questions, and get support.

📚 Documentation

For more detailed information, check out our full documentation.


Made with ❤️ by the PyPSA meets Earth team

earth-osm logo

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

earth_osm-2.3.post1.tar.gz (159.9 kB view details)

Uploaded Source

Built Distribution

earth_osm-2.3.post1-py3-none-any.whl (159.4 kB view details)

Uploaded Python 3

File details

Details for the file earth_osm-2.3.post1.tar.gz.

File metadata

  • Download URL: earth_osm-2.3.post1.tar.gz
  • Upload date:
  • Size: 159.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for earth_osm-2.3.post1.tar.gz
Algorithm Hash digest
SHA256 674187fcfbb99bab8a741a08e27e9444975f0f7ac81630789f43e0af48ba3ba4
MD5 53d912dbc3c07dec38a3aeafc896cd82
BLAKE2b-256 025df92aa3890652f44027a49d868d856eee68f64e58b9ec9c6713c6d60ee655

See more details on using hashes here.

Provenance

The following attestation bundles were made for earth_osm-2.3.post1.tar.gz:

Publisher: release.yml on pypsa-meets-earth/earth-osm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file earth_osm-2.3.post1-py3-none-any.whl.

File metadata

  • Download URL: earth_osm-2.3.post1-py3-none-any.whl
  • Upload date:
  • Size: 159.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for earth_osm-2.3.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 65e7e5494bc55da2e40bf4532e13d1bf1e259f407f7c042feddecdf75a180c90
MD5 1e4cf9a447e5aea5850056527e17c38b
BLAKE2b-256 b45ad056417a27b04ef89225834cd0f803c0620cec1f05bb8617aaa586617fb5

See more details on using hashes here.

Provenance

The following attestation bundles were made for earth_osm-2.3.post1-py3-none-any.whl:

Publisher: release.yml on pypsa-meets-earth/earth-osm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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