beautified bounding box coordinate output

pull/24/head
Hartmut Holzgraefe 2018-10-14 11:29:34 +02:00
rodzic 7c6a508703
commit 8b52dbcb25
3 zmienionych plików z 51 dodań i 4 usunięć

Wyświetl plik

@ -180,8 +180,13 @@
<td>{{ map.administrative_city }} ({{ map.administrative_osmid }})</td></tr>
{% else %}
<tr><td><strong>{% trans "Bounding box" %}</strong></td>
<td>({{ map.lat_upper_left }}, {{ map.lon_upper_left }}) &rarr;
({{ map.lat_bottom_right }}, {{ map.lon_bottom_right }})</td></tr>
<td>
{{ map.lat_upper_left|latitude }}, {{ map.lon_upper_left|longitude }}
&rarr;
{{ map.lat_bottom_right|latitude }}, {{ map.lon_bottom_right|longitude }}
&nbsp;&nbsp;&nbsp;({{ map|bbox_km }})
</td>
</tr>
{% endif %}
<tr><td><strong>{% trans "Layout" %}</strong></td>
<td>{{ map.layout }}</td></tr>

Wyświetl plik

@ -54,8 +54,12 @@
<td>{{ map.administrative_city }} ({{ map.administrative_osmid }})</td>
{% else %}
<td><strong>{% trans "Bounding Box" %}</strong></td>
<td>({{ map.lat_upper_left|floatformat:3 }}, {{ map.lon_upper_left|floatformat:3 }}) &rarr;
({{ map.lat_bottom_right|floatformat:3 }}, {{ map.lon_bottom_right|floatformat:3 }})</td>
<td>
{{ map.lat_upper_left|latitude }}, {{ map.lon_upper_left|longitude }}
&rarr;
{{ map.lat_bottom_right|latitude }}, {{ map.lon_bottom_right|longitude }}
&nbsp;&nbsp;&nbsp;({{ map|bbox_km }})
</td>
{% endif %}
<td rowspan="0" align="right" width="210">
{% if map.get_thumbnail %}

Wyświetl plik

@ -30,6 +30,8 @@ from django.utils.translation import ugettext_lazy as _
import www.settings
import ocitysmap
register = template.Library()
def job_status_to_str(value, arg, autoescape=None):
@ -67,9 +69,45 @@ def file_basename(value):
def add_blank_after_comma(value):
return value.replace(",",", ")
def _dd2dms(value):
degrees = abs(int(value))
minsec = value - degrees
minutes = int(minsec * 60)
seconds = (minsec % 60) / float(3600)
return (degrees, minutes, seconds)
def latitude(value):
latitude = float(value)
(degrees, minutes, seconds) = _dd2dms(latitude)
hemisphere = 'N' if latitude >= 0 else 'S'
return "%d°%d'%d\"%s" % (degrees, minutes, seconds, hemisphere)
def longitude(value):
latitude = float(value)
(degrees, minutes, seconds) = _dd2dms(latitude)
hemisphere = 'E' if latitude >= 0 else 'W'
return "%d°%d'%d\"%s" % (degrees, minutes, seconds, hemisphere)
def bbox_km(value):
boundingbox = ocitysmap.coords.BoundingBox(
value.lat_upper_left,
value.lon_upper_left,
value.lat_bottom_right,
value.lon_bottom_right)
(height, width) = boundingbox.spheric_sizes()
return "ca. %d x %d km²" % (width/1000, height/1000)
register.filter('job_status_to_str', job_status_to_str)
register.filter('feedparsed', feedparsed)
register.filter('abs', lambda x: abs(x))
register.filter('getitem', lambda d,i: d.get(i,''))
register.filter('file_basename', file_basename)
register.filter('add_blank_after_comma', add_blank_after_comma)
register.filter('latitude', latitude)
register.filter('longitude', longitude)
register.filter('bbox_km', bbox_km)