OpenStreetMap

mkarau's diary

Recent diary entries

Traffic Enforcement Cameras

Posted by mkarau on 2 November 2013 in English (English)

First - wow! It's quite un-intuitive to add a traffic camera to OSM... http://wiki.openstreetmap.org/wiki/Relation:enforcement

Second - wow^2! No one seems to render the traffic enforcements. They're not shown on the default OSM rendering, and OSMand+ for Android phones (a navigation app that should show them) also does not include them.

This site scrapes the database every couple weeks and renders the enforcements. Enjoy! http://frink.bplaced.de/blitzer/

Tile Stitching...

Posted by mkarau on 24 October 2013 in English (English)

Below is a shell script using graphicsmagick (can be easily adapted to imagemagick by simply removing gm from the two image-generation lines below) for stitching together downloaded tile sets into one large PNG. It is tested on MacOS 10.8.5 with graphicsmagick installed via homebrew and should work on most Linux distros. This script is adapted from a script posted by HannesHH.

The script can be useful when producing large printed maps at a zoom level unavailable from most online services. I use JTileDownloader to grab tiles. Be sure to obey the terms of use of your tile server (or bake your own).

#!/bin/bash
# Original credit to OSM user HannesHH
# Updated by OSM user mkarau
# will search for tiles in your current directory ($z/$x/$y.png) and stitch them all together
# will fail horribly if you do not have a rectangular area with tiles
# this is super i/o intense if you use it for a larger amount of tiles so do not do that
# that is because i am lazy and just needed something for small areas
# uses graphicsmagick's gm tool, just remove "gm" if you use imagemagick
# needs bash 3 i guess
# pass the wanted zoomlevel as argument, eg "bash ./tilestitch.sh 14"

blankFileName="./blank.png"
stitchedFileName="./stitchedtiles.png"
#montageOptions="-verbose +frame +shadow +label"
montageOptions="+frame +shadow +label"

runScript=0

if [ $# -gt 0 ];
then
    zoomlevel=$1
    if [ ${zoomlevel} -ge 0 ];
    then
        if [ ${zoomlevel} -le 18 ];
        then
            if [ -d "${zoomlevel}" ];
            then
                runScript=1
            fi
        fi
    fi
fi


if [ ${runScript} -le 0 ];
then
    echo "usage: $0 ZOOMLEVEL"
    echo "ZOOMLEVEL: 0-18"
    echo "Files must be stored in the directory structure below"
    echo "./ZOOMLEVEL/XXXXXX/YYYYYY.png"
    exit    
fi

rows=$(ls -1 $zoomlevel/*/*.png | grep -Eo '/.*/' | sort| uniq | wc -l)
rows=$(echo ${rows} | tr -d ' ')

columns=$(ls -1 $zoomlevel/*/*.png | grep -Eo '/[^/]*png' | sort | uniq | wc -l)
columns=$(echo ${columns} | tr -d ' ')

min_x=$(ls -1 $zoomlevel/*/*.png | grep -Eo '/.*/' | sed 's/\///g' | sort -n  | head -1)
max_x=$(ls -1 $zoomlevel/*/*.png | grep -Eo '/.*/' | sed 's/\///g' | sort -n | tail -1)
min_y=$(ls -1 $zoomlevel/*/*.png | grep -Eo '[^/]*png' | sed 's/\.png//g' | sort -n | head -1)
max_y=$(ls -1 $zoomlevel/*/*.png | grep -Eo '[^/]*png' | sed 's/\.png//g' | sort -n | tail -1)
# so sorry...

echo "zoomlevel: $zoomlevel"
echo "rows: $rows"
echo "columns: $columns"
totalTiles=$(( rows * columns ))
echo "Total Tiles: ${totalTiles}"

echo "min_x: $min_x"
echo "max_x: $max_x"
echo "min_y: $min_y"
echo "max_y: $max_y"

missingTiles=0
tileNo=0
xIndex=0
yIndex=0

echo -n "Ordering filenames for stitching "
# gm montage needs them ordered by column ($y).
for y in $(eval echo {${min_y}..${max_y}})
do
    for x in $(eval echo {${min_x}..${max_x}})
    do  
        xIndex=$((x - min_x))
        yIndex=$((y - min_y))
        tileNo=$(( ((yIndex) * (rows)) + (xIndex) ))
#       echo "Count: ${tileNo} Missing: ${missingTiles} X: ${x}  Y: ${y} xIndx: ${xIndex} yIndx: ${yIndex}" 
        if [ -f $zoomlevel/$x/$y.png ];
        then
            filenames="${filenames} ${zoomlevel}/${x}/${y}.png"
            echo -n "."
        else
            echo -n "B"
#           echo "$zoomlevel/$x/$y.png does not exist, using blank tile"
            filenames="${filenames} ${blankFileName}"
            missingTiles=$(( missingTiles + 1 ))            
        fi
    done
done
echo " DONE"

if [ ${missingTiles} -gt 0 ];
then
    echo -n "Creating blank tile: "
    gm convert -format png -geometry 256x256+0+0 -colorspace RGB xc:none ${blankFileName}
    echo "DONE"
fi

echo -n "Creating Montage (${stitchedFileName})... "
tileSize="${rows}x${columns}"
gmCommand="gm montage ${montageOptions} -tile ${tileSize} -geometry 256x256+0+0 ${filenames} ${stitchedFileName}"
#echo "${gmCommand}"
${gmCommand}
echo "DONE"


if [ ${missingTiles} -gt 0 ];
then
    if [ -f ${blankFileName} ];
    then
        echo -n "Removing blank tile (${blankFileName}): "
        rm ${blankFileName}
        echo "DONE"
    fi
fi
Location: 30th Street, Abu Dhabi, أبو ظبي, United Arab Emirates
Older Entries | Newer Entries