osmpythontools
A library to access OpenStreetMap related services
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (9.7%) to scientific vocabulary
Keywords
Repository
A library to access OpenStreetMap related services
Basic Info
Statistics
- Stars: 464
- Watchers: 15
- Forks: 51
- Open Issues: 1
- Releases: 0
Topics
Metadata Files
README.md
OSMPythonTools
The python package OSMPythonTools provides easy access to OpenStreetMap (OSM) related services, among them an Overpass endpoint, Nominatim, and the OSM API.
Installation
To install OSMPythonTools, you will need python3 and pip (How to install pip). Then execute:
bash
pip install OSMPythonTools
On some operating systems, pip for python3 is named pip3:
bash
pip3 install OSMPythonTools
Example 1
Which object does the way with the ID 5887599 represent?
We can use the OSM API to answer this question:
python
from OSMPythonTools.api import Api
api = Api()
way = api.query('way/5887599')
The resulting object contains information about the way, which can easily be accessed:
```python
way.tag('building')
'castle'
way.tag('architect')
'Johann Lucas von Hildebrandt'
way.tag('website')
'http://www.belvedere.at'
```
Example 2
What is the English name of the church called ‘Stephansdom’, what address does it have, and which of which denomination is the church?
We use the Overpass API to query the corresponding data:
python
from OSMPythonTools.overpass import Overpass
overpass = Overpass()
result = overpass.query('way["name"="Stephansdom"]; out body;')
This time, the result is a number of objects, which can be accessed by result.elements(). We just pick the first one:
python
stephansdom = result.elements()[0]
Information about the church can now easily be accessed:
```python
stephansdom.tag('name:en')
"Saint Stephen's Cathedral"
'%s %s, %s %s' % (stephansdom.tag('addr:street'), stephansdom.tag('addr:housenumber'), stephansdom.tag('addr:postcode'), stephansdom.tag('addr:city'))
'Stephansplatz 3, 1010 Wien'
stephansdom.tag('building')
'cathedral'
stephansdom.tag('denomination')
'catholic'
```
Example 3
How many trees are in the OSM data of Vienna? And how many trees have there been in 2013?
This time, we have to first resolve the name ‘Vienna’ to an area ID:
python
from OSMPythonTools.nominatim import Nominatim
nominatim = Nominatim()
areaId = nominatim.query('Vienna, Austria').areaId()
This area ID can now be used to build the corresponding query:
```python
from OSMPythonTools.overpass import overpassQueryBuilder, Overpass
overpass = Overpass()
query = overpassQueryBuilder(area=areaId, elementType='node', selector='"natural"="tree"', out='count')
result = overpass.query(query)
result.countElements()
137830
There are 134520 trees in the current OSM data of Vienna. How many have there been in 2013?
python
result = overpass.query(query, date='2013-01-01T00:00:00Z', timeout=60)
result.countElements()
127689
```
Example 4
Where are waterbodies located in Vienna?
Again, we have to resolve the name ‘Vienna’ before running the query:
python
from OSMPythonTools.nominatim import Nominatim
nominatim = Nominatim()
areaId = nominatim.query('Vienna, Austria').areaId()
The query can be built like in the examples before. This time, however, the argument includeGeometry=True is provided to the overpassQueryBuilder in order to let him generate a query that downloads the geometry data.
python
from OSMPythonTools.overpass import overpassQueryBuilder, Overpass
overpass = Overpass()
query = overpassQueryBuilder(area=areaId, elementType=['way', 'relation'], selector='"natural"="water"', includeGeometry=True)
result = overpass.query(query)
Next, we can exemplarily choose one random waterbody (the first one of the download ones) and compute its geometry like follows:
```python
firstElement = result.elements()[0]
firstElement.geometry()
{"coordinates": [[[16.498671, 48.27628], [16.4991, 48.276345], ... ]], "type": "Polygon"}
``` Observe that the resulting geometry is provided in the GeoJSON format.
Example 5
How did the number of trees in Berlin, Paris, and Vienna change over time?
Before we can answer the question, we have to import some modules:
python
from collections import OrderedDict
from OSMPythonTools.data import Data, dictRangeYears, ALL
from OSMPythonTools.overpass import overpassQueryBuilder, Overpass
The question has two ‘dimensions’: the dimension of time, and the dimension of different cities:
python
dimensions = OrderedDict([
('year', dictRangeYears(2013, 2017.5, 1)),
('city', OrderedDict({
'berlin': 'Berlin, Germany',
'paris': 'Paris, France',
'vienna': 'Vienna, Austria',
})),
])
We have to define how we fetch the data. We again use Nominatim and the Overpass API to query the data (it can take some time to perform this query the first time!):
python
overpass = Overpass()
def fetch(year, city):
areaId = nominatim.query(city).areaId()
query = overpassQueryBuilder(area=areaId, elementType='node', selector='"natural"="tree"', out='count')
return overpass.query(query, date=year, timeout=60).countElements()
data = Data(fetch, dimensions)
We can now easily generate a plot from the result:
python
data.plot(city=ALL, filename='example4.png')

