2017-07-07 14:48:11 +00:00
|
|
|
# -*- 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
|
|
|
|
|
2017-07-12 12:56:43 +00:00
|
|
|
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)
|
|
|
|
|
2017-07-07 14:48:11 +00:00
|
|
|
def transfer_existing_orthophoto_extent_values(apps, schema_editor):
|
2017-07-10 14:30:33 +00:00
|
|
|
Task = apps.get_model('app', 'Task')
|
2017-07-07 14:48:11 +00:00
|
|
|
|
|
|
|
for t in Task.objects.all():
|
|
|
|
print("Checking {}".format(t))
|
2017-07-12 12:56:43 +00:00
|
|
|
orthophoto_path = assets_path(t.project.id, t.id, "odm_orthophoto", "odm_orthophoto_4326.tif")
|
2017-07-07 14:48:11 +00:00
|
|
|
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),
|
|
|
|
]
|