Party render

From OpenStreetMap

Jump to: navigation, search

Contents

Introduction

Each evening of Mapping parties after all the tracklogs have been collected, there is always one further ritual to be performed. It goes something like this:

  • Open all 30 GPX files in JOSM
  • Select the first GPX file, and choose a colour for it
    • Choose colours for the other GPX files, trying to find unique colours that haven't already been used
  • Take a screenshot for the press, the wiki, etc.

And you end up with a result like this:

Question is: could this be automated?

Code

Source code is in Python, and located in SVN with history

Sample output:

Devon

Surrey Hills (Sunday)

Black background:

Surrey Hills (Sunday) - Black background

With town locations (can be downloaded, or from a file):

Surrey Hills (Sunday) - Black background - with city names

Options

  • -d Directory to scan for GPX files
    • Will be scanned recursively
    • Files ending in ".gpx" only
  • -s Image size (pixels)
    • Actual image width will be larger, to accommodate the key
  • -p Size of each dot
    • Seems to be in mm for some reason. 1 is normal
  • -r Radius of map in kilometres
  • -g Gazeteer filename
    • Location of an OSM file containing city/town/village nodes
    • Use "osmxapi" to download it from the internet (default)
    • Use "none" to prevent displaying cities
  • --pos=lat,lon Centre of the map
    • Available on the animated version only
    • If not supplied, will centre on the mean average of your trackpoints

Run python render.py --help to get the command-line names for those

Structure

  • SAX used for parsing GPX files
  • Cairo is used for drawing
  • Data is stored as a hash of files
    • each containing a list of trackpoints
      • each of which is a tuple of (lat,lon) in degrees
  • width is the width of the map itself - the actual image is fullwidth and includes the key
  • Y values start from 0 at the top and increase downwards


Maths

Naively, you might think you could take the extents of the trackpoints and use those to scale the map. Doesn't work - nearly everyone has erroneous points from middle of the atlantic, or from their home town 100 miles away.

Theoretically, the best algorithm to scale the map would be Median absolute deviation, since you can ask it for the middle 90% (say) of points and ignore outliers completely. However, I've had some trouble getting MAD to work on 200,000+ points (The O(n) algorithm uses quicksort and uses too much memory/recursion depth. Other algorithms are just very slow)

There is a suggestion to use MAD on a subset of the points, e.g. every 1/1000 points. Ojw 17:35, 14 October 2007 (BST)

(note: on my tests, the "real map" only covers about 0.1 standard deviations, so SD doesn't look like a very good measure either)

So the current version just asks for how many kilometres you want, and centres the map on the average (mean) position of trackpoints. But we should try and find a better way of doing it from the tracklogs themselves.

Animated version

needed libraries

Example output as MPEG or on YouTube

if the code in the SVN is not working try this one

rendered mapping parties

Pavia Mapping Party - January 6th 2008

Personal tools
recent changes