diff options
Diffstat (limited to 'ishtar_common/models_common.py')
-rw-r--r-- | ishtar_common/models_common.py | 119 |
1 files changed, 101 insertions, 18 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index 5cbb5da1e..ebf480ff0 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -2876,7 +2876,10 @@ class SpatialReferenceSystem(GeneralType): class Meta: verbose_name = _("Spatial reference system") verbose_name_plural = _("Spatial reference systems") - ordering = ("label",) + ordering = ( + "order", + "label", + ) @classmethod def get_documentation_string(cls): @@ -2894,18 +2897,87 @@ post_save.connect(post_save_cache, sender=SpatialReferenceSystem) post_delete.connect(post_save_cache, sender=SpatialReferenceSystem) +class GeoOriginType(HierarchicalType): + """ + ex: topographical surveys, georeferencing, ... + """ + + order = models.IntegerField(_("Order"), default=10) + + class Meta: + verbose_name = _("Geographic - Origin type") + verbose_name_plural = _("Geographic - Origin types") + ordering = ( + "order", + "label", + ) + + +class GeoDataType(HierarchicalType): + """ + ex: outline, z-sup, ... + """ + + order = models.IntegerField(_("Order"), default=10) + + class Meta: + verbose_name = _("Geographic - Data type") + verbose_name_plural = _("Geographic - Data types") + ordering = ( + "order", + "label", + ) + + +class GeoProviderType(HierarchicalType): + """ + ex: GeoNames, IGN, ... + """ + + order = models.IntegerField(_("Order"), default=10) + + class Meta: + verbose_name = _("Geographic - Provider type") + verbose_name_plural = _("Geographic - Provider types") + ordering = ( + "order", + "label", + ) + + class GeoVectorData(models.Model): name = models.CharField(_("Name"), default=_("Default"), max_length=200) source_content_type = models.ForeignKey( - ContentType, related_name="content_type_geovectordata", - on_delete=models.CASCADE) + ContentType, related_name="content_type_geovectordata", on_delete=models.CASCADE + ) source_id = models.PositiveIntegerField() - source = GenericForeignKey('content_type', 'object_id') - + source = GenericForeignKey("source_content_type", "source_id") + origin = models.ForeignKey( + GeoOriginType, + blank=True, + null=True, + on_delete=models.PROTECT, + verbose_name=_("Origin"), + ) + data_type = models.ForeignKey( + GeoDataType, + blank=True, + null=True, + on_delete=models.PROTECT, + verbose_name=_("Data type"), + ) + provider = models.ForeignKey( + GeoProviderType, + blank=True, + null=True, + on_delete=models.PROTECT, + verbose_name=_("Provider"), + ) + comment = models.TextField(_("Comment"), default="", blank=True) x = models.FloatField(_("X"), blank=True, null=True, help_text=_("User input")) y = models.FloatField(_("Y"), blank=True, null=True, help_text=_("User input")) z = models.FloatField(_("Z"), blank=True, null=True, help_text=_("User input")) - # x == cached_x if user input else get it from point_2d + # x == cached_x if user input else get it from other sources # cached is converted to the display SRID cached_x = models.FloatField(_("X (cached)"), blank=True, null=True) cached_y = models.FloatField(_("Y (cached)"), blank=True, null=True) @@ -2926,14 +2998,16 @@ class GeoVectorData(models.Model): null=True, on_delete=models.PROTECT, ) - point = models.PointField(_("Point"), blank=True, null=True, dim=3) point_2d = models.PointField(_("Point (2D)"), blank=True, null=True) + point_3d = models.PointField(_("Point (3D)"), blank=True, null=True, dim=3) + multi_points = models.MultiPointField(_("Multi points"), blank=True, null=True) + multi_line = models.MultiLineStringField(_("Multi line"), blank=True, null=True) multi_polygon = models.MultiPolygonField(_("Multi polygon"), blank=True, null=True) need_update = models.BooleanField(_("Need update"), default=False) class Meta: - verbose_name = _("Geographic vector data") - verbose_name_plural = _("Geographic vector data") + verbose_name = _("Geographic - Vector data") + verbose_name_plural = _("Geographic - Vector data") def display_coordinates(self, rounded=5, dim=2, cache=True): srid = None @@ -2956,8 +3030,11 @@ class GeoVectorData(models.Model): if dim == 3: coordinates.append(self.z) else: - args = {"x": self.x, "y": self.y, - "srid": self.spatial_reference_system.srid} + args = { + "x": self.x, + "y": self.y, + "srid": self.spatial_reference_system.srid, + } if dim == 3: args["z"] = self.z point = Point(**args).transform(srid, clone=True) @@ -2967,8 +3044,8 @@ class GeoVectorData(models.Model): elif self.point_2d and dim == 2: point = self.point_2d.transform(srid, clone=True) coordinates = [point.x, point.y] - elif self.point and dim == 3: - point = self.point.transform(srid, clone=True) + elif self.point_3d and dim == 3: + point = self.point_3d.transform(srid, clone=True) coordinates = [point.x, point.y, point.z] else: return @@ -2978,8 +3055,9 @@ class GeoVectorData(models.Model): def get_coordinates_from_polygon(self, rounded=5, srid: int = None): if self.multi_polygon: - return self.convert_coordinates(self.multi_polygon.centroid, - rounded=rounded, srid=srid) + return self.convert_coordinates( + self.multi_polygon.centroid, rounded=rounded, srid=srid + ) def get_x(self, srid: int = None) -> float: coord = self.get_coordinates(srid) @@ -3097,16 +3175,21 @@ class GeoVectorData(models.Model): return self._geojson_serialize("multi_polygon") + + post_save.connect(post_save_geodata, sender=GeoVectorData) class GeoItem(models.Model): main_geodata = models.ForeignKey( - GeoVectorData, on_delete=models.SET_NULL, blank=True, null=True, - related_name="main_related_items_%(app_label)s_%(class)s" + GeoVectorData, + on_delete=models.SET_NULL, + blank=True, + null=True, + related_name="main_related_items_%(app_label)s_%(class)s", ) geodata = models.ManyToManyField( - GeoVectorData, null=True, related_name="related_items_%(app_label)s_%(class)s" + GeoVectorData, blank=True, related_name="related_items_%(app_label)s_%(class)s" ) GEO_SOURCE = (("T", _("Town")), ("P", _("Precise")), ("M", _("Polygon"))) |