OpenStreetMap logo OpenStreetMap

osmdiff 0.3.2

Posted by mvexel on 13 October 2022 in English.

I’ve spent a few evenings and spare hours this week dusting off and updating osmdiff. If you’re a python developer and you need to interact with replication diffs or augmented diffs, this may just be something of interest to you. osmdiff can retrieve replication diffs as well as augmented diffs from OSM servers, and parse them into native Python Node, Way and Relation objects you can use in your code. This lets you do things like

>>> from osmdiff import OSMChange
>>> o = OSMChange()
>>> o.frequency = "minute"  # the default
>>> o.get_state()  # retrieve current sequence ID
>>> o.sequence_number
2704451
>>> o.retrieve()  # retrieve from API
>>> o
OSMChange (677 created, 204 modified, 14 deleted)

Once you have the data, you can filter and inspect it:

>>> w = [n["new"] for n in a.modify if n["new"].attribs["id"] == "452218081"]
>>> w
[Way 452218081 (10 nodes)]
>>> w[0]
Way 452218081 (10 nodes)
>>> w[0].tags
{'highway': 'residential'}
>>> w[0].attribs
{'id': '452218081', 'version': '2', 'timestamp': '2017-11-10T13:52:01Z', 'changeset': '53667190', 'uid': '2352517', 'user': 'carths81'}
>>> w[0].attribs
{'id': '452218081', 'version': '2', 'timestamp': '2017-11-10T13:52:01Z', 'changeset': '53667190', 'uid': '2352517', 'user': 'carths81'}
>>> w[0].bounds
['12.8932677', '43.3575917', '12.8948117', '43.3585947']

You can also use osmdiffs implementation of Node, Way and Relation objects separately if you need just those, the library is quite small and has few dependencies (just requests and dateutil)

On the list of things in development and slated for the next release are: * Python __geo_interface__ support so you can easily use them in other Python modules that support them like shapely and geojson * Retrieving individual OSM features from the OSM API * Ability to create an AugmentedDiff / OSMChange object with a datetime parameter, which will then calculate the sequence number for you * More tests, always more tests, and CircleCI integration

If you are using osmdiff and find it useful, I would love to hear from you. If you find a bug or find something lacking, please [open an issue].

Discussion

Comment from Christian Ledermann on 14 October 2022 at 09:34

Can you elaborate a bit more about your plans for __geo_interface__? I am the author of pygeoif and osmoapi and have some interest in making OSM more interoperable on the python side.

Comment from mvexel on 14 October 2022 at 15:24

Christian - thanks for sharing links to your work as well! The OAuth module is something I may use soon in fact.

For __geo_interface__, I think it would be great to have a canonical representation of OSM nodes, ways, relations in Python that support __geo_interface__ interoperability. I think I am probably 60% of the way there with the implementation in osmdiff. I would be happy to extract it to a separate module if that makes sense for visibility and clarity. The __geo_interface__ implementation for Relation is almost certainly too simplistic, it just iterates over the members to create a FeatureCollection right now.

There’s also OSMNx, which is widely used in the academic community but I don’t know how useful it is as a general purpose module for OSM data processing and representation. I think it’s specifically targeted at network analysis use cases, but I haven’t used it myself.

I’d love to collaborate on this.

Comment from Christian Ledermann on 14 October 2022 at 16:28

I have not worked with osmoapi for a while, I hope it is still up-to-date with the current API implementation. I used it only once to crowdsource the import of UK schools.

Comment from mvexel on 14 October 2022 at 16:42

There’s OAuth 2.0 now but 1.0a is still supported, and I guess will be for a while?

Is there a sample client app? I can probably help out a bit to dust it off if needed.

Comment from mvexel on 14 October 2022 at 19:41

There seem to be project governance related issues with PSA.

How about Requests-OAuthlib?

Log in to leave a comment