geometry_srid_migration #183
35
konova/migrations/0012_auto_20220713_0801.py
Normal file
35
konova/migrations/0012_auto_20220713_0801.py
Normal 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),
|
||||
]
|
22
konova/migrations/0013_auto_20220713_0814.py
Normal file
22
konova/migrations/0013_auto_20220713_0814.py
Normal 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"
|
||||
),
|
||||
]
|
Loading…
Reference in New Issue
Block a user