| 1 |
#!/usr/bin/env texlua |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
local http = require("socket.http") |
| 12 |
local ltn12 = require("ltn12") |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
function url_escape(s) |
| 17 |
return (string.gsub(s, "([^A-Za-z0-9_])", function(c) |
| 18 |
return string.format("%%%02x", string.byte(c)) |
| 19 |
end)) |
| 20 |
end |
| 21 |
|
| 22 |
local OSMURL = "http://open.mapquestapi.com/staticmap/v4/getplacemap" |
| 23 |
local GMURL = "http://maps.googleapis.com/maps/api/staticmap" |
| 24 |
local GSVURL = "http://maps.googleapis.com/maps/api/streetview" |
| 25 |
local KEY = "" |
| 26 |
local MODE = "" |
| 27 |
local LOCATION = "" |
| 28 |
local XSIZE = "" |
| 29 |
local CENTER = "" |
| 30 |
local YSIZE = "" |
| 31 |
local SIZE = "" |
| 32 |
local SCALE = "" |
| 33 |
local ZOOM = "" |
| 34 |
local TYPE = "" |
| 35 |
local IMAGETYPE = "" |
| 36 |
local COLOR = "" |
| 37 |
local NUMBER = "" |
| 38 |
local VISIBLE = "" |
| 39 |
local IPATH = "" |
| 40 |
local FPATH = "" |
| 41 |
local MARKERS = "" |
| 42 |
local HEADING = "" |
| 43 |
local FOV = "" |
| 44 |
local PITCH = "" |
| 45 |
local LANGUAGE = "" |
| 46 |
local GPFILE = "" |
| 47 |
local KMLFILE = "" |
| 48 |
local BOUND = 0.1 |
| 49 |
local OFILE = "getmap" |
| 50 |
local QUIET = "false" |
| 51 |
local VERSION = "v1.5a (2018/07/18)" |
| 52 |
|
| 53 |
function pversion() |
| 54 |
print("getmapdl.lua " .. VERSION) |
| 55 |
print("(C) Josef Kleber License: LPPL") |
| 56 |
os.exit(0) |
| 57 |
end |
| 58 |
|
| 59 |
function phelp() |
| 60 |
print([[ |
| 61 |
getmapdl.lua [options] |
| 62 |
|
| 63 |
downloads an OpenStreetMap, Google Maps or Google Street View map |
| 64 |
specified by [options] or parses gpx, gps and kml files to create |
| 65 |
encoded polylines |
| 66 |
|
| 67 |
Options: |
| 68 |
|
| 69 |
-m specify the mode (osm|gm|gsv|gpx2epl|gps2epl|gpx2gps|kml2epl|kml2gps) |
| 70 |
|
| 71 |
-l specify a location |
| 72 |
e.g. 'Bergheimer Straße 110A, 69115 Heidelberg, Germany' |
| 73 |
|
| 74 |
-x specify a xsize (600) |
| 75 |
|
| 76 |
-y specify a ysize (400) |
| 77 |
|
| 78 |
-S short form to specify a size, e.g. 600,400 (osm) or 600x400 (gm) |
| 79 |
|
| 80 |
-s specify a scale factor in the range 1692-221871572 (osm) or |
| 81 |
1-2 (gm) |
| 82 |
|
| 83 |
-z specify a zoom in the range 1-18 (osm) or 0-21 (17) (gm) |
| 84 |
|
| 85 |
-t specify map type {map|sathyb} (map) (osm) or |
| 86 |
{roadmap|satellite|hybrid|terrain} (roadmap) (gm) |
| 87 |
|
| 88 |
-i specify image type {png|gif|jpg|jpeg} (png) (osm) or |
| 89 |
{png|png8|png32|gif|jpg|jpg-baseline} (png) (gm) |
| 90 |
|
| 91 |
-c specify icon color (yelow_1) (osm) or (blue) (gm) |
| 92 |
see: http://open.mapquestapi.com/staticmap/icons.html |
| 93 |
https://developers.google.com/maps/documentation/staticmaps/#MarkerStyles |
| 94 |
|
| 95 |
-n specify the icon number (1) |
| 96 |
|
| 97 |
-o specify output basename without file extension (getmap.IMAGETYPE) |
| 98 |
|
| 99 |
-q quiet; no output! |
| 100 |
|
| 101 |
-v prints version information |
| 102 |
|
| 103 |
-h prints help information |
| 104 |
|
| 105 |
gm mode only: |
| 106 |
|
| 107 |
-L specify the language of map labels (xx language code (en,de,fr,...)) |
| 108 |
|
| 109 |
-M specify markers; see: |
| 110 |
https://developers.google.com/maps/documentation/staticmaps/index#Markers |
| 111 |
e.g.: &markers=size:mid|color:blue|label:1|address or more of these |
| 112 |
location and zoom will be ignored if used! |
| 113 |
|
| 114 |
-C specify center of the map |
| 115 |
|
| 116 |
-V specify a list of visible locations (loc1|loc2) |
| 117 |
|
| 118 |
-P specify path from location to location |
| 119 |
e.g.: &path=weight:7|color:purple|loc1|loc2 |
| 120 |
|
| 121 |
-p specify a file holding the path specification |
| 122 |
(maybe needed for encoded polylines) |
| 123 |
|
| 124 |
gsv mode only: |
| 125 |
|
| 126 |
-H specify heading (view) (0) (0 -- 360) (east: 90, ...) |
| 127 |
|
| 128 |
-T specify the pitch (angle) (0) (-90 -- 90) |
| 129 |
|
| 130 |
-F specify horizontal field of view (90) (0 -- 120) |
| 131 |
The field of view is expressed in degrees and a kind of zoom! |
| 132 |
|
| 133 |
gpx2epl, gps2epl and gpx2gps mode only: |
| 134 |
|
| 135 |
-G specify the gpx or gps file |
| 136 |
|
| 137 |
kml2epl and kml2gps mode only: |
| 138 |
|
| 139 |
-K specify the kml file |
| 140 |
|
| 141 |
gps2gps mode only: |
| 142 |
|
| 143 |
-B specify the bound for reducing way points (default: 0.1) |
| 144 |
|
| 145 |
]]) |
| 146 |
pversion() |
| 147 |
end |
| 148 |
|
| 149 |
function getmap_error(exitcode, errortext) |
| 150 |
io.stderr:write ("Error (" .. exitcode .. "): " .. errortext .. "\n") |
| 151 |
os.exit(exitcode) |
| 152 |
end |
| 153 |
|
| 154 |
function getmap_warning(warningtext) |
| 155 |
io.stderr:write("WARNING: " .. warningtext .. "\n") |
| 156 |
end |
| 157 |
|
| 158 |
function check_number(var, varname) |
| 159 |
if not(string.match(var, '^[-]?[0-9]+$')) then |
| 160 |
getmap_error(2, varname .. " can't be " .. var .. "! Not a number!") |
| 161 |
end |
| 162 |
end |
| 163 |
|
| 164 |
function check_range(var,min,max,exitcode,varname) |
| 165 |
check_number(var,varname) |
| 166 |
if (tonumber(var) < tonumber(min) or tonumber(var) > tonumber(max)) then |
| 167 |
getmap_error(exitcode, varname .. " = " .. var .. "; must be in the range of " .. min .. "-" .. max) |
| 168 |
end |
| 169 |
end |
| 170 |
|
| 171 |
function round(number, precision) |
| 172 |
return math.floor(number*math.pow(10,precision)+0.5) / math.pow(10,precision) |
| 173 |
end |
| 174 |
|
| 175 |
function encodeNumber(number) |
| 176 |
local num = number |
| 177 |
num = num * 2 |
| 178 |
if num < 0 |
| 179 |
then |
| 180 |
num = (num * -1) - 1 |
| 181 |
end |
| 182 |
local t = {} |
| 183 |
while num >= 32 |
| 184 |
do |
| 185 |
local num2 = 32 + (num % 32) + 63 |
| 186 |
table.insert(t,string.char(num2)) |
| 187 |
num = math.floor(num / 32) |
| 188 |
end |
| 189 |
table.insert(t,string.char(num + 63)) |
| 190 |
return table.concat(t) |
| 191 |
end |
| 192 |
|
| 193 |
function printepl(epltable) |
| 194 |
local string = table.concat(epltable) |
| 195 |
|
| 196 |
local stingwithoutcontrolcharacters = string:gsub("%c", "") |
| 197 |
print(stingwithoutcontrolcharacters) |
| 198 |
end |
| 199 |
|
| 200 |
function isnotnumber(number) |
| 201 |
if tonumber(number) == nil then |
| 202 |
return true |
| 203 |
else |
| 204 |
return false |
| 205 |
end |
| 206 |
end |
| 207 |
|
| 208 |
function dbtbound(Onum, num, bound) |
| 209 |
local absdiff = math.abs(tonumber(Onum) - tonumber(num)) |
| 210 |
if absdiff >= tonumber(bound) then |
| 211 |
return true |
| 212 |
else |
| 213 |
return false |
| 214 |
end |
| 215 |
end |
| 216 |
|
| 217 |
do |
| 218 |
local newarg = {} |
| 219 |
local i, limit = 1, #arg |
| 220 |
while (i <= limit) do |
| 221 |
if arg[i] == "-l" then |
| 222 |
LOCATION = arg[i+1] |
| 223 |
i = i + 1 |
| 224 |
elseif arg[i] == "-C" then |
| 225 |
CENTER = arg[i+1] |
| 226 |
i = i + 1 |
| 227 |
elseif arg[i] == "-m" then |
| 228 |
MODE = arg[i+1] |
| 229 |
i = i + 1 |
| 230 |
elseif arg[i] == "-k" then |
| 231 |
KEY = arg[i+1] |
| 232 |
i = i + 1 |
| 233 |
elseif arg[i] == "-x" then |
| 234 |
XSIZE = arg[i+1] |
| 235 |
i = i + 1 |
| 236 |
elseif arg[i] == "-y" then |
| 237 |
YSIZE = arg[i+1] |
| 238 |
i = i + 1 |
| 239 |
elseif arg[i] == "-S" then |
| 240 |
SIZE = arg[i+1] |
| 241 |
i = i + 1 |
| 242 |
elseif arg[i] == "-s" then |
| 243 |
SCALE = arg[i+1] |
| 244 |
i = i + 1 |
| 245 |
elseif arg[i] == "-z" then |
| 246 |
ZOOM = arg[i+1] |
| 247 |
i = i + 1 |
| 248 |
elseif arg[i] == "-t" then |
| 249 |
TYPE = arg[i+1] |
| 250 |
i = i + 1 |
| 251 |
elseif arg[i] == "-i" then |
| 252 |
IMAGETYPE = arg[i+1] |
| 253 |
i = i + 1 |
| 254 |
elseif arg[i] == "-c" then |
| 255 |
COLOR = arg[i+1] |
| 256 |
i = i + 1 |
| 257 |
elseif arg[i] == "-n" then |
| 258 |
NUMBER = arg[i+1] |
| 259 |
i = i + 1 |
| 260 |
elseif arg[i] == "-L" then |
| 261 |
LANGUAGE = arg[i+1] |
| 262 |
i = i + 1 |
| 263 |
elseif arg[i] == "-M" then |
| 264 |
MARKERS = arg[i+1] |
| 265 |
i = i + 1 |
| 266 |
elseif arg[i] == "-H" then |
| 267 |
HEADING = arg[i+1] |
| 268 |
i = i + 1 |
| 269 |
elseif arg[i] == "-T" then |
| 270 |
PITCH = arg[i+1] |
| 271 |
i = i + 1 |
| 272 |
elseif arg[i] == "-F" then |
| 273 |
FOV = arg[i+1] |
| 274 |
i = i + 1 |
| 275 |
elseif arg[i] == "-V" then |
| 276 |
VISIBLE = arg[i+1] |
| 277 |
i = i + 1 |
| 278 |
elseif arg[i] == "-P" then |
| 279 |
IPATH = arg[i+1] |
| 280 |
i = i + 1 |
| 281 |
elseif arg[i] == "-p" then |
| 282 |
FPATH = arg[i+1] |
| 283 |
i = i + 1 |
| 284 |
elseif arg[i] == "-G" then |
| 285 |
GPFILE = arg[i+1] |
| 286 |
i = i + 1 |
| 287 |
elseif arg[i] == "-K" then |
| 288 |
KMLFILE = arg[i+1] |
| 289 |
i = i + 1 |
| 290 |
elseif arg[i] == "-B" then |
| 291 |
BOUND = arg[i+1] |
| 292 |
i = i + 1 |
| 293 |
elseif arg[i] == "-o" then |
| 294 |
OFILE = arg[i+1] |
| 295 |
i = i + 1 |
| 296 |
elseif arg[i] == "-q" then |
| 297 |
QUIET = 1 |
| 298 |
elseif arg[i] == "-v" then |
| 299 |
pversion() |
| 300 |
elseif arg[i] == "-h" then |
| 301 |
phelp() |
| 302 |
else |
| 303 |
newarg[#newarg+1] = arg[i] |
| 304 |
end |
| 305 |
i = i + 1 |
| 306 |
end |
| 307 |
arg = newarg |
| 308 |
end |
| 309 |
|
| 310 |
if QUIET == 1 then |
| 311 |
getmap_warning("-q option currently not supported!") |
| 312 |
end |
| 313 |
|
| 314 |
if MODE == "gpx2epl" then |
| 315 |
local file = GPFILE |
| 316 |
local name |
| 317 |
local desc |
| 318 |
local Olatitude = 0 |
| 319 |
local Olongitude = 0 |
| 320 |
local epl = {} |
| 321 |
|
| 322 |
for line in io.lines(file) |
| 323 |
do |
| 324 |
local latitude |
| 325 |
local longitude |
| 326 |
local encnum |
| 327 |
|
| 328 |
if string.match(line, "<trk>") then |
| 329 |
Olatitude = 0 |
| 330 |
Olongitude = 0 |
| 331 |
name = "" |
| 332 |
desc = "" |
| 333 |
epl = {} |
| 334 |
end |
| 335 |
if string.match(line, "<name") then |
| 336 |
name = string.match(line, '<name>(.-)</name>') |
| 337 |
if name == nil then |
| 338 |
name = "Name (E)" |
| 339 |
end |
| 340 |
end |
| 341 |
if string.match(line, "<desc") then |
| 342 |
desc = string.match(line, '<desc>(.-)</desc>') |
| 343 |
if desc == nil then |
| 344 |
desc = "" |
| 345 |
end |
| 346 |
end |
| 347 |
if string.match(line, "<trkseg") then |
| 348 |
print("Route: " .. name .. " [" .. desc .. "]") |
| 349 |
end |
| 350 |
if string.match(line, "<trkpt") then |
| 351 |
latitude = string.match(line, 'lat="(.-)"') |
| 352 |
longitude = string.match(line, 'lon="(.-)"') |
| 353 |
latitude = round(latitude,5)*100000 |
| 354 |
longitude = round(longitude,5)*100000 |
| 355 |
encnum = encodeNumber(latitude - Olatitude) |
| 356 |
table.insert(epl,encnum) |
| 357 |
encnum = encodeNumber(longitude - Olongitude) |
| 358 |
table.insert(epl,encnum) |
| 359 |
Olatitude = latitude |
| 360 |
Olongitude = longitude |
| 361 |
end |
| 362 |
if string.match(line, "</trk>") then |
| 363 |
printepl(epl) |
| 364 |
print("\n") |
| 365 |
end |
| 366 |
end |
| 367 |
os.exit(0) |
| 368 |
end |
| 369 |
|
| 370 |
if MODE == "gpx2gps" then |
| 371 |
local file = GPFILE |
| 372 |
local name |
| 373 |
local desc |
| 374 |
|
| 375 |
for line in io.lines(file) |
| 376 |
do |
| 377 |
local latitude |
| 378 |
local longitude |
| 379 |
local encnum |
| 380 |
|
| 381 |
if string.match(line, "<trk>") then |
| 382 |
name = "" |
| 383 |
desc = "" |
| 384 |
end |
| 385 |
if string.match(line, "<name") then |
| 386 |
name = string.match(line, '<name>(.-)</name>') |
| 387 |
if name == nil then |
| 388 |
name = "Name (E)" |
| 389 |
end |
| 390 |
end |
| 391 |
if string.match(line, "<desc") then |
| 392 |
desc = string.match(line, '<desc>(.-)</desc>') |
| 393 |
if desc == nil then |
| 394 |
desc = "" |
| 395 |
end |
| 396 |
end |
| 397 |
if string.match(line, "<trkseg") then |
| 398 |
print("Route: " .. name .. " [" .. desc .. "]") |
| 399 |
end |
| 400 |
if string.match(line, "<trkpt") then |
| 401 |
latitude = string.match(line, 'lat="(.-)"') |
| 402 |
longitude = string.match(line, 'lon="(.-)"') |
| 403 |
latitude = round(latitude,5) |
| 404 |
longitude = round(longitude,5) |
| 405 |
print(latitude .. "," .. longitude) |
| 406 |
end |
| 407 |
if string.match(line, "</trk>") then |
| 408 |
print("\n") |
| 409 |
end |
| 410 |
end |
| 411 |
os.exit(0) |
| 412 |
end |
| 413 |
|
| 414 |
if MODE == "gps2gps" then |
| 415 |
local file = GPFILE |
| 416 |
local bound = BOUND |
| 417 |
local incount = 0 |
| 418 |
local outcount = 0 |
| 419 |
local routecount = 1 |
| 420 |
local latitude |
| 421 |
local longitude |
| 422 |
local Olatitude |
| 423 |
local Olongitude |
| 424 |
local Llatitude |
| 425 |
local Llongitude |
| 426 |
local ignorenextline = false |
| 427 |
local firstroute = true |
| 428 |
|
| 429 |
for line in io.lines(file) |
| 430 |
do |
| 431 |
latitude, longitude = line:match("([^,]+),([^,]+)") |
| 432 |
if ignorenextline == true then |
| 433 |
line = "" |
| 434 |
ignorenextline = false |
| 435 |
end |
| 436 |
|
| 437 |
|
| 438 |
if line:match("Point:") then |
| 439 |
ignorenextline = true |
| 440 |
end |
| 441 |
if line:match("Route:") then |
| 442 |
if firstroute == true then |
| 443 |
firstroute = false |
| 444 |
routecount = 0 |
| 445 |
else |
| 446 |
|
| 447 |
print(Llatitude .. "," .. Llongitude) |
| 448 |
outcount = outcount + 1 |
| 449 |
io.stderr:write("\nRoute " .. routecount .. ": reduced gps coordinates (Bound = " .. bound .. "): " .. incount .. " -> " .. outcount) |
| 450 |
end |
| 451 |
incount = 0 |
| 452 |
outcount = 0 |
| 453 |
routecount = routecount + 1 |
| 454 |
print("\n" .. line .. "\n") |
| 455 |
line = "" |
| 456 |
end |
| 457 |
if line == "" or isnotnumber(latitude) or isnotnumber(longitude) |
| 458 |
then |
| 459 |
|
| 460 |
else |
| 461 |
latitude = round(latitude,5) |
| 462 |
longitude = round(longitude,5) |
| 463 |
Llatitude = latitude |
| 464 |
Llongitude = longitude |
| 465 |
incount = incount + 1 |
| 466 |
if incount == 1 then |
| 467 |
Olatitude = latitude |
| 468 |
Olongitude = longitude |
| 469 |
print(Olatitude .. "," .. Olongitude) |
| 470 |
outcount = outcount + 1 |
| 471 |
else |
| 472 |
if dbtbound(Olatitude,latitude,bound) or dbtbound(Olongitude,longitude,bound) then |
| 473 |
print(latitude .. "," .. longitude) |
| 474 |
outcount = outcount + 1 |
| 475 |
Olatitude = latitude |
| 476 |
Olongitude = longitude |
| 477 |
end |
| 478 |
end |
| 479 |
end |
| 480 |
end |
| 481 |
|
| 482 |
print(Llatitude .. "," .. Llongitude) |
| 483 |
outcount = outcount + 1 |
| 484 |
io.stderr:write("\nRoute " .. routecount .. ": reduced gps coordinates (Bound = " .. bound .. "): " .. incount .. " -> " .. outcount) |
| 485 |
os.exit(0) |
| 486 |
end |
| 487 |
|
| 488 |
if MODE == "gps2epl" then |
| 489 |
local file = GPFILE |
| 490 |
local Olatitude = 0 |
| 491 |
local Olongitude = 0 |
| 492 |
local epl = {} |
| 493 |
local firstroute = true |
| 494 |
|
| 495 |
for line in io.lines(file) |
| 496 |
do |
| 497 |
local latitude |
| 498 |
local longitude |
| 499 |
local encnum |
| 500 |
|
| 501 |
latitude, longitude = line:match("([^,]+),([^,]+)") |
| 502 |
if ignorenextline == true then |
| 503 |
line = "" |
| 504 |
ignorenextline = false |
| 505 |
end |
| 506 |
|
| 507 |
|
| 508 |
if line:match("Point:") then |
| 509 |
ignorenextline = true |
| 510 |
end |
| 511 |
if line:match("Route:") then |
| 512 |
if firstroute == true then |
| 513 |
firstroute = false |
| 514 |
else |
| 515 |
printepl(epl) |
| 516 |
Olatitude = 0 |
| 517 |
Olongitude = 0 |
| 518 |
epl = {} |
| 519 |
end |
| 520 |
print("\n" .. line .. "\n") |
| 521 |
line = "" |
| 522 |
end |
| 523 |
if line == "" or isnotnumber(latitude) or isnotnumber(longitude) |
| 524 |
then |
| 525 |
|
| 526 |
else |
| 527 |
latitude = round(latitude,5)*100000 |
| 528 |
longitude = round(longitude,5)*100000 |
| 529 |
encnum = encodeNumber(latitude - Olatitude) |
| 530 |
table.insert(epl,encnum) |
| 531 |
encnum = encodeNumber(longitude - Olongitude) |
| 532 |
table.insert(epl,encnum) |
| 533 |
Olatitude = latitude |
| 534 |
Olongitude = longitude |
| 535 |
end |
| 536 |
end |
| 537 |
printepl(epl) |
| 538 |
os.exit(0) |
| 539 |
end |
| 540 |
|
| 541 |
if MODE == "kml2gps" or MODE == "kml2epl" then |
| 542 |
local file = KMLFILE |
| 543 |
local name |
| 544 |
local cdata |
| 545 |
local cotype |
| 546 |
local Olatitude = 0 |
| 547 |
local Olongitude = 0 |
| 548 |
local epl = {} |
| 549 |
|
| 550 |
for line in io.lines(file) |
| 551 |
do |
| 552 |
local latitude |
| 553 |
local longitide |
| 554 |
local elevation |
| 555 |
|
| 556 |
|
| 557 |
if string.match(line, "<Placemark>") then |
| 558 |
Olatitude = 0 |
| 559 |
Olongitude = 0 |
| 560 |
cotype = nil |
| 561 |
epl = {} |
| 562 |
end |
| 563 |
if string.match(line, "<name>") then |
| 564 |
name = string.match(line, '<name>(.-)</name>') |
| 565 |
if name == nil then |
| 566 |
name = "Name (E)" |
| 567 |
end |
| 568 |
end |
| 569 |
if string.match(line, "CDATA") then |
| 570 |
cdata = string.match(line, 'CDATA%[(.-)%]') |
| 571 |
if cdata == nil then |
| 572 |
cdata = "" |
| 573 |
end |
| 574 |
end |
| 575 |
if string.match(line, "<Point>") then |
| 576 |
cotype = "point" |
| 577 |
end |
| 578 |
if string.match(line, "<LineString>") then |
| 579 |
cotype = "route" |
| 580 |
end |
| 581 |
if cotype == "point" or cotype == "route" then |
| 582 |
if string.match(line, "<coordinates>") then |
| 583 |
local colist = string.match(line, '<coordinates>(.-)</coordinates>') |
| 584 |
if cotype == "route" then |
| 585 |
print("Route: " .. name) |
| 586 |
else |
| 587 |
print("Point: " .. name .. " [" .. cdata .. "]") |
| 588 |
end |
| 589 |
for cocsv in string.gmatch(colist, "%S+") do |
| 590 |
longitude, latitude, altitude = cocsv:match("([^,]+),([^,]+),([^,]+)") |
| 591 |
latitude = round(latitude,5) |
| 592 |
longitude = round(longitude,5) |
| 593 |
if MODE == "kml2epl" then |
| 594 |
local encnum |
| 595 |
if cotype == "route" then |
| 596 |
latitude = latitude*100000 |
| 597 |
longitude = longitude*100000 |
| 598 |
encnum = encodeNumber(latitude - Olatitude) |
| 599 |
table.insert(epl,encnum) |
| 600 |
encnum = encodeNumber(longitude - Olongitude) |
| 601 |
table.insert(epl,encnum) |
| 602 |
Olatitude = latitude |
| 603 |
Olongitude = longitude |
| 604 |
else |
| 605 |
print(latitude .. "," .. longitude) |
| 606 |
end |
| 607 |
else |
| 608 |
print(latitude .. "," .. longitude) |
| 609 |
end |
| 610 |
end |
| 611 |
if MODE == "kml2epl" and cotype == "route" then |
| 612 |
printepl(epl) |
| 613 |
end |
| 614 |
print("\n") |
| 615 |
end |
| 616 |
end |
| 617 |
end |
| 618 |
os.exit(0) |
| 619 |
end |
| 620 |
|
| 621 |
print("\n") |
| 622 |
|
| 623 |
if KEY == "" then |
| 624 |
if MODE == "osm" then |
| 625 |
KEY="Kmjtd|luu7n162n1,22=o5-h61wh" |
| 626 |
getmap_warning("KEY not specified; using mapquest example key as default!") |
| 627 |
end |
| 628 |
end |
| 629 |
|
| 630 |
if LOCATION == "" then |
| 631 |
LOCATION = "Bergheimer Straße 110A, 69115 Heidelberg, Germany" |
| 632 |
getmap_warning("LOCATION not specified; using Dante e.V. Office as default!") |
| 633 |
end |
| 634 |
|
| 635 |
if MODE == "gm" then |
| 636 |
if ZOOM == "" then |
| 637 |
ZOOM=17 |
| 638 |
getmap_warning("ZOOM not specified; using ZOOM=17 as default!") |
| 639 |
end |
| 640 |
end |
| 641 |
|
| 642 |
if XSIZE == "" then |
| 643 |
XSIZE=600 |
| 644 |
getmap_warning("XSIZE not specified; using XSIZE=600 as default!") |
| 645 |
end |
| 646 |
|
| 647 |
if YSIZE == "" then |
| 648 |
YSIZE=400 |
| 649 |
getmap_warning("YSIZE not specified; using YSIZE=400 as default!") |
| 650 |
end |
| 651 |
|
| 652 |
if SIZE == "" then |
| 653 |
if MODE == "gm" then |
| 654 |
SIZE = XSIZE .. "x" .. YSIZE |
| 655 |
elseif MODE == "gsv" then |
| 656 |
SIZE = XSIZE .. "x" .. YSIZE |
| 657 |
elseif MODE == "osm" then |
| 658 |
SIZE = XSIZE .. "," .. YSIZE |
| 659 |
end |
| 660 |
end |
| 661 |
|
| 662 |
if SCALE == "" then |
| 663 |
if MODE == "gm" then |
| 664 |
SCALE=1 |
| 665 |
getmap_warning("SCALE not specified, using SCALE=1 as default!") |
| 666 |
elseif MODE == "osm" then |
| 667 |
if ZOOM == "" then |
| 668 |
SCALE=3385 |
| 669 |
getmap_warning("SCALE not specified, using SCALE=3385 as default!") |
| 670 |
end |
| 671 |
end |
| 672 |
end |
| 673 |
|
| 674 |
if TYPE == "" then |
| 675 |
if MODE == "gm" then |
| 676 |
TYPE = "roadmap" |
| 677 |
getmap_warning("TYPE not specified; using roadmap as default!") |
| 678 |
elseif MODE == "osm" then |
| 679 |
TYPE = "map" |
| 680 |
getmap_warning("TYPE not specified; using map as default!") |
| 681 |
end |
| 682 |
end |
| 683 |
|
| 684 |
if IMAGETYPE == "" then |
| 685 |
if MODE == "gsv" then |
| 686 |
else |
| 687 |
IMAGETYPE="png" |
| 688 |
getmap_warning("IMAGETYPE not specified; using png as default!") |
| 689 |
end |
| 690 |
end |
| 691 |
|
| 692 |
if COLOR == "" then |
| 693 |
if MODE == "gm" then |
| 694 |
COLOR="blue" |
| 695 |
getmap_warning("COLOR not specified; using blue as default!") |
| 696 |
elseif MODE == "osm" then |
| 697 |
COLOR="yellow_1" |
| 698 |
getmap_warning("COLOR not specified; using yellow_1 as default!") |
| 699 |
end |
| 700 |
end |
| 701 |
|
| 702 |
if NUMBER == "" then |
| 703 |
if MODE == "gsv" then |
| 704 |
else |
| 705 |
NUMBER=1 |
| 706 |
getmap_warning("NUMBER not specified; using 1 as default!") |
| 707 |
end |
| 708 |
end |
| 709 |
|
| 710 |
if MODE == "gsv" then |
| 711 |
if HEADING == "" then |
| 712 |
HEADING=0 |
| 713 |
getmap_warning("HEADING not specified; using 0 as default!") |
| 714 |
end |
| 715 |
|
| 716 |
if FOV == "" then |
| 717 |
FOV=90 |
| 718 |
getmap_warning("FOV not specified; using 90 as default!") |
| 719 |
end |
| 720 |
|
| 721 |
if PITCH == "" then |
| 722 |
PITCH=0 |
| 723 |
getmap_warning("PITCH not specified; using 0 as default!") |
| 724 |
end |
| 725 |
end |
| 726 |
|
| 727 |
if MODE == "gm" then |
| 728 |
if ZOOM == "" then |
| 729 |
ZOOM = 17 |
| 730 |
else |
| 731 |
check_range(ZOOM,0,21,11,"ZOOM") |
| 732 |
end |
| 733 |
check_range(XSIZE,1,640,12,"XSIZE") |
| 734 |
check_range(YSIZE,1,640,13,"YSIZE") |
| 735 |
check_range(SCALE,1,2,14,"SCALE") |
| 736 |
elseif MODE == "gsv" then |
| 737 |
check_range(XSIZE,1,640,12,"XSIZE") |
| 738 |
check_range(YSIZE,1,640,13,"YSIZE") |
| 739 |
check_range(HEADING,0,360,15,"HEADING") |
| 740 |
check_range(FOV,0,120,16,"FOV") |
| 741 |
check_range(PITCH,-90,90,17,"PITCH") |
| 742 |
elseif MODE == "osm" then |
| 743 |
check_range(XSIZE,1,3840,11,"XSIZE") |
| 744 |
check_range(YSIZE,1,3840,12,"YSIZE") |
| 745 |
if ZOOM == "" then |
| 746 |
check_range(SCALE,1692,221871572,13,"SCALE") |
| 747 |
else |
| 748 |
check_range(ZOOM,1,18,14,"ZOOM") |
| 749 |
end |
| 750 |
check_number(NUMBER,"NUMBER") |
| 751 |
end |
| 752 |
|
| 753 |
local UKEY = "" |
| 754 |
local ULOCATION = "" |
| 755 |
local UZOOM = "" |
| 756 |
local USCALEZOOM = "" |
| 757 |
local UMARKERS = "" |
| 758 |
local USIZE = "" |
| 759 |
local USCALE = "" |
| 760 |
local UTYPE = "" |
| 761 |
local USHOWICON = "" |
| 762 |
local UIMAGETYPE = "" |
| 763 |
local UVISIBLE = "" |
| 764 |
local UIPATH = "" |
| 765 |
local UFPATH = "" |
| 766 |
local EPLFILE = "" |
| 767 |
local UHEADING = "" |
| 768 |
local UFOV = "" |
| 769 |
local UPITCH = "" |
| 770 |
local ULANGUAGE = "" |
| 771 |
local UOFILE = "" |
| 772 |
local IMGURL = "" |
| 773 |
|
| 774 |
if MODE == "gm" then |
| 775 |
ULOCATION = "center=" .. url_escape(LOCATION) |
| 776 |
if MARKERS == "" then |
| 777 |
UMARKERS = "&markers=size:mid|color:" .. COLOR .. "|label:" .. NUMBER .. "|" .. url_escape(LOCATION) |
| 778 |
UZOOM = "&zoom=" .. url_escape(ZOOM) |
| 779 |
else |
| 780 |
UMARKERS = "" .. url_escape(MARKERS) |
| 781 |
|
| 782 |
UMARKERS = UMARKERS:gsub("%%26markers%%3d","&markers=") |
| 783 |
UZOMM = "" |
| 784 |
if CENTER == "" then |
| 785 |
ULOCATION = "" |
| 786 |
else |
| 787 |
ULOCATION = "center=" .. url_escape(CENTER) |
| 788 |
end |
| 789 |
end |
| 790 |
USIZE = "&size=" .. url_escape(SIZE) |
| 791 |
USCALE = "&scale=" .. url_escape(SCALE) |
| 792 |
UTYPE = "&maptype=" .. url_escape(TYPE) |
| 793 |
UIMAGETYPE = "&format=" .. url_escape(IMAGETYPE) |
| 794 |
if IMAGETYPE == "jpg-baseline" then |
| 795 |
IMAGETYPE = "jpg" |
| 796 |
end |
| 797 |
if VISIBLE == "" then |
| 798 |
UVISIBLE = "" |
| 799 |
else |
| 800 |
UVISIBLE = "&visible=" .. url_escape(VISIBLE) |
| 801 |
end |
| 802 |
if IPATH == "" then |
| 803 |
UIPATH = "" |
| 804 |
else |
| 805 |
UIPATH = "" .. url_escape(IPATH) |
| 806 |
|
| 807 |
UIPATH = UIPATH:gsub("%%26path%%3d","&path=") |
| 808 |
end |
| 809 |
if FPATH == "" then |
| 810 |
UFPATH = "" |
| 811 |
else |
| 812 |
EPLFILE = io.open(FPATH, "r") |
| 813 |
local contents = EPLFILE:read() |
| 814 |
EPLFILE:close() |
| 815 |
UFPATH = "" .. url_escape(contents) |
| 816 |
|
| 817 |
UFPATH = UFPATH:gsub("%%26path%%3d","&path=") |
| 818 |
end |
| 819 |
if LANGUAGE == "" then |
| 820 |
ULANGUAGE="" |
| 821 |
else |
| 822 |
ULANGUAGE="&language=" .. LANGUAGE |
| 823 |
end |
| 824 |
UOFILE = OFILE .. "." .. IMAGETYPE |
| 825 |
IMGURL = GMURL .. "?" .. ULOCATION .. USIZE .. UZOOM .. UMARKERS .. UTYPE .. USCALE .. UIMAGETYPE .. UVISIBLE .. UIPATH .. UFPATH .. ULANGUAGE .. "&sensor=false&key=AIzaSyDXlmAP7TENopGqgCkW9Ec3Wymno3a2cBg" |
| 826 |
elseif MODE == "gsv" then |
| 827 |
ULOCATION = "location=" .. url_escape(LOCATION) |
| 828 |
USIZE = "&size=" .. url_escape(SIZE) |
| 829 |
UHEADING = "&heading=" .. url_escape(HEADING) |
| 830 |
UFOV = "&fov=" .. url_escape(FOV) |
| 831 |
UPITCH = "&pitch=" .. url_escape(PITCH) |
| 832 |
UOFILE = OFILE .. ".jpg" |
| 833 |
IMGURL = GSVURL .. "?" .. ULOCATION .. USIZE .. UHEADING .. UFOV .. UPITCH .. "&sensor=false&key=AIzaSyDXlmAP7TENopGqgCkW9Ec3Wymno3a2cBg" |
| 834 |
elseif MODE == "osm" then |
| 835 |
UKEY = "?key=" .. url_escape(KEY) |
| 836 |
ULOCATION = "&location=" .. url_escape(LOCATION) |
| 837 |
USIZE = "&size=" .. url_escape(SIZE) |
| 838 |
if ZOOM == "" then |
| 839 |
USCALEZOOM = "&scale=" .. url_escape(SCALE) |
| 840 |
else |
| 841 |
USCALEZOOM = "&zoom=" .. url_escape(ZOOM) |
| 842 |
end |
| 843 |
UTYPE = "&type=" .. url_escape(TYPE) |
| 844 |
UIMAGETYPE = "&imagetype=" .. url_escape(IMAGETYPE) |
| 845 |
USHOWICON = "&showicon=" .. url_escape(COLOR) .. "-" .. url_escape(NUMBER) |
| 846 |
UOFILE = OFILE .. "." .. IMAGETYPE |
| 847 |
IMGURL = OSMURL .. UKEY .. ULOCATION .. USIZE .. USCALEZOOM .. UTYPE .. UIMAGETYPE .. USHOWICON |
| 848 |
end |
| 849 |
|
| 850 |
local ret, msg |
| 851 |
local ofile |
| 852 |
ofile, msg = io.open(UOFILE, "wb") |
| 853 |
if not ofile then |
| 854 |
getmap_error(21, msg) |
| 855 |
end |
| 856 |
print("\n\ngetmapdl.lua:") |
| 857 |
print("url = " .. IMGURL) |
| 858 |
print("url length = " .. string.len(IMGURL) .. " bytes") |
| 859 |
print("output = " .. UOFILE) |
| 860 |
if string.len(IMGURL) > 2048 then |
| 861 |
getmap_error(23, "URL exceeds length limit of 2048 bytes!") |
| 862 |
end |
| 863 |
ret, msg = http.request{ |
| 864 |
url = IMGURL, |
| 865 |
sink = ltn12.sink.file(ofile) |
| 866 |
} |
| 867 |
if not ret then |
| 868 |
getmap_error(22, msg) |
| 869 |
end |
| 870 |
os.exit(0) |