diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-01-12 10:08:57 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:23 +0100 |
commit | c482d09651451301e3c27fbfcc0455bb5f150d5b (patch) | |
tree | 0ac8b3ad6c1293a4a163d40546a656bcbd67d871 /ishtar_common/models_common.py | |
parent | e67a7ac0e246985beec12a8193928fe0f7e09280 (diff) | |
download | Ishtar-c482d09651451301e3c27fbfcc0455bb5f150d5b.tar.bz2 Ishtar-c482d09651451301e3c27fbfcc0455bb5f150d5b.zip |
X, Y fields to export in the default SRS
Diffstat (limited to 'ishtar_common/models_common.py')
-rw-r--r-- | ishtar_common/models_common.py | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index 3bd97e192..6d8db23e0 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -2526,9 +2526,9 @@ class GeoItem(models.Model): ) # gis - x = models.FloatField(_(u'X'), blank=True, null=True) - y = models.FloatField(_(u'Y'), blank=True, null=True) - z = models.FloatField(_(u'Z'), blank=True, null=True) + x = models.FloatField(_('X'), blank=True, null=True) + y = models.FloatField(_('Y'), blank=True, null=True) + z = models.FloatField(_('Z'), blank=True, null=True) estimated_error_x = models.FloatField(_(u'Estimated error for X'), blank=True, null=True) estimated_error_y = models.FloatField(_(u'Estimated error for Y'), @@ -2565,14 +2565,37 @@ class GeoItem(models.Model): raise NotImplementedError @property - def display_coordinates(self): + def X(self): + """x coordinates using the default SRS""" + coord = self.display_coordinates + if not coord: + return + return coord[0] + + @property + def Y(self): + """y coordinates using the default SRS""" + coord = self.display_coordinates + if not coord: + return + return coord[1] + + @property + def display_coordinates(self, rounded=True): 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) + if not profile.display_srs or not profile.display_srs.srid or ( + profile.display_srs == self.spatial_reference_system + and self.x and self.y): + x, y = self.x, self.y + else: + point = self.point_2d.transform(profile.display_srs.srid, + clone=True) + x, y = point.x, point.y + if rounded: + return round(x, 5), round(y, 5) + return x, y @property def display_spatial_reference_system(self): |