Adding distance calculation to the Coord class
[treecutter.git] / xinclude / address.py
index 3b7ff38a3754fe945d227280d133758de70b574d..fd7e0002589cd843964b5d73fc0d8338bd9bea25 100755 (executable)
@@ -21,6 +21,17 @@ ZOOMRANGE = range(1, 18)
 # tile size
 TS = 256
 
+DB_NS="http://docbook.org/ns/docbook"
+DB = "{%s}" % DB_NS
+XI_NS="http://www.w3.org/2001/XInclude"
+XI = "{%s}" % XI_NS
+XLINK_NS="http://www.w3.org/1999/xlink"
+XLINK = "{%s}" % XLINK_NS
+HTML_NS="http://www.w3.org/1999/xhtml"
+HTML = "{%s}" % HTML_NS
+NSMAP = {None : DB_NS,
+         'xlink' : XLINK_NS}
+
 
 h = Http(".cache")
 
@@ -74,6 +85,11 @@ class Coord(object):
         yo = int(floor((y-floor(y))*TS))
         return (xo, yo)
 
+    def distance(self, point):
+        res = Geodesic.WGS84.Inverse(self.latitude, self.longitude,
+                                     point.latitude, point.longitude)
+        return res['s12']
+
     def png(self,zoom=15,size=(TS,TS)):
         filename = encode(self.latitude, self.longitude)+'.png'
         if path.isfile(filename):
@@ -120,7 +136,6 @@ class Coord(object):
         gridc = grid.crop((xp-TS/2,yp-TS/2,xp+TS/2,yp+TS/2))
         gridc.save(filename)
 
-
     def db_xml(self):
         uri = etree.Element(DB+'uri',nsmap=NSMAP)
         ln  = etree.SubElement(uri,  DB+'link')