Geometry Model geom SRID migration

* adds two new migrations for transforming existing geometries into the default SRID
This commit is contained in:
mpeltriaux 2022-07-13 08:19:27 +02:00
parent 16107f93f6
commit 0e7859e538
2 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,35 @@
# Generated by Django 3.1.3 on 2022-07-13 06:01
import django
from django.db import migrations
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP
def migrate_geometry_srs(apps, schema_editor):
Geometry = apps.get_model("konova", "Geometry")
all_geoms = Geometry.objects.all()
# Transform all geoms and store in new geom field
for geometry in all_geoms:
geom = geometry.geom
if geom is None:
continue
geom.transform(DEFAULT_SRID_RLP)
geometry.geom_tmp = geom
geometry.save()
class Migration(migrations.Migration):
dependencies = [
('konova', '0011_auto_20220420_1101'),
]
operations = [
migrations.AddField(
model_name="geometry",
name="geom_tmp",
field=django.contrib.gis.db.models.fields.MultiPolygonField(blank=True, null=True, srid=DEFAULT_SRID_RLP)
),
migrations.RunPython(migrate_geometry_srs),
]

View File

@ -0,0 +1,22 @@
# Generated by Django 3.1.3 on 2022-07-13 06:14
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('konova', '0012_auto_20220713_0801'),
]
operations = [
migrations.RemoveField(
model_name="geometry",
name="geom"
),
migrations.RenameField(
model_name="geometry",
old_name="geom_tmp",
new_name="geom"
),
]