forked from cyclingzealot/bin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeoHashHistory.pl
executable file
·95 lines (81 loc) · 3.11 KB
/
geoHashHistory.pl
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
#! /usr/bin/perl
#
# GeoHistory - (C) 2012 AeroIllini <aeroillini@gmail.com>
#
# This script generates a kml file containing placemarks for every
# geohash point in a certain graticule since a certain date. The
# default start date is May 21, 2008, which is the date the comic
# first appeared and Geohashing was born.
#
# The output should be piped to a file, and then either loaded in
# Google Earth or hosted on a public server and loaded in Google
# Maps.
#
# The script can be used to explore the random distribution of points,
# or to check for retroactive Couch Potato Awards (or Curse of
# Unawareness Awards).
#
# More information on Geohashing:
# <http://wiki.xkcd.com/geohashing/Main_Page>
#
# ---------------------------------------------------------------------
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# ---------------------------------------------------------------------
# Import some useful stuff.
use Date::Calc qw(Add_Delta_Days Delta_Days);
use Time::Local;
use Geo::Hashing;
# This is the start date. Modify as you see fit.
($startyear, $startmonth, $startday) = ("2008", "5", "21");
# This is the graticule we're calculating for.
($lat, $lon) = ("47", "-122");
$lat = $ARGV[0] || 47 ;
$lon = $ARGV[1] || -122;
# Grab the current date.
($a,$a,$a,$todayday,$todaymonth,$todayyear,$a,$a,$a) = localtime(time);
# Translate months for placemark titles.
@months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
# Do some interim math.
$todayyear = $todayyear+1900;
$todaymonth = $todaymonth+1;
($year, $month, $day) = ($startyear, $startmonth, $startday);
$delta = Delta_Days(($startyear, $startmonth, $startday),($todayyear,$todaymonth,$todayday));
# Output file header xml stuff
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<kml xmlns=\"http://www.google.com/earth/kml/2\">
<Document>
<name>Historical Geohash Points for ",$lat,",",$lon,"</name>
";
# Main loop
for ($i = 0; $i <= $delta; $i++) {
# format date for Geo::Hashing
my $date = sprintf("%04d-%02d-%02d", $year, $month, $day);
# magic happens!
my $geo = new Geo::Hashing(lat => $lat, lon => $lon, date => $date);
# output placemark xml
print "<Placemark>";
print "<name>";
print $months[$month-1]," ",$day,", ",$year;
print "</name>";
print "<description>",$geo->lat,", ",$geo->lon,"</description>";
print "<Point><coordinates>",$geo->lon,",",$geo->lat,"</coordinates></Point>";
print "</Placemark>","\n";
# increment day and loop again!
($year, $month, $day) = Add_Delta_Days($startyear, $startmonth, $startday, $i);
}
# finish up xml file
print "</Document>
</kml>";