summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ishtar_common/models_common.py28
-rw-r--r--ishtar_common/utils.py9
2 files changed, 23 insertions, 14 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]
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index a7e07ebde..88c9129a3 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -774,16 +774,13 @@ def _post_save_geodata(sender, **kwargs):
modified = True
# managed cached coordinates
- # TODO
cached_x, cached_y, cached_z = None, None, None
- coords = instance.display_coordinates(rounded=False, dim=3)
- if coords:
+ coords = instance.display_coordinates(rounded=False, dim=3, cache=False)
+ if coords and coords != [None, None, None]:
cached_x, cached_y, cached_z = coords
else:
- coords = instance.display_coordinates(rounded=False, dim=2)
- if not coords:
- coords = instance.get_coordinates_from_polygon(rounded=False)
+ coords = instance.display_coordinates(rounded=False, dim=2, cache=False)
if coords:
cached_x, cached_y = coords