Changeset 391
- Timestamp:
- 10/09/06 12:03:02 (2 years ago)
- Files:
-
- PleiadesGeocoder/trunk/CHANGES.txt (modified) (2 diffs)
- PleiadesGeocoder/trunk/DEPENDENCIES.txt (modified) (1 diff)
- PleiadesGeocoder/trunk/README.txt (modified) (4 diffs)
- PleiadesGeocoder/trunk/__init__.py (modified) (1 diff)
- PleiadesGeocoder/trunk/geocode.py (modified) (4 diffs)
- PleiadesGeocoder/trunk/tests/test_geocode.py (deleted)
- PleiadesGeocoder/trunk/tests/test_tool.py (modified) (1 diff)
- PleiadesGeocoder/trunk/version.txt (modified) (1 diff)
- PleiadesGeocoder/trunk/www/geocode.pt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
PleiadesGeocoder/trunk/CHANGES.txt
r356 r391 1 1 Changes 2 2 ======= 3 4 All ticket numbers are relative to http://icon.stoa.org/trac/pleiades/tickets. 3 5 4 6 0.6 - 2 October 2006 … … 14 16 - New @@geo logical view replaces all previous Python skin helper scripts. 15 17 18 0.6.1 - 9 Ocober 2006 19 --------------------- 20 - Switch to use of geopy for geocoding (ticket #68, #183). 21 PleiadesGeocoder/trunk/DEPENDENCIES.txt
r356 r391 2 2 ============ 3 3 4 - ElementTree or lxml4 - geopy: http://exogen.case.edu/projects/geopy/ 5 5 PleiadesGeocoder/trunk/README.txt
r356 r391 2 2 ================ 3 3 4 A geocoder for Plone locations based on the Yahoo API. A geocoder converts5 textlocations such as "Fort Collins, Colorado" to spatial coordinates. Other4 A geocoder for Plone locations based on geopy. A geocoder converts text 5 locations such as "Fort Collins, Colorado" to spatial coordinates. Other 6 6 geocoding backends could be supported in the future. 7 7 … … 15 15 ------------ 16 16 17 PleiadesGeocoder is installed like any other Plone product. It depends on 18 ElementTree or lxml. Your choice. Until we have a release, we will describe 19 installing from SVN. 17 PleiadesGeocoder is installed like any other Plone product. Until we have a 18 release, we will describe installing from SVN. 20 19 21 20 1. Checkout PleiadesGeocoder … … 28 27 29 28 3. Give the portal_geocoder a trial run via portal_geocoder/geocodeForm. 30 31 4. Register for a Yahoo application id and enter it in32 portal_geocoder/manage_propertiesForm.33 29 34 30 … … 54 50 Funding for the creation of this software was provided by a grant from the 55 51 U.S. National Endowment for the Humanities (http://www.neh.gov). 52 PleiadesGeocoder/trunk/__init__.py
r227 r391 32 32 33 33 from config import product_name 34 from geocode import YahooGeocoder34 from geocode import Geocoder 35 35 36 36 skin_globals=globals() 37 37 registerDirectory('skins', skin_globals) 38 38 39 tools = ( YahooGeocoder,)39 tools = (Geocoder,) 40 40 41 41 def initialize(context): PleiadesGeocoder/trunk/geocode.py
r227 r391 28 28 # =========================================================================== 29 29 30 import urllib31 32 # Import etree from elementtree or lxml33 try:34 from elementtree import ElementTree as etree35 except:36 from lxml import etree37 38 30 from Globals import InitializeClass 39 31 from OFS.SimpleItem import SimpleItem … … 47 39 from Products.PageTemplates.PageTemplateFile import PageTemplateFile 48 40 49 class YahooGeocoder(UniqueObject, PropertyManager, SimpleItem): 41 from geopy.geocoders import Google 42 43 44 class Geocoder(UniqueObject, PropertyManager, SimpleItem): 50 45 51 """A proxy for the Yahoo geocoder.46 """A proxy for geocoders using geopy. 52 47 """ 53 48 meta_type = product_name … … 56 51 security = ClassSecurityInfo() 57 52 58 def __init__(self, appid='YahooDemo'):53 def __init__(self, **kwargs): 59 54 """Create a new instance. 60 61 Parameters62 ----------63 appid : string64 Application id. See65 http://developer.yahoo.com/faq/index.html#appid66 55 """ 67 self._serverurl = 'http://api.local.yahoo.com' 68 self._service = '/MapsService/V1' 69 self._url = self._serverurl + self._service 70 self.manage_addProperty('appid', 'YahooDemo', 'string') 56 self._g = Google(resource='maps') 71 57 72 58 security.declareProtected(view_permission, 'geocode') … … 82 68 83 69 """ 84 request = "%s/%s" % (self._url, 'geocode')85 data = {'appid': getattr(self, 'appid', 'YahooDemo'),86 'location': location }87 u = urllib.urlopen(request, urllib.urlencode(data))88 response = u.read()89 u.close()90 91 infoset = etree.fromstring(response)92 93 # Error?94 error = infoset.find('{urn:yahoo:api}Error')95 if error:96 raise GeocoderError, error.find('{urn:yahoo:api}Message').text97 70 98 71 # Get results 99 72 records = [] 100 results = infoset.findall('{urn:yahoo:maps}Result')73 results = [x for x in self._g.geocode(location, exactly_one=False)] 101 74 for result in results: 102 75 r = {} 103 r['precision'] = result.get('precision', None) 104 r['warning'] = result.get('warning', None) 105 r['lat'] = result.find('{urn:yahoo:maps}Latitude').text 106 r['lon'] = result.find('{urn:yahoo:maps}Longitude').text 107 r['city'] = result.find('{urn:yahoo:maps}City').text 108 r['state'] = result.find('{urn:yahoo:maps}State').text 109 r['country'] = result.find('{urn:yahoo:maps}Country').text 76 r['place'] = result[0] 77 r['lat'] = result[1][0] 78 r['lon'] = result[1][1] 110 79 records.append(r) 111 80 return records PleiadesGeocoder/trunk/tests/test_tool.py
r176 r391 9 9 10 10 from Products.PleiadesGeocoder.interfaces.simple import IGeoItemSimple 11 from Products.PleiadesGeocoder import YahooGeocoder11 from Products.PleiadesGeocoder import Geocoder 12 12 13 13 class ExistenceTest(PloneTestCase.PloneTestCase): 14 15 14 def afterSetUp(self): 16 self.id = YahooGeocoder.id 17 15 self.id = Geocoder.id 18 16 def testGeocoderToolExists(self): 19 17 self.failUnless(self.id in self.portal.objectIds()) 20 18 21 19 class GoogleGeocodeTest(PloneTestCase.PloneTestCase): 20 def afterSetUp(self): 21 self.g = self.portal.portal_geocoder 22 def test_ftc(self): 23 results = self.g.geocode('Fort Collins, CO') 24 r = results[0] 25 self.assertEqual(r['place'], u'Fort Collins, CO', results) 26 self.assertAlmostEqual(r['lat'], 40.585278) 27 self.assertAlmostEqual(r['lon'], -105.083889) 28 def test_london(self): 29 results = self.g.geocode('London, England') 30 r = results[0] 31 self.assertEqual(r['place'], u'London, UK', results) 32 self.assertAlmostEqual(r['lat'], 51.500197) 33 self.assertAlmostEqual(r['lon'], -0.126197) 34 def test_goteborg(self): 35 results = self.g.geocode('Goteborg, Sweden') 36 r = results[0] 37 self.assertEqual(r['place'], u'Goteborg, Sweden', results) 38 self.assertAlmostEqual(r['lat'], 57.690996) 39 self.assertAlmostEqual(r['lon'], 11.971496) 40 41 22 42 def test_suite(): 23 43 from unittest import TestSuite, makeSuite 24 44 suite = TestSuite() 25 45 suite.addTest(makeSuite(ExistenceTest)) 46 suite.addTest(makeSuite(GoogleGeocodeTest)) 26 47 return suite 27 48 PleiadesGeocoder/trunk/version.txt
r227 r391 1 0.6 1 0.6.1 2 2 PleiadesGeocoder/trunk/www/geocode.pt
r112 r391 83 83 <tr class="search-results"> 84 84 <td class="search-results" align="left" valign="top"> 85 <div class="form-label">Precision</div>86 </td>87 <td class="search-results" align="left" valign="top">88 85 <div class="form-label">Location</div> 89 86 </td> … … 91 88 <div class="form-label">Lat/Long</div> 92 89 </td> 93 <td class="search-results" align="left" valign="top">94 <div class="form-label">Warning</div>95 </td>96 90 </tr> 97 91 98 92 <tbody class="search-results" tal:repeat="result results"> 99 93 <tr tal:condition="repeat/result/odd" class="search-result-odd"> 100 <td class="search-results" tal:content="string:${result/precision}">Precision</td> 101 <td class="search-results" tal:content="string:${result/city}, ${result/state}, ${result/country}">Location</td> 94 <td class="search-results" tal:content="string:${result/place}">Location</td> 102 95 <td class="search-results" tal:content="string:${result/lat} ${result/lon}">Lat/Long</td> 103 <td class="search-results" tal:content="string:${result/warning}">Warning</td>104 96 </tr> 105 97 <tr tal:condition="repeat/result/even" class="search-result-even"> 106 <td class="search-results" tal:content="string:${result/precision}">Precision</td> 107 <td class="search-results" tal:content="string:${result/city}, ${result/state}, ${result/country}">Location</td> 98 <td class="search-results" tal:content="string:${result/place}">Location</td> 108 99 <td class="search-results" tal:content="string:${result/lat} ${result/lon}">Lat/Long</td> 109 <td class="search-results" tal:content="string:${result/warning}">Warning</td>110 100 </tr> 111 101 </tbody>
