summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2023-06-08 14:31:50 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2023-06-08 15:42:43 +0200
commita27b447ae2c9afc73078dd9aedd7709145e1d537 (patch)
treea796f46aed73677a06495d7323964af8d81568a5
parent0112faa3ca8e199f6a3e9ba0ab6a89d1b9eade10 (diff)
downloadIshtar-a27b447ae2c9afc73078dd9aedd7709145e1d537.tar.bz2
Ishtar-a27b447ae2c9afc73078dd9aedd7709145e1d537.zip
✨ models: default round and round z for each spatial reference system - 🐛 fix precise_town_id migration
-rw-r--r--changelog/en/changelog_2022-06-15.md1
-rw-r--r--changelog/fr/changelog_2023-01-25.md1
-rw-r--r--ishtar_common/migrations/0229_auto_20230608_1303.py101
-rw-r--r--ishtar_common/models_common.py47
4 files changed, 143 insertions, 7 deletions
diff --git a/changelog/en/changelog_2022-06-15.md b/changelog/en/changelog_2022-06-15.md
index 10a126566..56270084d 100644
--- a/changelog/en/changelog_2022-06-15.md
+++ b/changelog/en/changelog_2022-06-15.md
@@ -2,6 +2,7 @@ v4.0.48 - 2023-
--------------------
### Technical ###
+- Default round and round z for each spatial reference system
- Do not put debug log in root path on Debian
diff --git a/changelog/fr/changelog_2023-01-25.md b/changelog/fr/changelog_2023-01-25.md
index 96f39b212..1a249b6e0 100644
--- a/changelog/fr/changelog_2023-01-25.md
+++ b/changelog/fr/changelog_2023-01-25.md
@@ -2,6 +2,7 @@ v4.0.48 - 2023-
--------------------
### Technique ###
+- arrondi et arrondi en z par défaut pour chaque système de référence spatiale
- ne pas mettre le journal de débogage dans le répertoire projet sous Debian
diff --git a/ishtar_common/migrations/0229_auto_20230608_1303.py b/ishtar_common/migrations/0229_auto_20230608_1303.py
new file mode 100644
index 000000000..c33a42238
--- /dev/null
+++ b/ishtar_common/migrations/0229_auto_20230608_1303.py
@@ -0,0 +1,101 @@
+# Generated by Django 2.2.24 on 2023-06-08 13:03
+
+from django.db import migrations, models
+
+
+COPY_HISTORICALORGANIZATION = """
+UPDATE ishtar_common_historicalorganization
+SET precise_town_id2 = precise_town_id
+"""
+COPY_ORGANIZATION = """
+UPDATE ishtar_common_organization
+SET precise_town_id2 = precise_town_id
+"""
+COPY_HISTORICALPERSON = """
+UPDATE ishtar_common_historicalperson
+SET precise_town_id2 = precise_town_id
+"""
+COPY_PERSON = """
+UPDATE ishtar_common_person
+SET precise_town_id2 = precise_town_id
+"""
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('ishtar_common', '0228_auto_20230418_1622'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='historicalorganization',
+ name='precise_town_id2',
+ field=models.PositiveIntegerField(blank=True, null=True, verbose_name='Town (precise)'),
+ ),
+ migrations.AddField(
+ model_name='historicalperson',
+ name='precise_town_id2',
+ field=models.PositiveIntegerField(blank=True, null=True, verbose_name='Town (precise)'),
+ ),
+ migrations.AddField(
+ model_name='organization',
+ name='precise_town_id2',
+ field=models.PositiveIntegerField(blank=True, null=True, verbose_name='Town (precise)'),
+ ),
+ migrations.AddField(
+ model_name='person',
+ name='precise_town_id2',
+ field=models.PositiveIntegerField(blank=True, null=True, verbose_name='Town (precise)'),
+ ),
+ migrations.RunSQL(COPY_PERSON),
+ migrations.RunSQL(COPY_HISTORICALPERSON),
+ migrations.RunSQL(COPY_ORGANIZATION),
+ migrations.RunSQL(COPY_HISTORICALORGANIZATION),
+ migrations.RemoveField(
+ model_name='historicalorganization',
+ name='precise_town',
+ ),
+ migrations.RemoveField(
+ model_name='historicalperson',
+ name='precise_town',
+ ),
+ migrations.RemoveField(
+ model_name='organization',
+ name='precise_town',
+ ),
+ migrations.RemoveField(
+ model_name='person',
+ name='precise_town',
+ ),
+ migrations.RenameField(
+ model_name='historicalorganization',
+ old_name='precise_town_id2',
+ new_name='precise_town_id'
+ ),
+ migrations.RenameField(
+ model_name='historicalperson',
+ old_name='precise_town_id2',
+ new_name='precise_town_id'
+ ),
+ migrations.RenameField(
+ model_name='organization',
+ old_name='precise_town_id2',
+ new_name='precise_town_id'
+ ),
+ migrations.RenameField(
+ model_name='person',
+ old_name='precise_town_id2',
+ new_name='precise_town_id'
+ ),
+ migrations.AddField(
+ model_name='spatialreferencesystem',
+ name='round',
+ field=models.IntegerField(default=5, verbose_name='Number of decimal places'),
+ ),
+ migrations.AddField(
+ model_name='spatialreferencesystem',
+ name='round_z',
+ field=models.IntegerField(default=3, verbose_name='Number of decimal places for Z'),
+ ),
+ ]
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index a8e377209..a6f5d1197 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -2221,6 +2221,8 @@ class SpatialReferenceSystem(GeneralType):
order = models.IntegerField(_("Order"), default=10)
auth_name = models.CharField(_("Authority name"), default="EPSG", max_length=256)
srid = models.IntegerField(_("Authority SRID"))
+ round = models.IntegerField(_("Number of decimal places"), default=5)
+ round_z = models.IntegerField(_("Number of decimal places for Z"), default=3)
class Meta:
verbose_name = _("Geographic - Spatial reference system")
@@ -2523,19 +2525,38 @@ class GeoVectorData(Imported, OwnPerms):
def source_label(self):
return str(self.source)
- def display_coordinates(self, rounded=5, dim=2, srid=None, cache=True):
+ def display_coordinates_3d(self):
+ return self.display_coordinates(dim=3)
+
+ def display_coordinates(self, rounded=None, rounded_z=None, dim=2, srid=None, cache=True):
+ spatial_reference_system = None
if not srid:
if self.spatial_reference_system and self.spatial_reference_system.srid:
- srid = self.spatial_reference_system.srid
+ spatial_reference_system = self.spatial_reference_system
else:
profile = get_current_profile()
if profile.display_srs and profile.display_srs.srid:
- srid = profile.display_srs.srid
+ spatial_reference_system = profile.display_srs
+ srid = spatial_reference_system.srid
if not srid:
srid = 4326
- return self.get_coordinates(rounded=rounded, srid=srid, dim=dim, cache=cache)
+ q = SpatialReferenceSystem.objects.filter(srid=srid)
+ if q.count():
+ spatial_reference_system = q.all()[0]
+ if not rounded:
+ if spatial_reference_system:
+ rounded = spatial_reference_system.round
+ else:
+ rounded = 5
+ if not rounded_z:
+ if spatial_reference_system:
+ rounded_z = spatial_reference_system.round_z
+ else:
+ rounded_z = 3
+ return self.get_coordinates(rounded=rounded, rounded_z=rounded_z, srid=srid, dim=dim,
+ cache=cache)
- def get_coordinates(self, rounded=5, srid: int = None, dim=2, cache=False):
+ def get_coordinates(self, rounded=5, rounded_z=3, srid: int = None, dim=2, cache=False):
if dim not in (2, 3):
raise ValueError(_("Only 2 or 3 dimensions"))
if cache and srid == 4326:
@@ -2593,9 +2614,21 @@ class GeoVectorData(Imported, OwnPerms):
coordinates = [x, y]
else:
coordinates = [x, y, point.z]
- if not rounded:
+ if rounded is None:
return coordinates
- return [round(coord or 0, rounded) for coord in coordinates]
+ if coordinates[0]:
+ if rounded <= 0:
+ coordinates[0] = int(coordinates[0])
+ coordinates[1] = int(coordinates[1])
+ else:
+ coordinates[0] = round(coordinates[0] or 0, rounded)
+ coordinates[1] = round(coordinates[1] or 0, rounded)
+ if dim == 3 and rounded_z is not None and coordinates[2] is not None:
+ if rounded_z <= 0:
+ coordinates[2] = round(coordinates[2] or 0, rounded_z)
+ else:
+ coordinates[2] = round(coordinates[2] or 0, rounded_z)
+ return coordinates
def get_coordinates_from_polygon(self, rounded=5, srid: int = None):
if self.multi_polygon: