]> ToastFreeware Gitweb - philipp/winterrodeln/wradmin.git/commitdiff
Added first draft version of a toolbox for coordinates.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Tue, 24 Nov 2009 18:25:07 +0000 (18:25 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Tue, 24 Nov 2009 18:25:07 +0000 (18:25 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/trunk/wradmin@531 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wradmin/wradmin/controllers/coordtool.py [new file with mode: 0644]
wradmin/wradmin/controllers/wrgpxtool.py [new file with mode: 0644]
wradmin/wradmin/model/validators.py
wradmin/wradmin/templates/coordtool.html [new file with mode: 0644]
wradmin/wradmin/templates/index.html
wradmin/wradmin/templates/wrgpxtool.html [new file with mode: 0644]
wradmin/wradmin/tests/functional/test_coordtool.py [new file with mode: 0644]
wradmin/wradmin/tests/functional/test_wrgpxtool.py [new file with mode: 0644]

diff --git a/wradmin/wradmin/controllers/coordtool.py b/wradmin/wradmin/controllers/coordtool.py
new file mode 100644 (file)
index 0000000..7abcdee
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/python2.5
+# -*- coding: iso-8859-15 -*-
+
+import logging
+
+from pylons import request, response, session, tmpl_context as c
+from pylons.controllers.util import abort, redirect_to
+
+from wradmin.lib.base import BaseController, render
+import wradmin.model.validators
+
+log = logging.getLogger(__name__)
+
+class CoordtoolController(BaseController):
+
+    def index(self):
+        c.result = None
+        return render('coordtool.html')
+    
+
+    def convert(self):
+        input = request.POST['input']
+        no_height = request.POST.has_key('no_height')
+        simplify = request.POST.has_key('simplify')
+        swap_latlon = request.POST.has_key('swap_latlon')
+        no_geoformat = request.POST.has_key('no_geoformat')
+        no_gpxformat = request.POST.has_key('no_gpxformat')
+        no_gmapsformat = request.POST.has_key('no_gmapsformat')
+        
+        if input is None or len(input.strip()) == 0: 
+            c.result = None
+            return redirect_to(controller='coordtool', action='index')
+        
+        geo = wradmin.model.validators.MultiGeo()
+        c.result = geo.to_python(input)
+        c.geo_winterrodeln = wradmin.model.validators.MultiGeo(output_format = geo.FORMAT_WINTERRODELN)
+        c.geo_geocaching = wradmin.model.validators.MultiGeo(output_format = geo.FORMAT_GEOCACHING)
+        
+        return render('coordtool.html')
\ No newline at end of file
diff --git a/wradmin/wradmin/controllers/wrgpxtool.py b/wradmin/wradmin/controllers/wrgpxtool.py
new file mode 100644 (file)
index 0000000..171eb25
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/python2.5
+# -*- coding: iso-8859-15 -*-
+
+import logging
+
+from pylons import request, response, session, tmpl_context as c
+from pylons.controllers.util import abort, redirect_to
+
+from wradmin.lib.base import BaseController, render
+
+log = logging.getLogger(__name__)
+
+class WrgpxtoolController(BaseController):
+
+    def index(self):
+        return render('wrgpxtool.html')
index e8e9d88649a7aa9a706c70caac425b33c3adf4bf..25c81d9bb2fba9cb4e2a215b8586292ec9a47d43 100644 (file)
@@ -112,6 +112,79 @@ class Geo(formencode.FancyValidator):
         return u'%.6f N %.6f E' % (latitude, longitude)
 
 
+class MultiGeo(formencode.FancyValidator):
+    "Formats multiple coordinates, even in multiple lines to [(latitude, longitude, height), ...] or [(latitude, longitude, None), ...] tuplets."
+    
+    # Valid for input_format
+    FORMAT_GUESS = 0         # guesses the input format; default for input_format
+    FORMAT_NONE = -1          # indicates missing formats
+    
+    # Valid for input_format and output_format
+    FORMAT_GEOCACHING = 1    # e.g. "N 47° 13.692 E 011° 25.535"
+    FORMAT_WINTERRODELN = 2  # e.g. "47.222134 N 11.467211 E"
+    FORMAT_GMAPPLUGIN = 3    # e.g. "47.232922, 11.452239"
+    FORMAT_GPX = 4           # e.g. "<trkpt lat="47.181289" lon="11.408827"><ele>1090.57</ele></trkpt>"
+    
+    input_format = FORMAT_GUESS
+    output_format = FORMAT_WINTERRODELN
+    last_input_format = FORMAT_NONE
+
+    def __init__(self, input_format = FORMAT_GUESS, output_format = FORMAT_WINTERRODELN, **keywords):
+        self.input_format = input_format
+        self.output_format = output_format
+        formencode.FancyValidator.__init__(self, if_empty = (None, None, None), **keywords)
+    
+    def _to_python(self, value, state):
+        input_format = self.input_format
+        if not input_format in [self.FORMAT_GUESS, self.FORMAT_GEOCACHING, self.FORMAT_WINTERRODELN, self.FORMAT_GMAPPLUGIN, self.FORMAT_GPX]:
+            raise formencode.Invalid(u"input_format %d is not recognized" % input_format, value, state) # Shouldn't it be an other type of runtime error?
+        lines = [line.strip() for line in value.split("\n") if len(line.strip()) > 0]
+        
+        result = []
+        for line in lines:
+            if input_format == self.FORMAT_GUESS or input_format == self.FORMAT_GEOCACHING:
+                pass
+                
+            if input_format == self.FORMAT_GUESS or input_format == self.FORMAT_WINTERRODELN:
+                r = re.match(u'(\d+\.\d+) N (\d+\.\d+) E', line)
+                if not r is None:
+                    result.append((float(r.groups()[0]), float(r.groups()[1]), None))
+                    last_input_format = self.FORMAT_WINTERRODELN
+                    continue
+                
+            if input_format == self.FORMAT_GUESS or input_format == FORMAT_GMAPPLUGIN:
+                pass
+                
+            if input_format == self.FORMAT_GUESS or input_format == self.FORMAT_GPX:
+                pass
+            
+            raise formencode.Invalid(u"Coordinates '%s' have no valid format" % value, value, state)
+            
+        return result
+    
+    def _from_python(self, value, state):
+        output_format = self.output_format
+        result = []
+        for latitude, longitude, height in value:
+            if output_format == self.FORMAT_GEOCACHING:
+                degree = latitude
+                result.append(u'N %02d° %02.3f E %03d° %02.3f' % (latitude, latitude % 1 * 60, longitude, longitude % 1 * 60))
+                
+            elif output_format == self.FORMAT_WINTERRODELN:
+                result.append(u'%.6f N %.6f E' % (latitude, longitude))
+
+            elif output_format == FORMAT_GMAPPLUGIN:
+                pass
+                
+            elif output_format == self.FORMAT_GPX:
+                pass
+            
+            else:
+                raise formencode.Invalid(u"output_format %d is not recognized" % output_format, value, state) # Shouldn't it be an other type of runtime error?
+            
+        return "\n".join(result)
+
+
 class AustrianPhoneNumber(formencode.FancyValidator):
     """
     Validates and converts phone numbers to +##/###/####### or +##/###/#######-### (having an extension)
diff --git a/wradmin/wradmin/templates/coordtool.html b/wradmin/wradmin/templates/coordtool.html
new file mode 100644 (file)
index 0000000..9a8d9ab
--- /dev/null
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
+                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+    xmlns:py="http://genshi.edgewall.org/"
+    xmlns:xi="http://www.w3.org/2001/XInclude">
+<xi:include href="master.html" />
+
+<head>
+    <title>Koordinaten-Rechner</title>
+</head>
+
+<body>
+
+<h2>Koordinaten-Rechner</h2>
+
+<p py:if="not c.result">Werkzeug für die Koordinatenumrechnung. Das Quellformat braucht nicht angegeben zu werden, es sollte automatisch erkannt werden. Wenn mehr als eine Koordinate gleichzeitig umgerechnet werden soll, dann bitte pro Zeile eine Koordinate angeben.</p>
+
+<h3 py:if="c.result">Winterrodeln-Format</h3>
+<p py:if="c.result">
+    <py:for each="line in c.result">${c.geo_winterrodeln.from_python([line])}<br/></py:for>
+</p>
+
+<h3 py:if="c.result">Geocaching-Format</h3>
+<p py:if="c.result">
+    <py:for each="line in c.result">${c.geo_geocaching.from_python([line])}<br/></py:for>
+</p>
+
+<form action="${h.url_for(controller='coordtool', action='convert')}" method="post">
+<table>
+    <tr><th></th><th>Beispiel</th></tr>
+       <tr><td><textarea name="input" cols="70" rows="10"/></td>
+    <td>
+        <p>47.222134 N 11.467211 E<br/>
+           47.222143 N 11.467209 E<br/>
+           47.222153 N 11.467210 E</p>
+        <p>N 47° 14.912 E 011° 27.432<br/>
+           N 47° 14.925 E 011° 27.439<br/>
+           N 47° 14.936 E 011° 27.440</p>
+    </td></tr>
+    <tr><td><input type="checkbox" name="no_height" />Höhe weglassen</td><td></td></tr>
+    <tr><td><input type="checkbox" name="simplify" /> Weg vereinfachen</td><td></td></tr>
+    <tr><td><input type="checkbox" name="swap_latlon" />Geogr. Länge und Breite vertauschen</td><td></td></tr>
+    <tr><td><input type="checkbox" name="no_geoformat" /> Zielformat <strong>&lt;geo&gt;</strong> auslassen</td><td>47.222134 N 11.467211 E</td></tr>
+    <tr><td><input type="checkbox" name="no_gpxformat" /> Zielformat <strong>&lt;GPX&gt;</strong> auslassen</td><td>&lt;trkpt lat="47.181289" lon="11.408827"&gt;&lt;ele&gt;1090.57&lt;/ele&gt;&lt;/trkpt&gt;</td></tr>
+    <tr><td><input type="checkbox" name="no_gmapsformat" /> Zielformat <strong>Google Maps Plugin</strong> auslassen</td><td>47.232922, 11.452239</td></tr>
+    <tr><td><input type="submit" value="Konvertieren"/></td><td></td></tr>
+</table>
+</form>
+
+</body>
+</html>
index bd37ee1c3894adf480a786e61c6a06de6968e03d..2ff6aeb78c131c6744a5eb16669aaebd01b5f050 100644 (file)
@@ -19,6 +19,9 @@
     <li><a href="${h.url_for(controller='rodelbahn', action='list')}">Rodelbahnen</a></li>
     <li><a href="${h.url_for(controller='bericht', action='list')}">Rodelbahnberichte</a></li>
     <li><a href="${h.url_for(controller='gasthaus', action='list')}">Gasthäuser</a></li>
+    <li><a href="${h.url_for(controller='maptool', action='index')}">Maptool</a></li>
+    <li><a href="${h.url_for(controller='coordtool', action='index')}">Koordinaten-Rechner</a></li>
+    <li><a href="${h.url_for(controller='wrgpxtool', action='index')}">Winterrodeln-GPX Datei Werkzeuge</a></li>
 </ul>
 
 <ul>
diff --git a/wradmin/wradmin/templates/wrgpxtool.html b/wradmin/wradmin/templates/wrgpxtool.html
new file mode 100644 (file)
index 0000000..092b73b
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
+                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+    xmlns:py="http://genshi.edgewall.org/"
+    xmlns:xi="http://www.w3.org/2001/XInclude">
+<xi:include href="master.html" />
+
+<head>
+    <title>WRGPX-Werkzeug</title>
+</head>
+
+<body>
+
+<h2>WRGPX-Werkzeug</h2>
+
+<p>WRGPX steht für "Winterrodeln GPX".</p>
+
+
+</body>
+</html>
diff --git a/wradmin/wradmin/tests/functional/test_coordtool.py b/wradmin/wradmin/tests/functional/test_coordtool.py
new file mode 100644 (file)
index 0000000..a7c46a3
--- /dev/null
@@ -0,0 +1,7 @@
+from wradmin.tests import *
+
+class TestCoordtoolController(TestController):
+
+    def test_index(self):
+        response = self.app.get(url(controller='coordtool', action='index'))
+        # Test response...
diff --git a/wradmin/wradmin/tests/functional/test_wrgpxtool.py b/wradmin/wradmin/tests/functional/test_wrgpxtool.py
new file mode 100644 (file)
index 0000000..db22a41
--- /dev/null
@@ -0,0 +1,7 @@
+from wradmin.tests import *
+
+class TestWrgpxtoolController(TestController):
+
+    def test_index(self):
+        response = self.app.get(url(controller='wrgpxtool', action='index'))
+        # Test response...