http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11682
Revision: 11682 Author: legoktm Date: 2013-06-21 19:26:19 +0000 (Fri, 21 Jun 2013) Log Message: ----------- Implement experimental and untested dimToPrecision function
Modified Paths: -------------- branches/rewrite/pywikibot/__init__.py
Modified: branches/rewrite/pywikibot/__init__.py =================================================================== --- branches/rewrite/pywikibot/__init__.py 2013-06-21 18:27:24 UTC (rev 11681) +++ branches/rewrite/pywikibot/__init__.py 2013-06-21 19:26:19 UTC (rev 11682) @@ -12,6 +12,7 @@ import datetime import difflib import logging +import math import re import sys import threading @@ -168,9 +169,28 @@ globes[data['globe']], site=site)
def dimToPrecision(self): - """Convert dim from GeoData to Wikibase's Precision""" - raise NotImplementedError + """Convert dim from GeoData to Wikibase's Precision
+ Formula from http://williams.best.vwh.net/avform.htm#LL and + http://gis.stackexchange.com/questions/2951/algorithm-for-offsetting-a-latit... + + THIS FUNCTION IS EXPERIMENTAL DO NOT USE IT! + """ + lat_r = math.radians(self.lat) + lon_r = math.radians(self.lon) + radius = 6378137 # TODO: Support other globes + offset = self.dim + d_lat_r = offset / radius + d_lon_r = offset / (radius * math.cos(math.pi * lat_r / 180)) + + # Now convert to degrees + lat_offset = math.degrees(d_lat_r) + lon_offset = math.degrees(d_lon_r) + + # Take the average + avg_offset = (lat_offset + lon_offset) / 2.0 + self.precision = avg_offset + def precisionToDim(self): """Convert precision from Wikibase to GeoData's dim""" raise NotImplementedError
pywikipedia-svn@lists.wikimedia.org