From c8d3021cee3397e200df30eac12984b5770adb6c Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 27 Oct 2017 17:51:52 +0200 Subject: Command import_insee_comm_csv: import town relations --- ishtar_common/models.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'ishtar_common/models.py') diff --git a/ishtar_common/models.py b/ishtar_common/models.py index a06568d99..36da56cad 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -2688,6 +2688,25 @@ class Town(Imported, models.Model): self.save() return self.cached_label + def generate_geo(self): + if self.limit: + return + parents = None + if not self.parents.count(): + return + for parent in self.parents.all(): + if not parent.limit: + return + if not parents: + parents = parent.limit + else: + parents = parents.union(parent.limit) + # if union is a simple polygon make it a multi + if 'MULTI' not in parents.wkt: + parents = parents.wkt.replace('POLYGON', 'MULTIPOLYGON(') + ")" + self.limit = parents + return self.limit + def _generate_cached_label(self): cached_label = self.name if settings.COUNTRY == "fr": -- cgit v1.2.3