templatetags: add |reproj to transform lon/lat to given map projection (#34966)
This commit is contained in:
parent
498b807d34
commit
7cc5ecd635
|
@ -6,6 +6,7 @@ import string
|
|||
|
||||
from django.test import override_settings
|
||||
from quixote import cleanup
|
||||
from qommon.substitution import CompatibilityNamesDict
|
||||
from qommon.template import Template, TemplateError
|
||||
from wcs.conditions import Condition
|
||||
from wcs.variables import LazyFormData
|
||||
|
@ -511,3 +512,13 @@ def test_get_filter():
|
|||
|
||||
tmpl = Template('{{ foo|get:0 }}')
|
||||
assert tmpl.render({'foo': ['bar', 'baz']}) == 'bar'
|
||||
|
||||
def test_reproj():
|
||||
|
||||
class MockFormData(object):
|
||||
formdef = None
|
||||
geolocations = {'base': {'lat': 48, 'lon': 2}}
|
||||
|
||||
lazy_formdata = LazyFormData(MockFormData())
|
||||
tmpl = Template('{% with form_geoloc_base|reproj:"EPSG:3946" as c %}{{c.0}}/{{c.1}}{% endwith %}')
|
||||
assert tmpl.render(CompatibilityNamesDict({'form': lazy_formdata})) == '1625337.15483/5422836.71627'
|
||||
|
|
|
@ -23,6 +23,7 @@ import math
|
|||
import string
|
||||
import random
|
||||
|
||||
import pyproj
|
||||
from pyproj import Geod
|
||||
|
||||
from django import template
|
||||
|
@ -341,3 +342,9 @@ def distance_filter(queryset, distance=1000):
|
|||
@register.filter
|
||||
def order_by(queryset, attribute):
|
||||
return queryset.order_by(attribute)
|
||||
|
||||
@register.filter
|
||||
def reproj(coords, projection_name):
|
||||
proj = pyproj.Proj(init='EPSG:4326')
|
||||
target_proj = pyproj.Proj(init=projection_name)
|
||||
return pyproj.transform(proj, target_proj, coords['lon'], coords['lat'])
|
||||
|
|
Loading…
Reference in New Issue