開放街圖標誌 OpenStreetMap 開放街圖

osmdiff 0.3.2

於 2022年十月13日 由 mvexelEnglish發表。

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].

電子郵件圖示 藍天圖示 Facebook 圖示 LinkedIn 圖示 乳齒象圖示 Telegram 圖示 X 圖示

討論

Christian Ledermann2022年10月14日 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.

mvexel2022年10月14日 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.

Christian Ledermann2022年10月14日 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.

mvexel2022年10月14日 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.

mvexel2022年10月14日 19時41分 發表的評論

There seem to be project governance related issues with PSA.

How about Requests-OAuthlib?

登入 來留下評論