Ierate over .osm file and call a provided callback function for each element
Project description
This code loads .osm file and allows to call function on all OSM objects in dataset.
It is distributed as an osm_iterator
PyPI package.
Usage example:
from osm_iterator.osm_iterator import Data
def show_places(element):
place_tag = element.get_tag_value("place")
name_tag = element.get_tag_value("name")
osm_object_url = element.get_link()
if place_tag != None:
print(name_tag + " is an object " + osm_object_url)
osm = Data("file.osm")
osm.iterate_over_data(show_places)
Design explanation: this code has deeply suboptimal handling of pretty much everything. For start, all data is loaded into memory and then duplicated in-memory dataset is created.
As result, attempt to process any large datasets will cause issues due to excessive memory consumption.
This situation is consequence of following facts
- This code was written during my first attempt to process OSM data using Python
- API allows (at least in theory) to painlessly switch to real iterator that is not loading all data into memory at once
- So far this was good enough for my purposes so I had no motivation to spend time on something working well
Though, if someone has good ideas (especially in form of a working code) - comments and pull requests are welcomed.
Publishing new version
Run from directory with setup.py
:
python3 setup.py sdist bdist_wheel
twine upload dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for osm_iterator-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8aa48ccc195110771bc135f470764f443fd76994ee8c8c2f8bf4fb5318e02492 |
|
MD5 | afb88e1e1a33b7d7cd4e914061b8eb27 |
|
BLAKE2b-256 | cb81da6ece9201a92c4b61eb1851af78ecd67b3e024ec1541f99551be7ecfd09 |