2012-10-04 19:33:47 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
warp.py
|
|
|
|
---------------------
|
|
|
|
Date : August 2012
|
|
|
|
Copyright : (C) 2012 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2013-02-24 16:07:21 +01:00
|
|
|
import os
|
|
|
|
from qgis.core import *
|
2012-09-15 18:25:25 +03:00
|
|
|
from PyQt4 import QtGui
|
|
|
|
from sextante.core.GeoAlgorithm import GeoAlgorithm
|
|
|
|
from sextante.parameters.ParameterRaster import ParameterRaster
|
|
|
|
from sextante.outputs.OutputRaster import OutputRaster
|
|
|
|
from sextante.parameters.ParameterSelection import ParameterSelection
|
|
|
|
from sextante.parameters.ParameterCrs import ParameterCrs
|
2012-10-17 22:03:40 +02:00
|
|
|
from sextante.gdal.GdalUtils import GdalUtils
|
2013-02-24 16:07:21 +01:00
|
|
|
from sextante.parameters.ParameterNumber import ParameterNumber
|
|
|
|
from sextante.parameters.ParameterString import ParameterString
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
class warp(GeoAlgorithm):
|
|
|
|
|
|
|
|
INPUT = "INPUT"
|
|
|
|
OUTPUT = "OUTPUT"
|
|
|
|
SOURCE_SRS = "SOURCE_SRS"
|
|
|
|
DEST_SRS = "DEST_SRS "
|
|
|
|
METHOD = "METHOD"
|
|
|
|
METHOD_OPTIONS = ["near", "bilinear", "cubic", "cubicspline", "lanczos"]
|
2013-02-24 16:07:21 +01:00
|
|
|
TR = "TR"
|
|
|
|
EXTRA = "EXTRA"
|
2012-09-15 18:25:25 +03:00
|
|
|
|
|
|
|
def getIcon(self):
|
|
|
|
filepath = os.path.dirname(__file__) + "/icons/warp.png"
|
|
|
|
return QtGui.QIcon(filepath)
|
|
|
|
|
|
|
|
def defineCharacteristics(self):
|
2012-11-10 00:31:01 +01:00
|
|
|
self.name = "Warp (reproject)"
|
|
|
|
self.group = "[GDAL] Projections"
|
2012-09-15 18:25:25 +03:00
|
|
|
self.addParameter(ParameterRaster(warp.INPUT, "Input layer", False))
|
2013-01-04 23:02:44 +01:00
|
|
|
self.addParameter(ParameterCrs(warp.SOURCE_SRS, "Source SRS (EPSG Code)", "EPSG:4326"))
|
|
|
|
self.addParameter(ParameterCrs(warp.DEST_SRS, "Destination SRS (EPSG Code)", "EPSG:4326"))
|
2013-02-24 16:07:21 +01:00
|
|
|
self.addParameter(ParameterNumber(warp.TR, "Output file resolution in target georeferenced units (leave 0 for no change)", 0.0, None, 0.0))
|
2012-09-15 18:25:25 +03:00
|
|
|
self.addParameter(ParameterSelection(warp.METHOD, "Resampling method", warp.METHOD_OPTIONS))
|
2013-02-24 16:07:21 +01:00
|
|
|
self.addParameter(ParameterString(warp.EXTRA, "Additional creation parameters", " "))
|
2012-09-15 18:25:25 +03:00
|
|
|
self.addOutput(OutputRaster(warp.OUTPUT, "Output layer"))
|
|
|
|
|
|
|
|
def processAlgorithm(self, progress):
|
|
|
|
srs = self.getParameterValue(warp.DEST_SRS)
|
2013-01-26 23:55:14 +01:00
|
|
|
self.crs = QgsCoordinateReferenceSystem(srs)
|
2012-09-15 18:25:25 +03:00
|
|
|
commands = ["gdalwarp"]
|
|
|
|
commands.append("-s_srs")
|
2013-01-04 23:02:44 +01:00
|
|
|
commands.append(str(self.getParameterValue(warp.SOURCE_SRS)))
|
2012-09-15 18:25:25 +03:00
|
|
|
commands.append("-t_srs")
|
2013-01-04 23:02:44 +01:00
|
|
|
commands.append(str(srs))
|
2012-09-15 18:25:25 +03:00
|
|
|
commands.append("-r")
|
|
|
|
commands.append(warp.METHOD_OPTIONS[self.getParameterValue(warp.METHOD)])
|
|
|
|
commands.append("-of")
|
|
|
|
out = self.getOutputValue(warp.OUTPUT)
|
|
|
|
commands.append(GdalUtils.getFormatShortNameFromFilename(out))
|
2013-02-24 16:07:21 +01:00
|
|
|
if self.getParameterValue(warp.TR) != 0:
|
|
|
|
trStr = "-tr "+str(self.getParameterValue(warp.TR))+" "+str(self.getParameterValue(warp.TR))
|
|
|
|
commands.append(trStr)
|
2013-02-28 22:08:32 +01:00
|
|
|
commands.append(str(self.getParameterValue(warp.EXTRA)))
|
2012-09-15 18:25:25 +03:00
|
|
|
commands.append(self.getParameterValue(warp.INPUT))
|
|
|
|
commands.append(out)
|
|
|
|
|
|
|
|
GdalUtils.runGdal(commands, progress)
|