diff options
Diffstat (limited to 'chimere/route.py')
| -rw-r--r-- | chimere/route.py | 24 | 
1 files changed, 15 insertions, 9 deletions
diff --git a/chimere/route.py b/chimere/route.py index 8c4638a..31cf4f0 100644 --- a/chimere/route.py +++ b/chimere/route.py @@ -22,7 +22,10 @@  Routing management  """ -import os, re, shutil, tempfile +import os +import re +import shutil +import tempfile  from BeautifulSoup import BeautifulSoup  from subprocess import Popen, PIPE  from django.contrib.gis.gdal import DataSource @@ -30,6 +33,7 @@ from django.contrib.gis.gdal.error import OGRException  from django.conf import settings +  class Router:      def route(self, lon1, lat1, lon2, lat2, transport='foot'):          ''' @@ -37,9 +41,11 @@ class Router:          '''          return [] +  class RoutinoRouter(Router):      re_desc = [re.compile("<tr class='n'>"), re.compile("<tr class='s'>"),                 re.compile("<tr class='t'>")] +      def route(self, lon1, lat1, lon2, lat2, steps=[], transport='foot',                speed=None):          ''' @@ -57,10 +63,12 @@ class RoutinoRouter(Router):                  "--lon1=%0.15f" % lon1,                  ]          if speed: -            args += ["--speed-%s=%s" % (highway, unicode(speed)) -                for highway in ('motorway', 'trunk', 'primary', 'secondary', -                      'tertiary', 'unclassified', 'residential', 'service', -                      'track','cycleway','path','steps')] +            args += [ +                "--speed-%s=%s" % (highway, unicode(speed)) +                for highway in ( +                    'motorway', 'trunk', 'primary', 'secondary', 'tertiary', +                    'unclassified', 'residential', 'service', 'track', +                    'cycleway', 'path', 'steps')]          lonlat_index = 1          for lon, lat in steps:              lonlat_index += 1 @@ -97,9 +105,8 @@ class RoutinoRouter(Router):          desc = desc[1:-2]          # very fragile piece of code but only break the numerotation          number_tpl = '<tr class="n"><span class="number">%d.</span>' -        desc = [re.sub('<tr class="n">', number_tpl % (idx/2+1), d) -                        if idx % 2 else d -                        for idx, d in enumerate(desc)] +        desc = [re.sub('<tr class="n">', number_tpl % (idx / 2 + 1), d) +                if idx % 2 else d for idx, d in enumerate(desc)]          desc = self.webify(BeautifulSoup('\n'.join(desc)).prettify())          desc = re.sub("  \[", "", desc)          desc = re.sub("  \]", "", desc) @@ -118,4 +125,3 @@ router = None  if hasattr(settings, 'CHIMERE_ROUTING_ENGINE') and \     settings.CHIMERE_ROUTING_ENGINE['ENGINE'] == 'routino':      router = RoutinoRouter() -  | 
