#!/usr/bin/gawk -f # Hilfsfunktion für den Tangens function tan(x) { return sin(x) / cos(x) } # Hilfsfunktion für den hyperbolischen Sinus (asinh) function asinh(x) { return log(x + sqrt(x*x + 1)) } # Umrechnung von Längengrad zu Kachel-X function lon2tilex(lon, z) { return int(int(floor((lon + 180.0) / 360.0 * (2^z)))) } # Umrechnung von Breitengrad zu Kachel-Y function lat2tiley(lat, z) { # M_PI ist ca. 3.141592653589793 latrad = lat * 3.141592653589793 / 180.0 return int(int(floor((1.0 - asinh(tan(latrad)) / 3.141592653589793) / 2.0 * (2^z)))) } # Mathematische Hilfsfunktion für die Abrundung function floor(x) { y = int(x) return (x < y) ? y - 1 : y } BEGIN { # Standardwerte setzen, falls Umgebungsvariablen nicht existieren PREFIX = (ENVIRON["TILE_PREFIX"] != "") ? ENVIRON["TILE_PREFIX"] : "" SUFFIX = (ENVIRON["TILE_SUFFIX"] != "") ? ENVIRON["TILE_SUFFIX"] : "" SEPARATOR = (ENVIRON["TILE_SEPARATOR"] != "") ? ENVIRON["TILE_SEPARATOR"] : "/" Z_START = (ENVIRON["TILE_ZOOM_START"] != "") ? int(ENVIRON["TILE_ZOOM_START"]) : 1 Z_STOP = (ENVIRON["TILE_ZOOM_STOP"] != "") ? int(ENVIRON["TILE_ZOOM_STOP"]) : 17 LON_START = (ENVIRON["TILE_LON_START"] != "") ?0+ENVIRON["TILE_LON_START"] : -180.0 LON_STOP = (ENVIRON["TILE_LON_STOP"] != "") ?0+ENVIRON["TILE_LON_STOP"] : 180.0 LAT_START = (ENVIRON["TILE_LAT_START"] != "") ?0+ENVIRON["TILE_LAT_START"] : -85.0 LAT_STOP = (ENVIRON["TILE_LAT_STOP"] != "") ?0+ENVIRON["TILE_LAT_STOP"] : 85.0 # Hauptschleife über Zoomstufen und Koordinaten for (z = Z_START; z <= Z_STOP; z++) { a_min = lon2tilex(LON_START, z) a_max = lon2tilex(LON_STOP, z) b_max = lat2tiley(LAT_START, z) b_min = lat2tiley(LAT_STOP, z) # Ausgabe von Debug-Informationen auf stderr (wie im C-Code) printf("processing %d %d %d %d %d %f %f %f %f\n", \ z, a_min, a_max, b_min, b_max, LON_START, LON_STOP, LAT_START, LAT_STOP) > "/dev/stderr" # Schleife für die Kachel-Generierung for (x = a_min; x <= a_max; x++) { for (y = b_min; y <= b_max; y++) { printf("%s%d%s%d%s%d%s\n", PREFIX, z, SEPARATOR, x, SEPARATOR, y, SUFFIX) } } } exit }