metaodi / osmapi

Python wrapper for the OpenStreetMap API
http://osmapi.metaodi.ch/
GNU General Public License v3.0
212 stars 41 forks source link

Upload multiple nodes/ways/relations with one connection #101

Open b-jazz opened 5 years ago

b-jazz commented 5 years ago

Wouldn't it be much faster to update several objects with a single call instead of doing NodeUpdate after NodeUpdate after NodeUpdate? Maybe have a NodesUpdate([node1, node2, ...]) call that would bundle that up into a single connection/upload to OSM servers.

austinhartzheim commented 5 years ago

Unless I am mistaken, there doesn't seem to support for bulk editing via the API this library depends on. If this feature is important for your use case, you might consider opening an issue on this repository. If a bulk edit endpoint is added to the API, that would open the possibility of supporting the feature here.

I will note that this library takes advantage of HTTP connection reuse, which is significantly faster than opening a new connection for each request. A bulk edit endpoint would likely be even faster, but it's not clear how much faster it would be without further investigation.

More immediately, you might find some of the links here to be useful if you are hoping to perform large edits via the API.

b-jazz commented 5 years ago

It makes sense that the API wouldn't support it, so I would understand if this gets closed. But I did notice the bit in the wiki that states, "You can also use the API to upload a change set in an atomic manner." I was kind of assuming that might be what JOSM does, so I figured if y'all use the same API, that this library could also build an atomic changeset.

As it stands, I won't be too sad if this doesn't get implemented. Just throwing it out there in case it was possible and someone wanted to tackle it.

mmd-osm commented 5 years ago

Every editing application (iD, JOSM,...) uses diff upload these days: https://wiki.openstreetmap.org/wiki/API_v0.6#Diff_upload:_POST_.2Fapi.2F0.6.2Fchangeset.2F.23id.2Fupload which allows uploading multiple changes at once.

Rather than doing this in python you could of course use some scripting in JOSM, as an example, and validate the results in an editor before uploading.

susrisha commented 9 months ago

I tried looking at ChangesetUpload api here. Looks like it was supposed to allow bulk updates. However, when I tried to do it, it only allows creating a single node at a time. There is an issue in the code. Specifically here..

for change in ChangesData:
            data += "<" + change["action"] + ">\n"
            change["data"]["changeset"] = self._CurrentChangesetId
            data += xmlbuilder._XmlBuild(
                change["type"], change["data"], False, data=self
            ).decode("utf-8")
            data += "</" + change["action"] + ">\n"
        data += "</osmChange>"

I will be more than happy to help in this regard. Do let me know if I can submit a pull request

metaodi commented 9 months ago

@susrisha Sure go ahead with a PR, this would be great 😃

susrisha commented 9 months ago

https://github.com/metaodi/osmapi/pull/155 - There you go :)

susrisha commented 9 months ago

@metaodi any update on the PR ??

metaodi commented 9 months ago

Not yet, didn't have the time to review it. I'll try to get back to you in a few days.

susrisha commented 8 months ago

Hey @metaodi can you please have a look at the PR?

metaodi commented 5 months ago

155 is the basis for this change, next up are changes needed in the "API"-methods for nodes/ways/relations to actually benefit from this new capability.