OpenStreetMap-logo OpenStreetMap

gpxupload.py

Pleatst troch Skippern op 2 jannewaris 2017 yn it English.

I have just released the first stable (and complete I hope) version of my gpxupload.py script for Python2.7. It reads the GPX files, and analyses the tracks against boundary data in OSM using Overpass, before tagging the script and uploading to your OSM account. It have (as far as I have been able to identify/test) rules for all countries (admin_level=2) currently in the OSM database.

I have done an extensive investigative work to identify the boundary hierarchy in every country, in order for the script to tag as correctly as possible, without testing unnecessary or non-existent levels, testing hieratic in order to do as few tests as possible. I also noted that building Shapely objects for each test was time (and memory) consuming, so I also enabled caching and retrieving the objects from cache using WKB (well known binary) formats, the result is that for a fully cached area, a complete boundary test of a normal length track requires less than 5 calls to Overpass. Longer tracks might still need more calls, and building cache need a lot of traffic to overpass. The script also load-share between the 3 overpass servers with global coverage, and adding further servers should be a small task.

Any suggestions for improvements for the script are welcome. One of the main goals with it have been to get a better understanding of Python2.7, Shapely, and Overpass, and I feel I have succeeded in that task. Any feedback appreciated.

gpxupload.py v1.0 for py2.7 @ GitHub

Lokaasje: Centro, Guarapari, Região Geográfica Imediata de Vitória, Greater Vitória, Região Geográfica Intermediária de Vitória, Espírito Santo, Southeast Region, Brazil
Email icon Bluesky Icon Facebook Icon LinkedIn Icon Mastodon Icon Telegram Icon X Icon

Discussion

Reäksje fan gileri op 3 jannewaris 2017 om 18.18 oere

Hello,

I see that you are using proper logging, good idea.

On top of my head, some things I think can be improved :

  • Such a long file should be split for readability
  • Lines are too long
  • Try to remove old commented code, that’s why code versionning tools exist (e.g. Git)
  • There is too much complexity (nested levels of conditions, exceptions handling, etc.)
  • Variables could be more explicit (instead of NATO alphabet)
  • There is a lot of redundancy starting around line 1000
  • Your code should be wrapped in a class/function to allow importing the file without executing it

Anyway, great work; as you said you accomplished your original goals and that’s what is important !

Reäksje fan Skippern op 3 jannewaris 2017 om 18.27 oere

Thanks for feedback

I chose NATO alphabet (phonetic names) to have variables follow admin_level, I started out with human readable variables indicating the name of levels, such as county, municipality, city, etc, but that became messy and confusing.

Code cleanup will sure be a task for next version, including removal of old commented code

To get rid of the redundant code after line 1000 will require a complete rewrite of how rules are handled, which might be a good idea for next version, though I have no immediate plans for that.

I’ll probably take a break from Python now, either to get to learn basic understanding of ObjC or C++, or maybe I’ll look at something completely different.

Reäksje fan Skippern op 15 oktober 2017 om 06.29 oere

A new version is ready for roll out, with much better chache handling, proper rule handling with classes, command line arguments, and storable configuration. Currently work in progress, but nearing ready for release.

Reäksje fan gileri op 17 oktober 2017 om 20.28 oere

Nice, can’t wait to see it !

Reäksje fan gileri op 17 oktober 2017 om 20.30 oere

Also maybe make a new blog entry for the new release, such old entries are not read by much people.

Reäksje fan Skippern op 17 oktober 2017 om 20.31 oere

Of course a new blog entry will announce the new version

Meld jo oan en lit in reäksje efter