From b36bd54a551eedb1129e60c3edc558591d417b9a Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 15 Mar 2022 13:02:28 +0100 Subject: Geodata: fix cached value update for geovector --- ishtar_common/models_common.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'ishtar_common/models_common.py') 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] -- cgit v1.2.3