# Perl script to convert Google maps tiles to the DSmaps naming convention # use File::Copy ; use File::Path ; # open our gtiles directory, read the files in there into an array # and chop off the first two entries (. and ..) opendir(gtiles, gtiles) or die "can't open dir: $!" ; @files = readdir(gtiles) ; shift(@files) ; shift(@files) ; # for each file, figure out the name in the DSmaps format and copy to that for $g (@files) { $file = $g ; $filename = $file ; substr($filename, -4, 4) = "" ; # chop the extension off the end of the file so we just have the qrst data %qrst = ( "q" => '00', "r" => '10', "s" => '11', "t" => '01'); # coords for each letter @filesplit = split(//, substr($filename, 1)) ; # split it up into individual letters, ignoring the first one # calculate the X, Y, and Zoom values from the qrst values $x = 0 ; $y = 0 ; $z = 17 ; for $i (@filesplit) { $x = $x * 2 + substr($qrst{"$i"}, 0, 1) ; $y = $y * 2 + substr($qrst{"$i"}, 1, 1) ; $z = $z - 1 ; } # convert to hex for DSmaps $zoomdec = $z ; $x = sprintf("%X", $x) ; $y = sprintf("%X", $y) ; $z = sprintf("%02X", $z) ; $xx = "000" ; $yy = "000" ; while (length($x) > 2) { $xx = $xx . substr($x, 0, 1) ; substr($x, 0, 1) = "" ; substr($xx, 0, 1) = "" ; } while (length($y) > 2) { $yy = $yy . substr($y, 0, 1) ; substr($y, 0, 1) = "" ; substr($yy, 0, 1) = "" ; } if (substr($x, 0, 1) eq 0) { if (length($x) > 1 ) { substr($x, 0, 1) = "" ; }} if (substr($y, 0, 1) eq 0) { if (length($y) > 1) { substr($y, 0, 1) = "" ; }} # create the directory and file from what we just figured out mkpath(["$x\\$y"]); $destfile = "$x\\$y\\$xx$yy$z.GMT" ; $startfile = "gtiles\\$file" ; print "$startfile, $destfile \n" ; copy($startfile, $destfile) or die "well that didn't work:$!"; } closedir(gtiles);