diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-03-15 13:02:28 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:21:00 +0100 |
commit | b36bd54a551eedb1129e60c3edc558591d417b9a (patch) | |
tree | 4ddf8a8cdee6f14f97ef9df28d32f40250f4bf64 /ishtar_common/models_common.py | |
parent | 4770486294b3c85ec986521abf4fbd8fe64d92ae (diff) | |
download | Ishtar-b36bd54a551eedb1129e60c3edc558591d417b9a.tar.bz2 Ishtar-b36bd54a551eedb1129e60c3edc558591d417b9a.zip |
Geodata: fix cached value update for geovector
Diffstat (limited to 'ishtar_common/models_common.py')
-rw-r--r-- | ishtar_common/models_common.py | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index 9aae922cc..a7f9bd2fd 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -2147,7 +2147,7 @@ class GeoVectorData(models.Model): if dim == 3: coordinates.append(self.cached_z) else: - if self.x and self.y: # user input + if self.x or self.y or self.z: # user input if not srid or srid == self.spatial_reference_system.srid: coordinates = [self.x, self.y] if dim == 3: @@ -2164,14 +2164,26 @@ class GeoVectorData(models.Model): coordinates = [point.x, point.y] if dim == 3: coordinates.append(point.z) - elif self.point_2d and dim == 2: - point = self.point_2d.transform(srid, clone=True) - coordinates = [point.x, point.y] - elif self.point_3d and dim == 3: - point = self.point_3d.transform(srid, clone=True) - coordinates = [point.x, point.y, point.z] else: - return + if self.point_2d and dim == 2: + geom = self.point_2d + elif self.point_3d and dim == 3: + geom = self.point_3d + elif self.multi_points: + geom = self.multi_points.centroid + elif self.multi_line: + geom = self.multi_line.centroid + elif self.multi_polygon: + geom = self.multi_polygon.centroid + else: + if dim == 2: + return [None, None] + return [None, None, None] + point = geom.transform(srid, clone=True) + if dim == 2: + coordinates = [point.x, point.y] + else: + coordinates = [point.x, point.y, point.z] if not rounded: return coordinates return [round(coord, rounded) for coord in coordinates] |