diff options
Diffstat (limited to 'ishtar_common/models_common.py')
| -rw-r--r-- | ishtar_common/models_common.py | 47 | 
1 files changed, 40 insertions, 7 deletions
| diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index a8e377209..a6f5d1197 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -2221,6 +2221,8 @@ class SpatialReferenceSystem(GeneralType):      order = models.IntegerField(_("Order"), default=10)      auth_name = models.CharField(_("Authority name"), default="EPSG", max_length=256)      srid = models.IntegerField(_("Authority SRID")) +    round = models.IntegerField(_("Number of decimal places"), default=5) +    round_z = models.IntegerField(_("Number of decimal places for Z"), default=3)      class Meta:          verbose_name = _("Geographic - Spatial reference system") @@ -2523,19 +2525,38 @@ class GeoVectorData(Imported, OwnPerms):      def source_label(self):          return str(self.source) -    def display_coordinates(self, rounded=5, dim=2, srid=None, cache=True): +    def display_coordinates_3d(self): +        return self.display_coordinates(dim=3) + +    def display_coordinates(self, rounded=None, rounded_z=None, dim=2, srid=None, cache=True): +        spatial_reference_system = None          if not srid:              if self.spatial_reference_system and self.spatial_reference_system.srid: -                srid = self.spatial_reference_system.srid +                spatial_reference_system = self.spatial_reference_system              else:                  profile = get_current_profile()                  if profile.display_srs and profile.display_srs.srid: -                    srid = profile.display_srs.srid +                    spatial_reference_system = profile.display_srs +            srid = spatial_reference_system.srid          if not srid:              srid = 4326 -        return self.get_coordinates(rounded=rounded, srid=srid, dim=dim, cache=cache) +            q = SpatialReferenceSystem.objects.filter(srid=srid) +            if q.count(): +                spatial_reference_system = q.all()[0] +        if not rounded: +            if spatial_reference_system: +                rounded = spatial_reference_system.round +            else: +                rounded = 5 +        if not rounded_z: +            if spatial_reference_system: +                rounded_z = spatial_reference_system.round_z +            else: +                rounded_z = 3 +        return self.get_coordinates(rounded=rounded, rounded_z=rounded_z, srid=srid, dim=dim, +                                    cache=cache) -    def get_coordinates(self, rounded=5, srid: int = None, dim=2, cache=False): +    def get_coordinates(self, rounded=5, rounded_z=3, srid: int = None, dim=2, cache=False):          if dim not in (2, 3):              raise ValueError(_("Only 2 or 3 dimensions"))          if cache and srid == 4326: @@ -2593,9 +2614,21 @@ class GeoVectorData(Imported, OwnPerms):                      coordinates = [x, y]                  else:                      coordinates = [x, y, point.z] -        if not rounded: +        if rounded is None:              return coordinates -        return [round(coord or 0, rounded) for coord in coordinates] +        if coordinates[0]: +            if rounded <= 0: +                coordinates[0] = int(coordinates[0]) +                coordinates[1] = int(coordinates[1]) +            else: +                coordinates[0] = round(coordinates[0] or 0, rounded) +                coordinates[1] = round(coordinates[1] or 0, rounded) +        if dim == 3 and rounded_z is not None and coordinates[2] is not None: +            if rounded_z <= 0: +                coordinates[2] = round(coordinates[2] or 0, rounded_z) +            else: +                coordinates[2] = round(coordinates[2] or 0, rounded_z) +        return coordinates      def get_coordinates_from_polygon(self, rounded=5, srid: int = None):          if self.multi_polygon: | 
