2015-04-09 10:25:53 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
rasterize_over.py
|
|
|
|
---------------------
|
|
|
|
Date : September 2013
|
|
|
|
Copyright : (C) 2013 by Alexander Bruy
|
|
|
|
Email : alexander dot bruy 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. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
2016-09-21 18:24:26 +02:00
|
|
|
from builtins import str
|
2015-04-09 10:25:53 +01:00
|
|
|
|
|
|
|
__author__ = 'Alexander Bruy'
|
|
|
|
__date__ = 'September 2013'
|
|
|
|
__copyright__ = '(C) 2013, Alexander Bruy'
|
|
|
|
|
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
|
|
|
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
2016-04-22 10:38:48 +02:00
|
|
|
from qgis.PyQt.QtGui import QIcon
|
2016-01-25 15:42:11 +02:00
|
|
|
|
2015-04-09 10:25:53 +01:00
|
|
|
from processing.core.parameters import ParameterVector
|
|
|
|
from processing.core.parameters import ParameterRaster
|
|
|
|
from processing.core.parameters import ParameterTableField
|
2016-01-22 15:45:09 +02:00
|
|
|
|
|
|
|
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
2015-04-09 10:25:53 +01:00
|
|
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
|
|
|
|
2017-03-04 19:41:23 +01:00
|
|
|
from processing.tools import dataobjects
|
2016-01-22 15:45:09 +02:00
|
|
|
from processing.tools.vector import ogrConnectionString, ogrLayerName
|
|
|
|
|
2016-01-25 15:42:11 +02:00
|
|
|
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
|
|
|
|
|
2015-04-09 10:25:53 +01:00
|
|
|
|
2016-01-22 15:45:09 +02:00
|
|
|
class rasterize_over(GdalAlgorithm):
|
2015-04-09 10:25:53 +01:00
|
|
|
|
|
|
|
INPUT = 'INPUT'
|
|
|
|
INPUT_RASTER = 'INPUT_RASTER'
|
|
|
|
FIELD = 'FIELD'
|
|
|
|
|
2017-03-29 10:42:42 +10:00
|
|
|
def icon(self):
|
2016-01-25 15:42:11 +02:00
|
|
|
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'rasterize.png'))
|
|
|
|
|
2017-03-29 12:51:59 +10:00
|
|
|
def name(self):
|
2017-03-29 17:09:39 +10:00
|
|
|
return 'rasterize_over'
|
2017-03-29 12:51:59 +10:00
|
|
|
|
|
|
|
def displayName(self):
|
|
|
|
return self.tr('Rasterize (write over existing raster)')
|
|
|
|
|
2017-03-29 12:04:09 +10:00
|
|
|
def group(self):
|
|
|
|
return self.tr('Vector conversion')
|
|
|
|
|
2015-04-09 10:25:53 +01:00
|
|
|
def defineCharacteristics(self):
|
|
|
|
self.addParameter(ParameterVector(self.INPUT, self.tr('Input layer')))
|
|
|
|
self.addParameter(ParameterTableField(self.FIELD,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Attribute field'), self.INPUT))
|
2015-04-09 10:25:53 +01:00
|
|
|
self.addParameter(ParameterRaster(self.INPUT_RASTER,
|
2015-08-22 14:29:41 +02:00
|
|
|
self.tr('Existing raster layer'), False))
|
2015-04-09 10:25:53 +01:00
|
|
|
|
2015-10-08 20:29:40 +05:30
|
|
|
def getConsoleCommands(self):
|
2017-04-05 18:35:55 +10:00
|
|
|
inLayer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT))
|
|
|
|
inRasterLayer = dataobjects.getLayerFromString(self.getParameterValue(self.INPUT_RASTER))
|
2016-12-30 15:24:34 +02:00
|
|
|
|
2016-01-22 15:45:09 +02:00
|
|
|
ogrLayer = ogrConnectionString(inLayer)[1:-1]
|
|
|
|
ogrRasterLayer = ogrConnectionString(inRasterLayer)[1:-1]
|
2015-04-09 10:25:53 +01:00
|
|
|
|
|
|
|
arguments = []
|
|
|
|
arguments.append('-a')
|
2016-09-21 18:24:26 +02:00
|
|
|
arguments.append(str(self.getParameterValue(self.FIELD)))
|
2015-04-09 10:25:53 +01:00
|
|
|
|
|
|
|
arguments.append('-l')
|
2016-01-22 15:45:09 +02:00
|
|
|
arguments.append(ogrLayerName(inLayer))
|
2015-04-09 10:25:53 +01:00
|
|
|
arguments.append(ogrLayer)
|
|
|
|
arguments.append(ogrRasterLayer)
|
|
|
|
|
2015-05-07 13:14:01 +02:00
|
|
|
return ['gdal_rasterize', GdalUtils.escapeAndJoin(arguments)]
|