開放街圖標誌 OpenStreetMap 開放街圖

gpxupload.py

於 2017年一月 2日 由 SkippernEnglish發表。

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

位置: 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
電子郵件圖示 藍天圖示 Facebook 圖示 LinkedIn 圖示 乳齒象圖示 Telegram 圖示 X 圖示

討論

gileri2017年01月 3日 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 !

Skippern2017年01月 3日 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.

Skippern2017年10月15日 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.

gileri2017年10月17日 20時28分 發表的評論

Nice, can’t wait to see it !

gileri2017年10月17日 20時30分 發表的評論

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

Skippern2017年10月17日 20時31分 發表的評論

Of course a new blog entry will announce the new version

登入 來留下評論