Skip to main content

Download, parse and store OSM data extracts

Project description

pydriosm

(Version 1.0.0)

Quick start

This package contains functions for the convenience of researchers to download and parse the OSM data extracts (in .osm.pbf and .shp.zip, which are available at Geofabrik's free download server and BBBike.org), and if appropriate, import the parsed data into PostgreSQL.

Note that this package is written in Python 3 on Windows operating system and may not be compatible with Python 2.

Installation (Testing phase)

Currently this package has been uploaded to TestPyPI only. The installation of the package requires a few supporting packages to ensure its complete functionality. However, some of the required packages, such as Fiona, GDAL and Shapely, may necessitate installing their Windows binaries available at Unofficial Windows Binaries for Python Extension Packages.

Otherwise, use the command prompt to run:

pip install --extra-index-url https://test.pypi.org/simple/ pydriosm

Example

import pydriosm

To download data for a region (or rather, a subregion) of which the OSM data extract is available, just simply provide the name of the (sub)region. Say if we need the data about 'West Midlands' of England:

subregion_name = 'west midlands'  # Case-insensitive
Downloading data

Download .osm.pbf data of 'West Midlands'

pydriosm.download_subregion_osm_file(subregion_name, download_path=None)

The parameterdownload_path is None by default. In that case, a default file path will be generated and the downloaded data file will be saved there; however, we may also set this parameter to be any other valid path.

import os

default_filename = pydriosm.get_default_filename(subregion_name)
download_path = os.path.join(os.getcwd(), "test_data", default_filename)

pydriosm.download_subregion_osm_file(subregion_name, download_path=download_path)
Parsing data

Pre-parse the .osm.pbf data:

west_midlands = pydriosm.read_raw_osm_pbf(subregion_name, rm_raw_file=False)

Or, fully parse the .osm.pbf data:

west_midlands_parsed = pydriosm.read_parsed_osm_pbf(subregion_name)

Note that we may simply skip the download step and run the parse functions directly. If data is not available, the parse function will download the data first. A confirmation of downloading the data will be asked if setting download_confirmation_required=True.

Importing data to PostgreSQL

The package provides a class, named 'OSM', which communicates with PostgreSQL.

osm_db = pydriosm.OSM()

A username and password to the server will be required.

Create a database:

osm_db.create_db(database_name='osm_extracts')  

# If the database is already available
# osmdb.connect_db(database_name='osm_extracts')

Import the pre-parsed .osm.pbf data into the database named 'osm_extracts':

osm_db.dump_data(west_midlands, table_name=subregion_name)

Data/Map data © Geofabrik GmbH and OpenStreetMap Contributors

All data from the OpenStreetMap is licensed under the OpenStreetMap License.

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

pydriosm-1.0.0.tar.gz (20.6 kB view hashes)

Uploaded Source

Built Distribution

pydriosm-1.0.0-py3-none-any.whl (250.9 kB view hashes)

Uploaded Python 3

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