So, heute hatte ich endlich mal wieder Zeit und Lust etwas zu programmieren. Heraus kam dabei das osmimage.sh
Bash-Script.
Das Script lädt ein Bild basierend auf den Daten von https://www.openstreetmap.org mit Hilfe der angegebenen Optionen (siehe osmimage.sh -h)!
In einem weiteren Schritt soll das Script Teil eines LaTeX-Pakets werden, das mit Hilfe von \write18
ein Bild zur Einbindung in ein LaTeX-Dokument bereitstellt!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
#!/bin/bash # # osmimage.sh [options] # # downloads an OpenStreetMap map specified by [options] # by using https://developer.mapquest.com/ web service # # License: LPPL # pversion() { echo "`basename $0` $VERSION" echo "(C) Josef Kleber License: LPPL" exit 0; } # function phelp() { echo -e \ "\n `basename $0` [options]\n\n"\ " downloads an OpenStreetMap map specified by [options]\n"\ " by using https://developer.mapquest.com/ web service\n\n"\ " Options:\n\n"\ " -k key registered by https://developer.mapquest.com/\n"\ " default (Example key from web site)!\n"\ " Please register and use your own key!\n\n"\ " -l specify a location\n"\ " e.g. 'Bergheimer Straße 110A, 69115 Heidelberg, Germany'\n\n"\ " -x specify a xsize (800)\n\n"\ " -y specify a ysize (400)\n\n"\ " -s short form to specify a size, e.g. 800,400\n\n"\ " -z specify a zoom in the range 1-18 (17)\n\n"\ " -t specify map type {map|sat|hyb} (map)\n\n"\ " -i specify image type {jpeg|jpg|gif|png} (png)\n\n"\ " -c specify a icon color (yellow_1)\n"\ " see: https://open.mapquestapi.com/staticmap/icons.html\n\n"\ " -n specify the icon number (1)\n\n"\ " -o specify output basename without file extension (osmimage.IMAGETYPE)\n\n"\ " -q quiet; no output!\n\n"\ " -v prints version information\n\n"\ " -h prints help information\n\n" pversion } # check_prog() { local prog="$1" hash $prog 2>/dev/null || { echo >&2 "Error (1): $prog not installed! Aborting."; exit 1; } } # check_range() { local var="$1" local min="$2" local max="$3" local exitcode="$4" local varname="$5" if [ $var -lt $min ] then echo "Error ($exitcode): $varname = $var; must be in the range of $min-$max" exit $exitcode fi if [ $var -gt $max ] then echo "Error ($exitcode): $varname = $var; must be in the range of $min-$max" exit $exitcode fi } # check_prog wget # URL="https://open.mapquestapi.com/staticmap/v4/getplacemap" KEY="" LOCATION="" # not larger than 3840 XSIZE="" YSIZE="" # 1 <= ZOOM <= 18 ZOOM="" # TYPE={map|sat|hyb} TYPE="" # IMAGETYPE={jpg|jpeg|gif|png} IMAGETYPE="" COLOR="" NUMBER="" OFILE="osmimage" QUIET="false" VERSION="v1.0 (17/05/2014)" # while getopts "k:l:x:y:s:z:t:i:c:n:o:qvh" flag do case "$flag" in k) KEY="$OPTARG";; l) LOCATION="$OPTARG";; x) XSIZE="$OPTARG";; y) YSIZE="$OPTARG";; s) SIZE="$OPTARG";; z) ZOOM="$OPTARG";; t) TYPE="$OPTARG";; i) IMAGETYPE="$OPTARG";; c) COLOR="$OPTARG";; n) NUMBER="$OPTARG";; o) OFILE="$OPTARG";; q) QUIET="true";; v) pversion;; h) phelp;; esac done # if [ "$QUIET" = "true" ] then exec 1>/dev/null exec 2>/dev/null fi # if [ -z $KEY ] then KEY="Kmjtd%7Cluu7n162n1%2C22%3Do5-h61wh" echo "WARNING:" echo "KEY not specified; using mapquest example key as default!" echo "This might not work forever! Register at https://developer.mapquest.com and use your own key!" echo fi # if [ -z $LOCATION ] then LOCATION="Bergheimer Straße 110A, 69115 Heidelberg, Germany" echo "WARNING:" echo "LOCATION not specified; using Dante e.V. Office as default!" echo fi # if [ -z $XSIZE ] then XSIZE=800 echo "WARNING:" echo "XSIZE not specified; using XSIZE=800 as default!" echo fi check_range $XSIZE 1 3840 11 XSIZE # if [ -z $YSIZE ] then YSIZE=400 echo "WARNING:" echo "YSIZE not specified; using YSIZE=400 as default!" echo fi check_range $YSIZE 1 3840 12 YSIZE # if [ -z $SIZE ] then SIZE="$XSIZE,$YSIZE" fi # if [ -z $ZOOM ] then ZOOM=17 echo "WARNING:" echo "ZOOM not specified, using ZOOM=17 as default!" echo fi check_range $ZOOM 1 18 13 ZOOM # if [ -z $TYPE ] then TYPE="map" echo "WARNING:" echo "TYPE not specified; using map as default!" echo fi # if [ -z $IMAGETYPE ] then IMAGETYPE="png" echo "WARNING:" echo "IMAGETYPE not specified; using png as default!" echo fi # if [ -z $COLOR ] then COLOR="yellow_1" echo "WARNING:" echo "COLOR not specified; using yellow_1 as default!" echo fi if [ -z $NUMBER ] then NUMBER=1 echo "WARNING:" echo "NUMBER not specified; using 1 as default!" echo fi # ULOCATION="&location=$LOCATION" USIZE="&size=$SIZE" UZOOM="&zoom=$ZOOM" UTYPE="&type=$TYPE" UIMAGETYPE="&imagetype=$IMAGETYPE" USHOWICON="&showicon=${COLOR}-${NUMBER}" UOFILE="${OFILE}.${IMAGETYPE}" IMGURL="${URL}?key=${KEY}${ULOCATION}${USIZE}${UZOOM}${UTYPE}${UIMAGETYPE}${USHOWICON}" # wget "$IMGURL" -O "$UOFILE" exit 0 |