diff options
author | QuentinAndre <quentin.andre@imt-atlantique.net> | 2021-07-06 18:58:53 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-07-08 09:58:48 +0200 |
commit | e9898ed41c220e102801a441d7d23d69787b5cf2 (patch) | |
tree | f9830f17a8cfa5aa46ad43b2685d722283177065 /ishtar_common/models_common.py | |
parent | 033576e879647ec05b7d7110c4ea2a0d5f6fb62a (diff) | |
download | Ishtar-e9898ed41c220e102801a441d7d23d69787b5cf2.tar.bz2 Ishtar-e9898ed41c220e102801a441d7d23d69787b5cf2.zip |
test + geo_get_items
Diffstat (limited to 'ishtar_common/models_common.py')
-rw-r--r-- | ishtar_common/models_common.py | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index f21a74a12..ebf9fbc41 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -2858,20 +2858,23 @@ class GeoItem(models.Model): def get_geo_items(self, get_polygons=False, rounded=True): dict = {} - if get_polygons and self.multi_polygon: + if self.multi_polygon: i = 0 - for polygon in self.multi_polygon: - i += 1 - for linearRing in range(len(polygon)): - if linearRing == 0: - key = "external" - else: - key = "internal" - key += "Polygon" + str(i) - dict[key] = [] - for coords in polygon[linearRing]: - point_2d = GEOSGeometry("POINT({} {})".format(coords[0], coords[1]), srid=self.multi_polygon.srid) - dict[key].append(self.convert_coordinates(point_2d, rounded)) + if get_polygons: + for polygon in self.multi_polygon: + i += 1 + for linearRing in range(len(polygon)): + if linearRing == 0: + key = "external" + else : + key = "internal" + key += "Polygon" + str(i) + dict[key] = [] + for coords in polygon[linearRing]: + point_2d = GEOSGeometry("POINT({} {})".format(coords[0], coords[1]), srid=self.multi_polygon.srid) + dict[key].append(self.convert_coordinates(point_2d, rounded)) + else: + dict["centroid"] = self.convert_coordinates(self.multi_polygon.centroid, rounded) else: dict["centroid"] = self.display_coordinates return dict |