Difference between revisions of "Decicule"

From Geohashing
imported>Robyn
(implementing joannac's suggestion.)
imported>Newacct
m (Implementation)
Line 42: Line 42:
 
date = datetime.date.today()
 
date = datetime.date.today()
 
djia = urllib.urlopen((date - datetime.timedelta(td30)).strftime("http://irc.peeron.com/xkcd/map/data/%Y/%m/%d")).read()
 
djia = urllib.urlopen((date - datetime.timedelta(td30)).strftime("http://irc.peeron.com/xkcd/map/data/%Y/%m/%d")).read()
if djia.find('404 Not Found') >= 0: sys.exit(sys.stderr.write("Dow Jones not available yet.\n"))
+
if '404 Not Found' in djia: sys.exit(sys.stderr.write("Dow Jones not available yet.\n"))
 
sum = hashlib.md5("%s-%s" % (date, djia)).digest()
 
sum = hashlib.md5("%s-%s" % (date, djia)).digest()
 
north, east = [str( d * (abs(a) + (f-(math.floor(f*10)/10)) ) ) for d, f, a in zip((south, west),
 
north, east = [str( d * (abs(a) + (f-(math.floor(f*10)/10)) ) ) for d, f, a in zip((south, west),

Revision as of 10:49, 25 December 2009

Note: This was an experimental proposal that never took hold.

A decicule is approximately one hundredth the area of a graticule, or more precisely the set of coordinates that has a common integer part and tenths digit for both the latitude and longitude. This follows the proposal set forth by Pinecone.

A decihash of a decicule is the same as the geohash of the graticule of which it is a part, except differing in the tenths digit where it takes the tenth digit of the decicule. This follows Pinecone's basic philosophy, but makes it simpler based on Rspeer's comments.

See also: centicule.

Implementation

# decihash.py
# by Paradoxian, based on Python implementation 2 at:
# http://wiki.xkcd.com/geohashing/Implementations

import hashlib, datetime, struct, urllib, re, sys, math, webbrowser
myLat = 34.0
myLon = -118.3
args = sys.argv
if len(args) == 1:
    args.append(myLat)
    args.append(myLon)
args[1] = float(args[1])
args[2] = float(args[2])
deciculeN = math.modf(args[1] * 10)[1] / 10
deciculeE = math.modf(args[2] * 10)[1] / 10

# may print wrong sign if rounds to -0.0, but result will still be correct
print "Decicule:", deciculeN, deciculeE

if args[2] < -30:
    td30 = 0
else:
    td30 = 1
if args[1] < 0:
    south = -1
else:
    south = 1
if args[2] < 0:
    west = -1
else:
    west = 1
date = datetime.date.today()
djia = urllib.urlopen((date - datetime.timedelta(td30)).strftime("http://irc.peeron.com/xkcd/map/data/%Y/%m/%d")).read()
if '404 Not Found' in djia: sys.exit(sys.stderr.write("Dow Jones not available yet.\n"))
sum = hashlib.md5("%s-%s" % (date, djia)).digest()
north, east = [str( d * (abs(a) + (f-(math.floor(f*10)/10)) ) ) for d, f, a in zip((south, west),
    [x/2.**64 for x in struct.unpack_from(">QQ", sum)], (deciculeN, deciculeE) )]
print "Decihash:", north, east
dest = 'http://maps.google.com/maps?f=q&hl=en&geocode=&q=' + north + '+' + east + '&ie=UTF8&ll=' + north + ',' + east + '&spn=0.918082,1,864929&z=9&iwloc=addr'
print "URL:", dest
webbrowser.open(dest)