summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-03-27 22:26:17 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-06-17 13:21:27 +0200
commitaba701cfb26a9432cd306ba832a5357b0705ae01 (patch)
tree2067a3d383585047b046804bc084d4a23ee6c5a3 /ishtar_common
parent4c9b8bc864e9138a31303a9d0744c853e431f37d (diff)
downloadIshtar-aba701cfb26a9432cd306ba832a5357b0705ae01.tar.bz2
Ishtar-aba701cfb26a9432cd306ba832a5357b0705ae01.zip
Sheet: add a display projection for coordinates
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/migrations/0091_ishtarsiteprofile_display_srs.py21
-rw-r--r--ishtar_common/models.py24
-rw-r--r--ishtar_common/templates/ishtar/blocks/sheet_coordinates.html13
3 files changed, 52 insertions, 6 deletions
diff --git a/ishtar_common/migrations/0091_ishtarsiteprofile_display_srs.py b/ishtar_common/migrations/0091_ishtarsiteprofile_display_srs.py
new file mode 100644
index 000000000..abccb6efd
--- /dev/null
+++ b/ishtar_common/migrations/0091_ishtarsiteprofile_display_srs.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.18 on 2019-03-27 22:07
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('ishtar_common', '0090_auto_20190327_1854'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='ishtarsiteprofile',
+ name='display_srs',
+ field=models.ForeignKey(blank=True, help_text='Spatial Reference System used for display when no SRS is defined', null=True, on_delete=django.db.models.deletion.CASCADE, to='ishtar_common.SpatialReferenceSystem', verbose_name='Spatial Reference System for display'),
+ ),
+ ]
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index c246380d5..a17bcac03 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -1765,6 +1765,23 @@ class GeoItem(models.Model):
def get_town_polygons(self):
raise NotImplementedError
+ @property
+ def display_coordinates(self):
+ if not self.point_2d:
+ return ""
+ profile = get_current_profile()
+ if not profile.display_srs or not profile.display_srs.srid:
+ return self.x, self.y
+ point = self.point_2d.transform(profile.display_srs.srid, clone=True)
+ return round(point.x, 5), round(point.y, 5)
+
+ @property
+ def display_spatial_reference_system(self):
+ profile = get_current_profile()
+ if not profile.display_srs or not profile.display_srs.srid:
+ return self.spatial_reference_system
+ return profile.display_srs
+
def get_precise_points(self):
if self.point_source == 'P' and self.point_2d:
return self.point_2d, self.point, self.point_source_item
@@ -2526,6 +2543,13 @@ class IshtarSiteProfile(models.Model, Cached):
default='SRID=4326;POINT(2.4397 46.5528)')
default_zoom = models.IntegerField(
_("Maps - default zoom"), default=6)
+ display_srs = models.ForeignKey(
+ SpatialReferenceSystem,
+ verbose_name=_("Spatial Reference System for display"),
+ blank=True, null=True,
+ help_text=_("Spatial Reference System used for display when no SRS is "
+ "defined")
+ )
class Meta:
verbose_name = _("Ishtar site profile")
diff --git a/ishtar_common/templates/ishtar/blocks/sheet_coordinates.html b/ishtar_common/templates/ishtar/blocks/sheet_coordinates.html
index ff0586515..dbcecef8c 100644
--- a/ishtar_common/templates/ishtar/blocks/sheet_coordinates.html
+++ b/ishtar_common/templates/ishtar/blocks/sheet_coordinates.html
@@ -3,16 +3,17 @@
<dl class="col-12">
<dt>{% trans "Coordinates" %}</dt>
<dd>
- {% trans "X:"%} {{geo_item.x|default_if_none:"-"}}
+ {% with coordinates=geo_item.display_coordinates %}
+ {% trans "X:"%} {{coordinates.0|default_if_none:"-"}}
{% if geo_item.estimated_error_x %} ({% trans "error:" %} {{geo_item.estimated_error_x}}){% endif %},
- {% trans "Y:"%} {{geo_item.y|default_if_none:"-"}},
+ {% trans "Y:"%} {{coordinates.1|default_if_none:"-"}}
{% if geo_item.estimated_error_y %} ({% trans "error:" %} {{geo_item.estimated_error_y}}){% endif %},
+ {% endwith %}
{% trans "Z:"%} {{geo_item.z|default_if_none:"-"}}
{% if geo_item.estimated_error_z %} ({% trans "error:" %} {{geo_item.estimated_error_z}}){% endif %}
- {% if geo_item.spatial_reference_system %}
- &ndash; {{geo_item.spatial_reference_system.label}}{% if geo_item.spatial_reference_system.srid %} -
- {% trans "SRID"%} {{geo_item.spatial_reference_system.srid}}{% endif %}
- {% endif %}
+ {% with srs=geo_item.display_spatial_reference_system %}
+ {% if srs %} &ndash; {{srs.label}} - {% trans "SRID"%} {{srs.srid}} {% endif %}
+ {% endwith %}
</dd>
</dl>
{% if geo_item.most_precise_geo == 'point' %}