Difference between revisions of "Decicule"

From Geohashing
imported>Paradoxian
m
m (redirect to section)
(Tag: New redirect)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Note: This is an experimental proposal.
+
#redirect[[centicule#Pinecone's algorithm]]
 
 
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 [[User:Pinecone|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 [[User:Pinecone|Pinecone]]'s basic philosophy, but makes it simpler based on [[User:Rspeer|Rspeer]]'s comments.
 
 
 
==Implementation==
 
 
 
<pre>
 
# 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 djia.find('404 Not Found') >= 0: 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)
 
</pre>
 

Latest revision as of 04:25, 30 May 2022