Skip to main content

Python tool to extract large-amounts of OpenStreetMap data

Project description

earth-osm. Python tool to extract large-amounts of OpenStreetMap data

PyPI version Conda version codecov CI License: MIT Discord Docs

earth-osm is a python package that provides an end-to-end solution to extract & standardize power infrastructure data from OpenStreetmap (OSM).

Features

  • Extracts power 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
  • Outputs .csv and .geojson files
  • Aggregate data per feature or per region
  • Easy to use CLI interface

Getting Started

Install earth-osm with pip:

pip install earth-osm

Or with conda:

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

Extract osm data

# Example CLI command
earth_osm extract power --regions benin monaco  --features substation line

This will extract primary feature = power for the regions = benin and monaco and the secondary features = substation and line. By default the resulting .csv and .geojson are stored in ./earth_data/out

Load the substation data for benin using pandas

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

Other Arguments

usage: earth_osm extract primary --regions region1, region2 --features feature1, feature2 --data_dir DATA_DIR [--update] [--mp]

primary (e.g power, water, road, etc) NOTE: currently only power is supported

--regions region1 region2 ... (use either iso3166-1:alpha2 or iso3166-2 codes or full names as given by running 'earth_osm view regions')

--features feature1 feature2 ... (optional, use sub-features of primary feature, e.g. substation, line, etc)

--update (optional, update existing data, default False)

--mp (optional, use multiprocessing, default True)

--data_dir (optional, path to data directory, default './earth_data')

--out_format (optional, export format options csv or geojson, default csv)

--out_aggregate (options, combine outputs per feature, default False)

Advanced Usage

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

(Optional) Intstall 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

Read the CONTRIBUTING.md file.

pip install git+https://github.com/pypsa-meets-earth/earth-osm.git
pip install -r requirements-test.txt 

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.0.tar.gz (131.1 kB view details)

Uploaded Source

Built Distribution

earth_osm-2.0-py3-none-any.whl (133.3 kB view details)

Uploaded Python 3

File details

Details for the file earth_osm-2.0.tar.gz.

File metadata

  • Download URL: earth_osm-2.0.tar.gz
  • Upload date:
  • Size: 131.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for earth_osm-2.0.tar.gz
Algorithm Hash digest
SHA256 c9b4dd92b3195a48b49d282efac47cc8aba32e4c900437ea05f36575c5006d87
MD5 5eca15f81bd525743b6ecf43fd506a2e
BLAKE2b-256 4d7da95b703ed9f8b0eba3dd642484e0fddd964273f5ca408f81b727bb0169d0

See more details on using hashes here.

File details

Details for the file earth_osm-2.0-py3-none-any.whl.

File metadata

  • Download URL: earth_osm-2.0-py3-none-any.whl
  • Upload date:
  • Size: 133.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for earth_osm-2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 971fe389fcda921c343c2fff8e613f3a73f61e69d39188307d0c4d26f36b57f3
MD5 a4912319c89fda6ca7da437fc7cdc6cc
BLAKE2b-256 28bf51485d85cfac93a29f7abc2a7e5d9718fcd5883515d249a9ae03ecf10e6a

See more details on using hashes here.

Supported by

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