diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-02-14 17:01:18 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-04-24 19:38:56 +0200 |
commit | 19428f8e1b30e92497fb87833e8d333feaf2ef81 (patch) | |
tree | 3abd9f70021cf3195ebf3a0d72cc85be9bafbc69 /ishtar_common | |
parent | 16b54ce820e0f522164a12819ffc18197be59b33 (diff) | |
download | Ishtar-19428f8e1b30e92497fb87833e8d333feaf2ef81.tar.bz2 Ishtar-19428f8e1b30e92497fb87833e8d333feaf2ef81.zip |
Fix geo post save (bad overload of source)
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/models.py | 5 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/blocks/sheet_coordinates.html | 4 | ||||
-rw-r--r-- | ishtar_common/utils.py | 32 |
3 files changed, 29 insertions, 12 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 8d3d5df9a..778461562 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1620,6 +1620,11 @@ class GeoItem(object): return "" return dict(self.GEO_SOURCE)[self.point_source] + def geo_polygon_source(self): + if not self.multi_polygon_source: + return "" + return dict(self.GEO_SOURCE)[self.multi_polygon_source] + def _geojson_serialize(self, geom_attr): if not hasattr(self, geom_attr): return "" diff --git a/ishtar_common/templates/ishtar/blocks/sheet_coordinates.html b/ishtar_common/templates/ishtar/blocks/sheet_coordinates.html index 8637853e3..bd0c1ef19 100644 --- a/ishtar_common/templates/ishtar/blocks/sheet_coordinates.html +++ b/ishtar_common/templates/ishtar/blocks/sheet_coordinates.html @@ -14,5 +14,9 @@ {% endif %} </dd> </dl> +{% if geo_item.point_source == 'P' or not geo_item.multi_polygon %} {% field_flex_full "Point source" geo_item.geo_point_source %} +{% else %} +{% field_flex_full "Polygon source" geo_item.geo_polygon_source %} +{% endif %} {% endif %} diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 25cc8f84c..408309c4e 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -469,13 +469,26 @@ def convert_coordinates_to_point(x, y, z=None, srid=4326): return geom +def get_srid_obj_from_point(point): + from ishtar_common.models import SpatialReferenceSystem + try: + return SpatialReferenceSystem.objects.get( + srid=int(point.srid)) + except SpatialReferenceSystem.DoesNotExist: + return SpatialReferenceSystem.objects.create( + srid=int(point.srid), + auth_name='EPSG', + label=u"EPSG-{}".format(point.srid), + txt_idx=u"epsg-{}".format(point.srid), + ) + + def post_save_geo(sender, **kwargs): """ Convert raw x, y, z point to real geo field """ if not kwargs.get('instance'): return - from ishtar_common.models import SpatialReferenceSystem from ishtar_common.models import get_current_profile # not clean but utils # is loaded before models @@ -493,23 +506,14 @@ def post_save_geo(sender, **kwargs): current_point = point_2d instance.x = current_point.x instance.y = current_point.y - try: - srs = SpatialReferenceSystem.objects.get( - srid=int(current_point.srid)) - except SpatialReferenceSystem.DoesNotExist: - srs = SpatialReferenceSystem.objects.create( - srid=int(current_point.srid), - auth_name='EPSG', - label=u"EPSG-{}".format(current_point.srid), - txt_idx=u"epsg-{}".format(current_point.srid), - ) + srs = get_srid_obj_from_point(current_point) instance.spatial_reference_system = srs instance.point_source = 'P' if not point_2d: instance.point_2d = convert_coordinates_to_point( instance.point.x, instance.point.y, srid=current_point.srid) - elif instance.x and instance.y and \ + elif not instance.point_source and instance.x and instance.y and \ instance.spatial_reference_system and \ instance.spatial_reference_system.auth_name == 'EPSG' and \ instance.spatial_reference_system.srid != 0: # form input @@ -534,6 +538,10 @@ def post_save_geo(sender, **kwargs): if point_2d != instance.point_2d: instance.point_2d = point_2d instance.point_source = 'T' # town + instance.x = point_2d.x + instance.y = point_2d.y + srs = get_srid_obj_from_point(point_2d) + instance.spatial_reference_system = srs modified = True if not hasattr(instance, 'multi_polygon'): |