Alternatively, we can generate a table from the result ```python data.select(city=ALL).getCSV()
year,berlin,paris,vienna
2013.0,10180,1936,127689
2014.0,17971,26905,128905
2015.0,28277,90599,130278
2016.0,86769,103172,132293
2017.0,108432,103246,134616
```
More examples can be found inside the documentation of the modules.
Usage
The following modules are available (please click on their names to access further documentation):
- OSMPythonTools.Api - Access to the official OSM API
- OSMPythonTools.Data - Collecting, mining, and drawing data from OSM; to be used in combination with the other modules
- OSMPythonTools.Element - Elements are returned by other services, like the OSM API or the Overpass API
- OSMPythonTools.Nominatim - Access to Nominatim, a reverse geocoder
- OSMPythonTools.Overpass - Access to the Overpass API
Please refer to the general remarks page if you have further questions related to OSMPythonTools in general or functionality that the several modules have in common.
Observe the breaking changes as included in the version history.
Logging
This library is a little bit more verbose than other Python libraries. The good reason behind is that the OpenStreetMap, the Nominatim, and the Overpass servers experience a heavy load already and their resources should be used carefully. In order to make you, the user of this library, aware of when OSMPythonTools accesses these servers, corresponding information is logged by default. In case you want to suppress these messages, you have to insert the following lines after the import of OSMPythonTools:
python
import logging
logging.getLogger('OSMPythonTools').setLevel(logging.ERROR)
Please note that suppressing the messages means that you have to ensure on your own that you do not overuse the provided services and that you stick to their fair policy guidelines.
Tests
You can test the package by installing the corresponding dependencies ```bash pip install OSMPythonTools [test]
or: pip3 install OSMPythonTools [test]
and then running
bash
pytest --verbose
```
Please note that the tests might run very long (several minutes) because the overpass server will most likely defer the downloads.
Author
This application is written and maintained by Franz-Benjamin Mocnik, mail@mocnik-science.net.
(c) by Franz-Benjamin Mocnik, 2017-2022.
The code is licensed under the GPL-3.
Owner
- Name: Franz-Benjamin Mocnik
- Login: mocnik-science
- Kind: user
- Location: Salzburg, Austria
- Company: Paris Lodron University of Salzburg
- Website: www.mocnik-science.net
- Repositories: 19
- Profile: https://github.com/mocnik-science
Citation (CITATION.cff)
cff-version: 1.2.0
message: "If you use this software, please provide a link to the following paper about data mining infrastructure for exploring and analysing OpenStreetMap data."
authors:
- family-names: "Mocnik"
given-names: "Franz-Benjamin"
orcid: "https://orcid.org/0000-0002-1759-6336"
title: "OSMPythonTools"
doi: 10.1186/s40965-018-0047-6
url: "https://github.com/mocnik-science/osm-python-tools"
preferred-citation:
type: article
authors:
- family-names: "Mocnik"
given-names: "Franz-Benjamin"
orcid: "https://orcid.org/0000-0002-1759-6336"
- family-names: "Mobasheri"
given-names: "Amin"
- family-names: "Zipf"
given-names: "Alexander"
title: "Open Source Data Mining Infrastructure for Exploring and Analysing OpenStreetMap"
journal: "Open Geospatial Data, Software and Standards"
issue: 3
volume: 7
year: 2018
doi: 10.1186/s40965-018-0047-6
GitHub Events
Total
- Issues event: 9
- Watch event: 31
- Issue comment event: 9
- Push event: 6
- Pull request event: 3
- Fork event: 2
Last Year
- Issues event: 9
- Watch event: 31
- Issue comment event: 9
- Push event: 6
- Pull request event: 3
- Fork event: 2
Committers
Last synced: 8 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Franz-Benjamin Mocnik | m****l@f****t | 145 |
| ty.hranac | t****c@g****m | 2 |
| cjdhein | c****n@g****m | 1 |
| antonio | a****o@c****u | 1 |
| Mateusz Konieczny | m****z@g****m | 1 |
| Konstantin Petrov | p****t@g****m | 1 |
| Jakob Miksch | j****h@p****u | 1 |
| Bongo2020 | 6****0 | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 4 months ago
All Time
- Total issues: 61
- Total pull requests: 20
- Average time to close issues: 4 months
- Average time to close pull requests: 3 months
- Total issue authors: 53
- Total pull request authors: 18
- Average comments per issue: 2.48
- Average comments per pull request: 1.9
- Merged pull requests: 8
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 2
- Pull requests: 1
- Average time to close issues: 26 days
- Average time to close pull requests: about 1 month
- Issue authors: 2
- Pull request authors: 1
- Average comments per issue: 0.5
- Average comments per pull request: 1.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- das-g (3)
- johnaschmidt (2)
- stefanct (2)
- rever96 (2)
- dpriskorn (2)
- TheFGFSEagle (2)
- simonmarti1992 (2)
- muran123 (1)
- skaryaeva (1)
- Res260 (1)
- EsbernJakobsen (1)
- DavidsonOtobo (1)
- MaRaSu (1)
- ZaraGi (1)
- RisingPhoelix (1)
Pull Request Authors
- st-a (2)
- V0lantis (2)
- tyhranac (1)
- ka-petrov (1)
- das-g (1)
- ad2476 (1)
- cjdhein (1)
- KAMI911 (1)
- EsbernJakobsen (1)
- huyphan2612 (1)
- matkoniecz (1)
- JakobMiksch (1)
- Bergruebe (1)
- cav71 (1)
- Zdeeno (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 5,805 last-month
- Total dependent packages: 5
- Total dependent repositories: 9
- Total versions: 27
- Total maintainers: 1
pypi.org: osmpythontools
A library to access OpenStreetMap related services
- Homepage: https://github.com/mocnik-science/osm-python-tools
- Documentation: https://osmpythontools.readthedocs.io/
- License: GPL-3
-
Latest release: 0.3.6
published 6 months ago