OpenStreetMaps logotyp OpenStreetMap

gpxupload.py

Skrivet av Skippern den 2 januari 2017 på 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

Plats: 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
E-post-ikon Bluesky-ikon Facebook-ikon LinkedIn-ikon Mastodon-ikon Telegram-ikon X-ikon

Diskussion

Kommentar från gileri 3 januari 2017 kl. 18:18

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 !

Kommentar från Skippern 3 januari 2017 kl. 18:27

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.

Kommentar från Skippern15 oktober 2017 kl. 06:29

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.

Kommentar från gileri17 oktober 2017 kl. 20:28

Nice, can’t wait to see it !

Kommentar från gileri17 oktober 2017 kl. 20:30

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

Kommentar från Skippern17 oktober 2017 kl. 20:31

Of course a new blog entry will announce the new version

Logga in för att lämna en kommentar