Skip to content

Commit a23a30c

Browse files
author
Giovanni Manghi
committedApr 9, 2015
add gdal_rasterize tool to easily allow write over existing raster
1 parent 10a51f6 commit a23a30c

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed
 

‎python/plugins/processing/algs/gdal/GdalOgrAlgorithmProvider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
from GridDataMetrics import GridDataMetrics
6767
from gdaltindex import gdaltindex
6868
from gdalcalc import gdalcalc
69+
from rasterize_over import rasterize_over
6970

7071
from ogr2ogr import Ogr2Ogr
7172
from ogr2ogrclip import Ogr2OgrClip
@@ -131,7 +132,7 @@ def createAlgsList(self):
131132
sieve(), fillnodata(), ExtractProjection(), gdal2xyz(),
132133
hillshade(), slope(), aspect(), tri(), tpi(), roughness(),
133134
ColorRelief(), GridInvDist(), GridAverage(), GridNearest(),
134-
GridDataMetrics(), gdaltindex(), gdalcalc(),
135+
GridDataMetrics(), gdaltindex(), gdalcalc(), rasterize_over(),
135136
# ----- OGR tools -----
136137
OgrInfo(), Ogr2Ogr(), Ogr2OgrClip(), Ogr2OgrClipExtent(),
137138
Ogr2OgrToPostGis(), Ogr2OgrToPostGisList(), Ogr2OgrPointsOnLines(),
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
rasterize_over.py
6+
---------------------
7+
Date : September 2013
8+
Copyright : (C) 2013 by Alexander Bruy
9+
Email : alexander dot bruy at gmail dot com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Alexander Bruy'
21+
__date__ = 'September 2013'
22+
__copyright__ = '(C) 2013, Alexander Bruy'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
import os
29+
30+
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
31+
from processing.core.parameters import ParameterVector
32+
from processing.core.parameters import ParameterRaster
33+
from processing.core.parameters import ParameterTableField
34+
from processing.core.parameters import ParameterSelection
35+
from processing.core.outputs import OutputRaster
36+
from processing.algs.gdal.OgrAlgorithm import OgrAlgorithm
37+
from processing.algs.gdal.GdalUtils import GdalUtils
38+
from processing.tools.system import isWindows
39+
40+
41+
class rasterize_over(OgrAlgorithm):
42+
43+
INPUT = 'INPUT'
44+
INPUT_RASTER = 'INPUT_RASTER'
45+
FIELD = 'FIELD'
46+
47+
def commandLineName(self):
48+
return "gdalogr:rasterize_over"
49+
50+
def defineCharacteristics(self):
51+
self.name = 'Rasterize (write over existing raster)'
52+
self.group = '[GDAL] Conversion'
53+
self.addParameter(ParameterVector(self.INPUT, self.tr('Input layer')))
54+
self.addParameter(ParameterTableField(self.FIELD,
55+
self.tr('Attribute field'), self.INPUT))
56+
self.addParameter(ParameterRaster(self.INPUT_RASTER,
57+
self.tr('Existing raster layer'), False))
58+
59+
def processAlgorithm(self, progress):
60+
inLayer = self.getParameterValue(self.INPUT)
61+
ogrLayer = self.ogrConnectionString(inLayer)[1:-1]
62+
inRasterLayer = self.getParameterValue(self.INPUT_RASTER)
63+
ogrRasterLayer = self.ogrConnectionString(inRasterLayer)[1:-1]
64+
65+
arguments = []
66+
arguments.append('-a')
67+
arguments.append(str(self.getParameterValue(self.FIELD)))
68+
69+
arguments.append('-l')
70+
arguments.append(self.ogrLayerName(inLayer))
71+
arguments.append(ogrLayer)
72+
arguments.append(ogrRasterLayer)
73+
74+
GdalUtils.runGdal(['gdal_rasterize',
75+
GdalUtils.escapeAndJoin(arguments)], progress)

0 commit comments

Comments
 (0)
Please sign in to comment.