ohsome

Python bindings for the ohsome API

https://github.com/giscience/ohsome-py

Science Score: 57.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 4 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
    2 of 6 committers (33.3%) from academic institutions
  • Institutional organization owner
    Organization giscience has institutional domain (www.geog.uni-heidelberg.de)
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.7%) to scientific vocabulary

Keywords

ohsome openstreetmap openstreetmap-data openstreetmap-history python
Last synced: 6 months ago · JSON representation

Repository

Python bindings for the ohsome API

Basic Info
  • Host: GitHub
  • Owner: GIScience
  • License: gpl-3.0
  • Language: Jupyter Notebook
  • Default Branch: master
  • Homepage:
  • Size: 1.63 MB
Statistics
  • Stars: 18
  • Watchers: 12
  • Forks: 4
  • Open Issues: 6
  • Releases: 12
Topics
ohsome openstreetmap openstreetmap-data openstreetmap-history python
Created over 5 years ago · Last pushed 9 months ago
Metadata Files
Readme Changelog License

README.md

ohsome-py: A Python client for the ohsome API

status: active

The ohsome-py package helps you extract and analyse OpenStreetMap history data using the ohsome API and Python. It handles queries to the ohsome API and converts its responses to Pandas and GeoPandas data frames to facilitate easy data handling and analysis.

The ohsome API provides various endpoints for data aggregation, data extraction and contributions to analyse the history of OSM data. Take a look at the documentation of the ohsome API or go through the Tutorial to get started on how to use ohsome-py.

Installation

Using pip

You can install ohsome-py using pip, which will also install all dependencies.

$ pip install ohsome

Using Anaconda

ohsome-py is not available through Conda. So if you are using Conda, create a new conda environment and install your required dependencies as well as those from ohsome-py (see pyproject.toml) before installing ohsome-py using pip. Please note that there might be issues when using pip within anaconda. To avoid issues we advise to install everything in a new conda environment.

Dependencies for Jupyter Notebooks

If you want to run the Jupyter Notebook Tutorial you also need to install jupyter and matplotlib e.g.

$ pip install jupyter matplotlib

Usage

All queries are handled by an OhsomeClient object, which also provides information about the current ohsome API instance, e.g. start_timestamp and end_timestamp indicate the earliest and the latest possible dates for a query.

python from ohsome import OhsomeClient client = OhsomeClient() client.start_timestamp # --> '2007-10-08T00:00:00Z' client.end_timestamp # --> '2021-01-23T03:00Z'

1. Data Aggregation

Example: The area of OSM elements tagged as landuse=farmland using the /elements/area endpoint:

python response = client.elements.area.post(bboxes=[8.625,49.3711,8.7334,49.4397], time="2014-01-01", filter="landuse=farmland and geometry:polygon")

The single components of the endpoint URL are appended as method calls to the OhsomeClient object. Use automatic code completion to find valid endpoints. Alternatively, you can define the endpoint as argument in the .post() method.

python response = client.post(endpoint="elements/area", bboxes=[8.625,49.3711,8.7334,49.4397], time="2020-01-01", filter="landuse=farmland and geometry:polygon")

Responses from the data aggregation endpoints can be converted to a pandas.DataFrame object using the OhsomeResponse.as_dataframe() method.

response_df = response.as_dataframe()

2. Data Extraction

Example: OSM elements tagged as landuse=farmland including their geometry and tags using the /elements/geometry endpoint:

python client = OhsomeClient() response = client.elements.geometry.post(bboxes=[8.625,49.3711,8.7334,49.4397], time="2020-01-01", filter="landuse=farmland and geometry:polygon", properties="tags") response_gdf = response.as_dataframe()

Responses from the data extraction endpoint can be converted to a geopandas.GeoDataFrame using the OhsomeResponse.as_dataframe() method, since the data contains geometries.

Query Parameters

All query parameters are described in the ohsome API documentation and can be passed as string objects to the post() method. Other Python data types are accepted as well.

Boundary

The boundary of the query can be defined using the bpolys, bboxes and bcircles parameters. The coordinates have to be given in WGS 84 (EPSG:4326).

bpolys

The bpolys parameter can be passed as a geopandas.GeoDataFrame containing the polygon features.

python bpolys = gpd.read_file("./data/polygons.geojson") client.elements.count.groupByBoundary.post(bpolys=bpolys, filter="amenity=restaurant")

bboxes

The bboxes parameter contains the coordinates of one or several bounding boxes.

python bboxes = [8.7137,49.4096,8.717,49.4119] # one bounding box bboxes = [[8.7137,49.4096,8.717,49.4119], [8.7137,49.4096,8.717,49.4119]] bboxes = {"A": [8.67066, 49.41423, 8.68177, 49.4204], "B": [8.67066, 49.41423, 8.68177, 49.4204]}

bcircles

