mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
add gdal_rasterize tool to easily allow write over existing raster
This commit is contained in:
parent
10a51f672f
commit
a23a30cb94
@ -66,6 +66,7 @@ from GridNearest import GridNearest
|
|||||||
from GridDataMetrics import GridDataMetrics
|
from GridDataMetrics import GridDataMetrics
|
||||||
from gdaltindex import gdaltindex
|
from gdaltindex import gdaltindex
|
||||||
from gdalcalc import gdalcalc
|
from gdalcalc import gdalcalc
|
||||||
|
from rasterize_over import rasterize_over
|
||||||
|
|
||||||
from ogr2ogr import Ogr2Ogr
|
from ogr2ogr import Ogr2Ogr
|
||||||
from ogr2ogrclip import Ogr2OgrClip
|
from ogr2ogrclip import Ogr2OgrClip
|
||||||
@ -131,7 +132,7 @@ class GdalOgrAlgorithmProvider(AlgorithmProvider):
|
|||||||
sieve(), fillnodata(), ExtractProjection(), gdal2xyz(),
|
sieve(), fillnodata(), ExtractProjection(), gdal2xyz(),
|
||||||
hillshade(), slope(), aspect(), tri(), tpi(), roughness(),
|
hillshade(), slope(), aspect(), tri(), tpi(), roughness(),
|
||||||
ColorRelief(), GridInvDist(), GridAverage(), GridNearest(),
|
ColorRelief(), GridInvDist(), GridAverage(), GridNearest(),
|
||||||
GridDataMetrics(), gdaltindex(), gdalcalc(),
|
GridDataMetrics(), gdaltindex(), gdalcalc(), rasterize_over(),
|
||||||
# ----- OGR tools -----
|
# ----- OGR tools -----
|
||||||
OgrInfo(), Ogr2Ogr(), Ogr2OgrClip(), Ogr2OgrClipExtent(),
|
OgrInfo(), Ogr2Ogr(), Ogr2OgrClip(), Ogr2OgrClipExtent(),
|
||||||
Ogr2OgrToPostGis(), Ogr2OgrToPostGisList(), Ogr2OgrPointsOnLines(),
|
Ogr2OgrToPostGis(), Ogr2OgrToPostGisList(), Ogr2OgrPointsOnLines(),
|
||||||
|
75
python/plugins/processing/algs/gdal/rasterize_over.py
Normal file
75
python/plugins/processing/algs/gdal/rasterize_over.py
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
# -*- 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. *
|
||||||
|
* *
|
||||||
|
***************************************************************************
|
||||||
|
"""
|
||||||
|
|
||||||
|
__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
|
||||||
|
|
||||||
|
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
||||||
|
from processing.core.parameters import ParameterVector
|
||||||
|
from processing.core.parameters import ParameterRaster
|
||||||
|
from processing.core.parameters import ParameterTableField
|
||||||
|
from processing.core.parameters import ParameterSelection
|
||||||
|
from processing.core.outputs import OutputRaster
|
||||||
|
from processing.algs.gdal.OgrAlgorithm import OgrAlgorithm
|
||||||
|
from processing.algs.gdal.GdalUtils import GdalUtils
|
||||||
|
from processing.tools.system import isWindows
|
||||||
|
|
||||||
|
|
||||||
|
class rasterize_over(OgrAlgorithm):
|
||||||
|
|
||||||
|
INPUT = 'INPUT'
|
||||||
|
INPUT_RASTER = 'INPUT_RASTER'
|
||||||
|
FIELD = 'FIELD'
|
||||||
|
|
||||||
|
def commandLineName(self):
|
||||||
|
return "gdalogr:rasterize_over"
|
||||||
|
|
||||||
|
def defineCharacteristics(self):
|
||||||
|
self.name = 'Rasterize (write over existing raster)'
|
||||||
|
self.group = '[GDAL] Conversion'
|
||||||
|
self.addParameter(ParameterVector(self.INPUT, self.tr('Input layer')))
|
||||||
|
self.addParameter(ParameterTableField(self.FIELD,
|
||||||
|
self.tr('Attribute field'), self.INPUT))
|
||||||
|
self.addParameter(ParameterRaster(self.INPUT_RASTER,
|
||||||
|
self.tr('Existing raster layer'), False))
|
||||||
|
|
||||||
|
def processAlgorithm(self, progress):
|
||||||
|
inLayer = self.getParameterValue(self.INPUT)
|
||||||
|
ogrLayer = self.ogrConnectionString(inLayer)[1:-1]
|
||||||
|
inRasterLayer = self.getParameterValue(self.INPUT_RASTER)
|
||||||
|
ogrRasterLayer = self.ogrConnectionString(inRasterLayer)[1:-1]
|
||||||
|
|
||||||
|
arguments = []
|
||||||
|
arguments.append('-a')
|
||||||
|
arguments.append(str(self.getParameterValue(self.FIELD)))
|
||||||
|
|
||||||
|
arguments.append('-l')
|
||||||
|
arguments.append(self.ogrLayerName(inLayer))
|
||||||
|
arguments.append(ogrLayer)
|
||||||
|
arguments.append(ogrRasterLayer)
|
||||||
|
|
||||||
|
GdalUtils.runGdal(['gdal_rasterize',
|
||||||
|
GdalUtils.escapeAndJoin(arguments)], progress)
|
Loading…
x
Reference in New Issue
Block a user