Migrate orthophoto to orthophoto_extent field

pull/230/head
Piero Toffanin 2017-07-07 10:48:11 -04:00
rodzic 30014f9ecf
commit 99d07b303d
4 zmienionych plików z 67 dodań i 17 usunięć

Wyświetl plik

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-07-07 14:14
from __future__ import unicode_literals
import django.contrib.gis.db.models.fields
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('app', '0003_auto_20170615_1300'),
]
operations = [
migrations.RemoveField(
model_name='task',
name='orthophoto',
),
migrations.AddField(
model_name='task',
name='orthophoto_extent',
field=django.contrib.gis.db.models.fields.GeometryField(blank=True, help_text='Extent of the orthophoto created by OpenDroneMap', null=True, srid=4326),
),
]

Wyświetl plik

@ -0,0 +1,34 @@
# -*- 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
from app.models import Task
import os
def transfer_existing_orthophoto_extent_values(apps, schema_editor):
for t in Task.objects.all():
print("Checking {}".format(t))
orthophoto_path = t.assets_path("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),
]

Wyświetl plik

@ -18,7 +18,8 @@ from guardian.models import UserObjectPermissionBase
from guardian.shortcuts import get_perms_for_model, assign_perm
from app import pending_actions
from app.postgis import OffDbRasterField
from django.contrib.gis.db.models.fields import GeometryField
from nodeodm import status_codes
from nodeodm.exceptions import ProcessingError, ProcessingTimeout, ProcessingException
from nodeodm.models import ProcessingNode
@ -146,9 +147,8 @@ class Task(models.Model):
console_output = models.TextField(null=False, default="", blank=True, help_text="Console output of the OpenDroneMap's process")
ground_control_points = models.FileField(null=True, blank=True, upload_to=gcp_directory_path, help_text="Optional Ground Control Points file to use for processing")
# georeferenced_model
orthophoto = OffDbRasterField(null=True, blank=True, srid=4326, help_text="Orthophoto created by OpenDroneMap")
# textured_model
orthophoto_extent = GeometryField(null=True, blank=True, srid=4326, help_text="Extent of the orthophoto created by OpenDroneMap")
# mission
created_at = models.DateTimeField(default=timezone.now, help_text="Creation date")
pending_action = models.IntegerField(choices=PENDING_ACTIONS, db_index=True, null=True, blank=True, help_text="A requested action to be performed on the task. The selected action will be performed by the scheduler at the next iteration.")

Wyświetl plik

@ -1,4 +1,5 @@
from django.contrib.gis.gdal import GDALRaster
from django.contrib.gis.geos import GEOSGeometry
from django.db import InternalError
from django.db import transaction
@ -14,18 +15,8 @@ class TestApi(BootTestCase):
pass
def test_db(self):
# Make sure we can use PostGIS raster type
raster = GDALRaster(os.path.realpath(os.path.join("app", "fixtures", "orthophoto.tif")), write=True)
self.assertTrue(raster.srid == 32615)
with transaction.atomic():
# We cannot store offdb references with SRID different than the one declared (4326)
self.assertRaises(InternalError, Task.objects.create, project=Project.objects.latest("created_at"),
orthophoto=raster)
# All OK when we transform to 4326
# Make sure we can use PostGIS geometry type
task = Task.objects.create(project=Project.objects.latest("created_at"),
orthophoto=raster.transform(4326))
orthophoto_extent=GEOSGeometry("POINT(1 2)"))
task.refresh_from_db()
self.assertTrue(task.orthophoto.srid == 4326)
self.assertTrue(task.orthophoto.width == 252) # not original size, warp happened
self.assertTrue(task.orthophoto_extent is not None)