Difference between revisions of "User:Wenslayer/KMLGenerator"

From Geohashing
imported>Wenslayer
(Tidied up page)
imported>Wenslayer
m (Usage: Updated usage from updated script (thanks Jiml!))
 
(7 intermediate revisions by 2 users not shown)
Line 4: Line 4:
  
 
== Solution ==
 
== Solution ==
I've submitted a script to the [http://public.perforce.com:8080 Perforce Public Depot]; the script can be downloaded here:
+
I've submitted a script to the [http://public.perforce.com:8080 Perforce Public Depot]: [http://public.perforce.com:8080/@rev1=head@//guest/marc_wensauer/geohash/gen_geohash_kml.pl gen_geohash_kml.pl]
* [http://public.perforce.com:8080/@rev1=head@//guest/marc_wensauer/geohash/gen_geohash_kml.sh gen_geohash_kml.sh]
+
 
 +
Kudos to [[User:Polysylabic Pseudonym|Psud]] for providing the [http://www.amipsychic.net/geohashing.html Geohashing historical coordinates].
 +
 
 +
See [[User_talk:{{PAGENAME}}|discussion page]] for to-do's.
  
 
== Usage ==
 
== Usage ==
 
<pre>
 
<pre>
Usage: gen_geohash_kml.sh -g <graticule> [-s <source file>]
+
Usage: ./gen_geohash_kml.pl -g <graticule[:<graticule>]> [-i <input file>] [-n <name>] [-l] [-v]
        -g: specify the graticule of interest (form: <latitude,longitude>)
+
-g: graticule of interest (format: "<latitude>,<longitude>")
        -s: source file to use (file format: YYYY-MM-DD,<DOW>,<LAT>,<LON>)
+
add more with colon separator
                default: '-' for standard input
+
-i: input file to use (file format: "YYYY-MM-DD,<DOW>,<LAT>,<LON>")
 +
default: '-' for standard input
 +
-n: name of top-level KML folder holding place markers
 +
default: "Geohash History for {graticule}"
 +
"{graticule}" is replaced with actual graticule(s) supplied
 +
-l: generate a label for each place marker corresponding to its date
 +
default is to suppress a label for the place marker
 +
-v: enable verbose logging
  
 
Notes:
 
Notes:
Line 18: Line 28:
 
   http://www.amipsychic.net/geohashing.html
 
   http://www.amipsychic.net/geohashing.html
 
* Resulting KML file is displayed to standard out.
 
* Resulting KML file is displayed to standard out.
* You may wish to pre-process the source file to only show dates of interest.
+
* The resulting KML file will organize the place markers into folders by:
   E.g.: grep "^2009" allcoords.csv | gen_geohash_kml.sh -g 49,-123 > 2009.kml
+
   Graticule -> Year -> Year-Month
  
 
Reference:
 
Reference:
* http://wiki.xkcd.com/geohashing/
+
* http://wiki.xkcd.com/geohashing
</pre>
 
 
 
== Examples ==
 
 
 
Using the source data, Geohash coordinates can be generated for every day since October 1st, 1928 (over 80 years worth), so with a little filtering, you should be able to generate a KML file for whatever date range and graticule you'd like.
 
  
 
Examples:
 
Examples:
* Generate a KML for the [[Surrey, British Columbia|Surrey]] graticule of all possible Geohash coordinates since October 1st, 1928 (over 29,000 points!):
+
* You can choose to generate a resulting KML file from the source data all
<pre>
+
  in one command, like this:
$ wget -qO http://www.amipsychic.net/coords/allcoords.csv.bz2 |
+
  $ wget -O - http://www.amipsychic.net/coords/allcoords.csv.bz2 |
      bzip2 -d | gen_geohash_kml.sh -g 49,-122 > 49,-122_all.kml
+
    bzip2 -d | gen_geohash_kml.pl -g 49,-123 > Van_all.kml
</pre>
 
  
* Generate a KML for the [[Vancouver, British Columbia|Vancouver]] graticule of all Canada Day and Christmas Day dates:
+
  ...or first stage the data to a local file:
<pre>
+
  $ wget -O - http://www.amipsychic.net/coords/allcoords.csv.bz2 |
$ wget -qO http://www.amipsychic.net/coords/allcoords.csv.bz2 |
+
    bzip2 -d > allcoords.csv
      bzip2 -d | sed -nre '/-(07-01|12-25)/p' |
 
      gen_geohash_kml.sh -g 48,-123 > 48,-123_7.1_12.25.kml
 
</pre>
 
 
 
* Generate a KML for the [[Victoria, British Columbia|Victoria]] graticule of all dates since the original Geohash webcomic (May 21st, 2008):
 
<pre>
 
$ wget -qO http://www.amipsychic.net/coords/allcoords.csv.bz2 |
 
      bzip2 -d | sed -ne '/^2008-05-21/,$p' |
 
      gen_geohash_kml.sh -g 49,-123 > 49,-123_since_2009-05-21.kml
 
</pre>
 
  
:Screen shot:
+
  ...and then generate the KML file from the local file:
:[[Image:KML Generator - Google Earth screen shot 1.jpg]]
+
  $ gen_geohash_kml.pl -g 48,-123:49,-123 -i allcoords.csv > VicVan_all.kml
  
Note how few Geohash coordinates actually fall in Victoria and the Saanich Peninsula? 
+
* You may wish to pre-process the source file to only show dates of interest:
 +
  $ grep "^2009" allcoords.csv |
 +
    gen_geohash_kml.pl -g 49,-123:49,-122:48,-122 > VanSurBham_2009.kml
  
== To Do ==
+
* Use of -l and -n flag:
 +
  $ sed -nre '/-(07-01|12-25)/p' allcoords.csv | gen_geohash_kml.pl \
 +
    -g 48,-123 -l -n "Canada/Xmas Day in {graticule}" > Vic_7.1_12.25.kml
  
* Convert script from Bash to Perl to run faster.
+
* Multiple graticules since a particular date:
* Automate retrieval and decompression of source data.
+
  $ sed -ne '/^2008-05-21/,$p' allcoords.csv | gen_geohash_kml.pl \
* <s>Pretty-up each placemark's description to include hyperlinks to this Wiki and peeron map.</s> Done; don't need link to peeron map (you're in a mapping application already!)
+
    -g 49,-123:48,-123:49,-122:48,-122 > VanVicSurBham_since_2008-05-21.kml
* Add format checking of source data.
+
</pre>
* Properly account for W30 graticules.
 

Latest revision as of 00:50, 8 July 2009

Problem

Have you wondered what historical Geohashes have occurred in your graticule? Have you wanted to see them all at once, instead of typing each date in via peeron? Well this script might help you out here.

Solution

I've submitted a script to the Perforce Public Depot: gen_geohash_kml.pl

Kudos to Psud for providing the Geohashing historical coordinates.

See discussion page for to-do's.

Usage

Usage: ./gen_geohash_kml.pl -g <graticule[:<graticule>]> [-i <input file>] [-n <name>] [-l] [-v]
	-g: graticule of interest (format: "<latitude>,<longitude>")
		add more with colon separator
	-i: input file to use (file format: "YYYY-MM-DD,<DOW>,<LAT>,<LON>")
		default: '-' for standard input
	-n: name of top-level KML folder holding place markers
		default: "Geohash History for {graticule}"
		"{graticule}" is replaced with actual graticule(s) supplied
	-l: generate a label for each place marker corresponding to its date
		default is to suppress a label for the place marker
	-v: enable verbose logging

Notes:
* You can get *all* retro Geohash data from:
  http://www.amipsychic.net/geohashing.html
* Resulting KML file is displayed to standard out.
* The resulting KML file will organize the place markers into folders by:
  Graticule -> Year -> Year-Month

Reference:
* http://wiki.xkcd.com/geohashing

Examples:
* You can choose to generate a resulting KML file from the source data all
  in one command, like this:
   $ wget -O - http://www.amipsychic.net/coords/allcoords.csv.bz2 |
     bzip2 -d | gen_geohash_kml.pl -g 49,-123 > Van_all.kml

  ...or first stage the data to a local file:
   $ wget -O - http://www.amipsychic.net/coords/allcoords.csv.bz2 |
     bzip2 -d > allcoords.csv

  ...and then generate the KML file from the local file:
   $ gen_geohash_kml.pl -g 48,-123:49,-123 -i allcoords.csv > VicVan_all.kml

* You may wish to pre-process the source file to only show dates of interest:
   $ grep "^2009" allcoords.csv | 
     gen_geohash_kml.pl -g 49,-123:49,-122:48,-122 > VanSurBham_2009.kml

* Use of -l and -n flag:
   $ sed -nre '/-(07-01|12-25)/p' allcoords.csv | gen_geohash_kml.pl \
     -g 48,-123 -l -n "Canada/Xmas Day in {graticule}" > Vic_7.1_12.25.kml

* Multiple graticules since a particular date:
   $ sed -ne '/^2008-05-21/,$p' allcoords.csv | gen_geohash_kml.pl \
     -g 49,-123:48,-123:49,-122:48,-122 > VanVicSurBham_since_2008-05-21.kml