summaryrefslogtreecommitdiff
path: root/ishtar_common/utils.py
diff options
context:
space:
mode:
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
commita59c4cba89c09d60674ee6a70eadea1b4e14a08c (patch)
tree3abd9f70021cf3195ebf3a0d72cc85be9bafbc69 /ishtar_common/utils.py
parent265d0180cc945281a93efc2f1278959594727e57 (diff)
downloadIshtar-a59c4cba89c09d60674ee6a70eadea1b4e14a08c.tar.bz2
Ishtar-a59c4cba89c09d60674ee6a70eadea1b4e14a08c.zip
Fix geo post save (bad overload of source)
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r--ishtar_common/utils.py32
1 files changed, 20 insertions, 12 deletions
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'):