zhongrj
2025-11-25 b89962006164a462404b79a738bee8cbb6d7fe7e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-07-07 14:14
from __future__ import unicode_literals
 
from django.contrib.gis.gdal import GDALRaster, OGRGeometry
from django.contrib.gis.geos import GEOSGeometry
from django.db import migrations
import os
 
from webodm import settings
 
 
def assets_path(project_id, task_id, *args):
    return os.path.join(settings.MEDIA_ROOT,
                        "project",
                        str(project_id),
                        "task",
                        str(task_id),
                        "assets",
                        *args)
 
def transfer_existing_orthophoto_extent_values(apps, schema_editor):
    Task = apps.get_model('app', 'Task')
 
    for t in Task.objects.all():
        print("Checking {}".format(t))
        orthophoto_path = assets_path(t.project.id, t.id, "odm_orthophoto", "odm_orthophoto_4326.tif")
        if os.path.exists(orthophoto_path):
            print("Migrating {}".format(orthophoto_path))
 
            raster = GDALRaster(orthophoto_path)
            geom = OGRGeometry.from_bbox(raster.extent)
            t.orthophoto_extent = GEOSGeometry(geom.wkt)
            t.save()
 
            os.remove(orthophoto_path)
 
class Migration(migrations.Migration):
 
    dependencies = [
        ('app', '0004_auto_20170707_1014'),
    ]
 
    operations = [
        migrations.RunPython(transfer_existing_orthophoto_extent_values),
    ]