The bcircles parameter contains one or several circles defined through the coordinates of the centroids and the radius in meters.

python bcircles = [8.7137,49.4096, 100] bcircles = [[8.7137,49.4096, 100], [8.7137,49.4096, 300]] bcircles = {"Circle1": [8.695, 49.41, 200], "Circle2": [8.696, 49.41, 200]}

Time

The time parameter must be ISO-8601 conform can be passed in several ways

python time = '2018-01-01/2018-03-01/P1M' time = ['2018-01-01', '2018-02-01', '2018-03-01'] time = datetime.datetime(year=2018, month=3, day=1) time = pandas.date_range("2018-01-01", periods=3, freq="M")

Citation

When using ohsome-py e.g. for a publication or elsewhere, please cite the ohsome-api as described in their citation recommendation for example like

M. Raifer, R. Troilo, F.-B. Mocnikand M. Schott, ‘OSHDB - OpenStreetMap History Data Analysis version 1.2.1 accessed via the ohsome-py library version 0.3.0’. Zenodo, Sep. 29, 2023. doi: 10.5281/zenodo.8391737.

bibtex @software{raifer_2023_7713347, author = {Raifer, Martin and Troilo, Rafael and Mocnik, Franz-Benjamin and Schott, Moritz}, title = {OSHDB - OpenStreetMap History Data Analysis version 1.2.1 accessed via the ohsome-py library version 0.3.0}, month = sep, year = 2023, publisher = {Zenodo}, version = {1.2.1}, doi = {10.5281/zenodo.8391737}, url = {https://doi.org/10.5281/zenodo.8391737} }

Contribution Guidelines

The easiest way to contribute is to file a comprehensive issue with a reproducible example. Pull requests are always welcome, so if you want to contribute to this project, please fork the repository or create a new branch containing your changes. Follow the steps below to make sure that your contributed code follows the code style and does not break any functionality. Create a pull request to the main/master branch once it is ready to be merged.

Install Package

This package uses poetry for dependency management. To install all packages necessary for testing and development run

poetry install

Install Pre-Commit Hooks

Install the pre-commit hooks in our local git repo before committing to ensure homogenous code style.

poetry run pre-commit install

Run Tests

Before pushing your commits, run the python unit tests

poetry run pytest

VCR

ohsome-py records responses using VCR via pytest-recording to prevent unnecessary network traffic and computing during testing. If you implement a test or change an existing one, make sure to update the recorded cassettes. In addition, you should delete all cassettes after a certain time (e.g. every 6m or on each new ohsome release) and re-record them. To do that run

poetry run pytest --record-mode=all

References

The design of this package was inspired by the blog post Using Python to Implement a Fluent Interface to Any REST API by Elmer Thomas.

Owner

  • Name: GIScience Research Group and HeiGIT
  • Login: GIScience
  • Kind: organization
  • Location: Heidelberg, Germany

🌍 HeiGIT and GIScience at Heidelberg University are engaged in research and opensource development at the interface between geography and computational science

GitHub Events

Total
  • Create event: 7
  • Release event: 1
  • Issues event: 4
  • Delete event: 7
  • Issue comment event: 6
  • Push event: 7
  • Pull request review event: 5
  • Pull request event: 12
Last Year
  • Create event: 7
  • Release event: 1
  • Issues event: 4
  • Delete event: 7
  • Issue comment event: 6
  • Push event: 7
  • Pull request review event: 5
  • Pull request event: 12

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 122
  • Total Committers: 6
  • Avg Commits per committer: 20.333
  • Development Distribution Score (DDS): 0.377
Past Year
  • Commits: 33
  • Committers: 1
  • Avg Commits per committer: 33.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Christina Ludwig c****g@u****e 76
Moritz Schott m****t@u****e 38
Julian Psotta 2****P 4
Julian Psotta j****n@o****g 2
Johannes Visintini j****i@h****g 1
Martin Raifer m****r@h****g 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 58
  • Total pull requests: 103
  • Average time to close issues: 6 months
  • Average time to close pull requests: 21 days
  • Total issue authors: 10
  • Total pull request authors: 7
  • Average comments per issue: 1.14
  • Average comments per pull request: 0.45
  • Merged pull requests: 79
  • Bot issues: 0
  • Bot pull requests: 18
Past Year
  • Issues: 10
  • Pull requests: 48
  • Average time to close issues: about 1 month
  • Average time to close pull requests: 13 days
  • Issue authors: 4
  • Pull request authors: 4
  • Average comments per issue: 0.3
  • Average comments per pull request: 0.44
  • Merged pull requests: 38
  • Bot issues: 0
  • Bot pull requests: 17
Top Authors
Issue Authors
  • SlowMo24 (33)
  • redfrexx (12)
  • MichaelsJP (2)
  • matthiasschaub (2)
  • matkoniecz (2)
  • maciej-adamiak (2)
  • joker234 (1)
  • tqa236 (1)
  • mcauer (1)
  • ManuelKraft (1)
  • Chwiggy (1)
Pull Request Authors
  • SlowMo24 (43)
  • redfrexx (38)
  • dependabot[bot] (35)
  • MichaelsJP (6)
  • rp280 (3)
  • matkoniecz (1)
  • joker234 (1)
Top Labels
Issue Labels
enhancement (20) bug (7) good first issue (7) testing (2) CI (1) invalid (1) documentation (1)
Pull Request Labels
dependencies (35) python (3) enhancement (2) bug (1)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 370 last-month
  • Total docker downloads: 12
  • Total dependent packages: 0
  • Total dependent repositories: 3
  • Total versions: 14
  • Total maintainers: 3
pypi.org: ohsome

A Python client for the ohsome API

  • Versions: 14
  • Dependent Packages: 0
  • Dependent Repositories: 3
  • Downloads: 370 Last month
  • Docker Downloads: 12
Rankings
Docker downloads count: 4.6%
Dependent repos count: 9.0%
Dependent packages count: 10.1%
Average: 11.6%
Downloads: 14.6%
Forks count: 15.4%
Stargazers count: 16.1%
Maintainers (3)
Last synced: 7 months ago

Dependencies

poetry.lock pypi
  • atomicwrites 1.4.0 develop
  • black 22.3.0 develop
  • cfgv 3.3.1 develop
  • coverage 6.3.2 develop
  • distlib 0.3.4 develop
  • filelock 3.6.0 develop
  • identify 2.4.12 develop
  • iniconfig 1.1.1 develop
  • mypy-extensions 0.4.3 develop
  • nodeenv 1.6.0 develop
  • packaging 21.3 develop
  • pathspec 0.9.0 develop
  • platformdirs 2.5.2 develop
  • pluggy 1.0.0 develop
  • pre-commit 2.18.1 develop
  • py 1.11.0 develop
  • pyparsing 3.0.8 develop
  • pytest 7.1.1 develop
  • pytest-cov 3.0.0 develop
  • pytest-random-order 1.0.4 develop
  • pyyaml 6.0 develop
  • toml 0.10.2 develop
  • tomli 2.0.1 develop
  • tox 3.25.0 develop
  • typed-ast 1.5.3 develop
  • virtualenv 20.14.1 develop
  • attrs 21.4.0
  • certifi 2021.10.8
  • charset-normalizer 2.0.12
  • click 8.1.2
  • click-plugins 1.1.1
  • cligj 0.7.2
  • colorama 0.4.4
  • fiona 1.8.21
  • geopandas 0.10.2
  • idna 3.3
  • importlib-metadata 4.11.3
  • multidict 5.2.0
  • munch 2.5.0
  • numpy 1.19.5
  • numpy 1.22.3
  • pandas 1.4.1
  • pandas 1.4.0
  • pandas 1.4.2
  • pandas 1.3.4
  • pandas 0.25.3
  • pandas 1.3.3
  • pandas 1.3.5
  • pyproj 3.2.1
  • python-dateutil 2.8.2
  • pytz 2022.1
  • requests 2.27.1
  • shapely 1.8.1.post1
  • six 1.16.0
  • typing-extensions 4.2.0
  • urllib3 1.26.9
  • zipp 3.8.0
pyproject.toml pypi
  • black ^22.3.0 develop
  • pre-commit ^2.9.2 develop
  • pytest ^7.1.1 develop
  • pytest-cov ^3.0.0 develop
  • pytest-random-order ^1.0.4 develop
  • tox ^3.23.0 develop
  • geopandas ^0.10.0
  • multidict ^5.1.0
  • numpy --- - !ruby/hash:ActiveSupport::HashWithIndifferentAccess version: "<=1.19.5" python: '3.7' - !ruby/hash:ActiveSupport::HashWithIndifferentAccess version: "^1.20.0" python: ">=3.8, <4"
  • pandas --- - !ruby/hash:ActiveSupport::HashWithIndifferentAccess version: "<=0.25.3" python: "<3.8" - !ruby/hash:ActiveSupport::HashWithIndifferentAccess version: "^1.0.5" python: ">=3.8, <4"
  • pip ^22.0.4
  • pyproj ^3.0.0
  • python >=3.7,<4.0
  • requests ^2.25.1
  • urllib3 ^1.26
.github/workflows/ci-development.yml actions
  • abatilo/actions-poetry v2.1.0 composite
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
  • codecov/codecov-action v1 composite
  • pre-commit/action v2.0.0 composite
  • julianpsotta/ohsome-api 1.4.1 docker
.github/workflows/ci-production.yml actions
  • abatilo/actions-poetry v2.1.0 composite
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
  • codecov/codecov-action v1 composite
  • julianpsotta/ohsome-api 1.4.1 docker