osmgnuplot.pl - Download OSM tiles, and make a gnuplot script to render them
$ osmgnuplot.pl --center 34.094719,-118.235779 --rad 300m --zoom 16
Downloading http://tile.openstreetmap.org/16/11243/26158.png
Downloading http://tile.openstreetmap.org/16/11244/26158.png
Downloading http://tile.openstreetmap.org/16/11243/26159.png
Downloading http://tile.openstreetmap.org/16/11244/26159.png
Done! Gnuplot script 'montage_34.094719_-118.235779_300m_16.gp' uses the image 'montage_34.094719_-118.235779_300m_16.png'
$ gnuplot -persist montage_34.094719_-118.235779_300m_16.gp
[a gnuplot window pops up, showing OSM tiles]
This script downloads OSM tiles, glues them together into a single image, and generates a gnuplot script to render this image, aligned correctly to its latitude, longitude (on the gnuplot y2 and x2 axes respectively). While this in itself is not useful, the gnuplot script can be expanded to plot other things on top of the map, to make it easy to visualize geospatial data. Example plots appear here:
The generated gnuplot script darkens the map a bit to make the extra stuff stand out (attenuation
parameter in the resulting script).
The communication with the OSM tile server assumes some caching. If an appropriately-named tile already exists on disk, the If-None-Match
header field is used to send over the MD5 hash of the tile on disk. If the tile on the server has the same hash, the server doesn't bother sending it over, which results in bandwidth savings.
The OSM tiles have a nonlinear relationship between longitude and tile pixels. The gnuplot script generated here applies the nonlinearity to the y2 axis, so the plotted image is not distorted, but the axes are still showing the correct data. A side-effect of this is that latitude is on the y2 axis and longitude is on the x2 axis. For instance, to plot a file latlon.dat
containing latitude,longitude columns with points on top of the stitched OSM tiles, do this:
plot "montage_....png" ...., \
"latlon.dat" using 2:1 with points axis x2y2
The "montage..."
stuff is generated by osmgnuplot.pl
, and the user would add the "latlon.dat"
stuff.
Note that some versions of gnuplot have a minor bug, and you may see the following message:
warning: could not confirm linked axis inverse mapping function
This is benign, and can be ignored
- --center <lat>,<lon>
-
Center point
- --rad <radius>
-
How far around the center to query. This must include units (support
m
,km
andmiles
; no whitespace between the number and units). - --zoom <zoom>
-
The OSM zoom level
- --serverpath <url>
-
The base URL to grab tiles from. We default to the OSM tile server:
http://tile.openstreetmap.org
I use non-core perl modules Getopt::Euclid
and LWP::UserAgent
. I also use the montage
tool from imagemagick
. On a Debian box the following should be sufficient:
apt-get install libgetopt-euclid-perl libwww-perl imagemagick
https://github.com/dkogan/osmgnuplot
Dima Kogan, <dima@secretsauce.net>
Copyright 2015 Dima Kogan.
This program is free software; you can redistribute it and/or modify it under the terms of the Lesser General Public License version 3, as published by the Free Software Foundation. Full text at http://www.gnu.org/licenses/lgpl.html