diff options
Diffstat (limited to 'ishtar_common')
| -rw-r--r-- | ishtar_common/migrations/0229_auto_20230608_1303.py | 101 | ||||
| -rw-r--r-- | ishtar_common/models_common.py | 47 | 
2 files changed, 141 insertions, 7 deletions
| 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: | 
