0001-templatetags-add-reproj-to-transform-lon-lat-to-give.patch
tests/test_templates.py | ||
---|---|---|
6 | 6 | |
7 | 7 |
from django.test import override_settings |
8 | 8 |
from quixote import cleanup |
9 |
from qommon.substitution import CompatibilityNamesDict |
|
9 | 10 |
from qommon.template import Template, TemplateError |
10 | 11 |
from wcs.conditions import Condition |
11 | 12 |
from wcs.variables import LazyFormData |
... | ... | |
511 | 512 | |
512 | 513 |
tmpl = Template('{{ foo|get:0 }}') |
513 | 514 |
assert tmpl.render({'foo': ['bar', 'baz']}) == 'bar' |
515 | ||
516 |
def test_reproj(): |
|
517 | ||
518 |
class MockFormData(object): |
|
519 |
formdef = None |
|
520 |
geolocations = {'base': {'lat': 48, 'lon': 2}} |
|
521 | ||
522 |
lazy_formdata = LazyFormData(MockFormData()) |
|
523 |
tmpl = Template('{% with form_geoloc_base|reproj:"EPSG:3946" as c %}{{c.0}}/{{c.1}}{% endwith %}') |
|
524 |
assert tmpl.render(CompatibilityNamesDict({'form': lazy_formdata})) == '1625337.15483/5422836.71627' |
wcs/qommon/templatetags/qommon.py | ||
---|---|---|
23 | 23 |
import string |
24 | 24 |
import random |
25 | 25 | |
26 |
import pyproj |
|
26 | 27 |
from pyproj import Geod |
27 | 28 | |
28 | 29 |
from django import template |
... | ... | |
341 | 342 |
@register.filter |
342 | 343 |
def order_by(queryset, attribute): |
343 | 344 |
return queryset.order_by(attribute) |
345 | ||
346 |
@register.filter |
|
347 |
def reproj(coords, projection_name): |
|
348 |
proj = pyproj.Proj(init='EPSG:4326') |
|
349 |
target_proj = pyproj.Proj(init=projection_name) |
|
350 |
return pyproj.transform(proj, target_proj, coords['lon'], coords['lat']) |
|
344 |
- |