]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/blobdiff - wradmin/lib/wrgpx.py
Files after running 2to3.py.
[philipp/winterrodeln/wradmin.git] / wradmin / lib / wrgpx.py
index 2b9b314bfb45bc540f1cb7ce5ad82e4a150f258b..9ba5c813beb6bb6f311b3438a16242a3d213c190 100644 (file)
@@ -13,7 +13,7 @@ import numpy as np
 import matplotlib
 matplotlib.use('Agg')
 import matplotlib.pyplot as plt
-import StringIO
+import io
 from pylons.i18n.translation import _
 
 
@@ -43,7 +43,7 @@ class Waypoint:
         self.name = None           # name as string or None
         self.type = None           # type as string or None
     def __repr__(self):
-        return u"Waypoint %s" % unicode(self.name)
+        return "Waypoint %s" % str(self.name)
 
 
 class Track:
@@ -52,7 +52,7 @@ class Track:
         self.type = None           # type as string or None
         self.points = []           # one point is a tuple (lat, lon, ele) or (lat, lon, None)
     def __repr__(self):
-        return u"Track %s" % unicode(self.name)
+        return "Track %s" % str(self.name)
 
 
 class WrGpx:
@@ -134,10 +134,10 @@ def parse_wrgpx(filename=None, string=None):
         elif element.tag == ns+'wpt':
             waypoint = parse_wpt(element)
             wrgpx.waypoints.append(waypoint)
-            if waypoint.ele is None: hints.append(Hint(_(u"Elevation of waypoint '%s' should be given.") % unicode(waypoint), 1))
-            if waypoint.name is None: hints.append(Hint(_(u"Name of waypoint '%s' must be given.") % unicode(waypoint), 2))
-            if waypoint.type is None: hints.append(Hint(_(u"Type of waypoint '%s' must be given (Gasthaus, Bushaltestelle, ...)") % unicode(waypoint), 2))
-            if not waypoint.type in ['Gasthaus', 'Parkplatz', 'Bushaltestelle']: hints.append(Hint(_(u"Type of the waypoint '%s' has to be one of (Gasthaus, Bushaltestelle, ...)") % unicode(waypoint), 2))
+            if waypoint.ele is None: hints.append(Hint(_("Elevation of waypoint '%s' should be given.") % str(waypoint), 1))
+            if waypoint.name is None: hints.append(Hint(_("Name of waypoint '%s' must be given.") % str(waypoint), 2))
+            if waypoint.type is None: hints.append(Hint(_("Type of waypoint '%s' must be given (Gasthaus, Bushaltestelle, ...)") % str(waypoint), 2))
+            if not waypoint.type in ['Gasthaus', 'Parkplatz', 'Bushaltestelle']: hints.append(Hint(_("Type of the waypoint '%s' has to be one of (Gasthaus, Bushaltestelle, ...)") % str(waypoint), 2))
 
         # Routes
         elif element.tag == ns+'rte':
@@ -159,8 +159,8 @@ def parse_wrgpx(filename=None, string=None):
                             track.points.append((trkpt.lat, trkpt.lon, trkpt.ele))
                             if trkpt.ele is None: no_ele += 1
                         elif e.tag == ns+'extensions': hints.append(Hint(_("XML element extensions within XML element trkpt is not used by WRGPX."), 2))
-                    if no_ele > 0: hints.append(Hint(_(u"%d of %d track points have no elevation (%s).") % (no_ele, len(track.points), unicode(track)), 1))
-            if len(track.points) == 0: hints.append(Hint(_(u"track '%s' is empty.") % unicode(track), 2))
+                    if no_ele > 0: hints.append(Hint(_("%d of %d track points have no elevation (%s).") % (no_ele, len(track.points), str(track)), 1))
+            if len(track.points) == 0: hints.append(Hint(_("track '%s' is empty.") % str(track), 2))
             wrgpx.tracks.append(track)
 
         # Extensions
@@ -175,18 +175,18 @@ def height_profile(wrgpx):
     "Create a elevation profile for the wrgpx class. Raises a RuntimError in case of an error, otherwise returns the PNG file as string."
     proj_utm32 = mapnik.Projection("+proj=utm +zone=32 +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
     bahntracks = [t for t in wrgpx.tracks if t.type=='Rodelbahn' and len(t.points) > 0]
-    if len(bahntracks) == 0: raise RuntimeError(_(u"There is no 'Rodelbahn' type track in the GPX file."))
+    if len(bahntracks) == 0: raise RuntimeError(_("There is no 'Rodelbahn' type track in the GPX file."))
 
     # Descending order and check
     for track in bahntracks:
-        if track.points[0][2] is None or track.points[-1][2] is None: raise RuntimeError(_(u'Track has no elevation data'))
+        if track.points[0][2] is None or track.points[-1][2] is None: raise RuntimeError(_('Track has no elevation data'))
         if track.points[0][2] < track.points[-1][2]: track.points[:] = track.points[::-1]
     bahntracks.sort(lambda x, y: -1 if x.points[0][2] > y.points[0][2] else 1)
     points = []
     for track in bahntracks: points.extend(track.points)
 
     points = np.array(points)
-    for i in xrange(len(points)):
+    for i in range(len(points)):
         c = mapnik.Coord(points[i][1], points[i][0])
         c = c.forward(proj_utm32)
         points[i][0] = c.y
@@ -207,12 +207,12 @@ def height_profile(wrgpx):
     plt.plot(x, h, color='black')
     plt.axis([axxmin, axxmax, axymin, axymax])
     plt.grid()
-    plt.xlabel(u'Strecke in m [%d m Gesamtstrecke]' % round(x[-1], -1))
-    plt.ylabel(u'Höhe in m [%d m Differenz]' % round(h[0]-h[-1]))
-    plt.title(u'%s - Höhenprofil' % wrgpx.metadata.name)
+    plt.xlabel('Strecke in m [%d m Gesamtstrecke]' % round(x[-1], -1))
+    plt.ylabel('Höhe in m [%d m Differenz]' % round(h[0]-h[-1]))
+    plt.title('%s - Höhenprofil' % wrgpx.metadata.name)
 
     width_px = 500
-    imgdata = StringIO.StringIO()
+    imgdata = io.StringIO()
     f.savefig(imgdata, dpi=width_px/plt.gcf().get_figwidth())
     s = imgdata.getvalue()
     imgdata.close()