Skip to content
Permalink
Browse files

[processing] remove unused code

  • Loading branch information
alexbruy committed Aug 1, 2017
1 parent 1443590 commit 27f4d42b2322c00a27fe1a9afce6c24c0e34e0ff
Showing with 0 additions and 78 deletions.
  1. +0 −78 python/plugins/processing/tools/raster.py
@@ -38,39 +38,6 @@
from qgis.core import QgsProcessingException


RASTER_EXTENSION_MAP = None


def initGdalData():
global RASTER_EXTENSION_MAP

if RASTER_EXTENSION_MAP is not None:
return

if gdal.GetDriverCount() == 0:
gdal.AllRegister()

RASTER_EXTENSION_MAP = dict()
for i in range(gdal.GetDriverCount()):
driver = gdal.GetDriver(i)
if driver is None:
continue
md = driver.GetMetadata()
if gdal.DCAP_CREATE in md and md[gdal.DCAP_CREATE].lower() == 'yes':
ext = md[gdal.DMD_EXTENSION] if gdal.DMD_EXTENSION in md else None
if ext is not None and ext != '':
RASTER_EXTENSION_MAP[driver.ShortName] = ext


def formatShortNameFromFileName(fileName):
initGdalData()
ext = os.path.splitext(fileName)[1][1:]
for k, v in RASTER_EXTENSION_MAP.items():
if ext == v:
return k
return 'GTiff'


def scanraster(layer, feedback):
filename = str(layer.source())
dataset = gdal.Open(filename, gdal.GA_ReadOnly)
@@ -111,48 +78,3 @@ def mapToPixel(mX, mY, geoTransform):

def pixelToMap(pX, pY, geoTransform):
return gdal.ApplyGeoTransform(geoTransform, pX + 0.5, pY + 0.5)


class RasterWriter(object):

NODATA = -99999.0

def __init__(self, fileName, minx, miny, maxx, maxy, cellsize,
nbands, crs, geotransform=None):
self.fileName = fileName
self.nx = int((maxx - minx) / float(cellsize))
self.ny = int((maxy - miny) / float(cellsize))
self.nbands = nbands
self.matrix = numpy.empty(shape=(self.ny, self.nx), dtype=numpy.float32)
self.matrix.fill(self.NODATA)
self.cellsize = cellsize
self.crs = crs
self.minx = minx
self.maxy = maxy
self.geotransform = geotransform

def setValue(self, value, x, y, band=0):
try:
self.matrix[y, x] = value
except IndexError:
pass

def getValue(self, x, y, band=0):
try:
return self.matrix[y, x]
except IndexError:
return self.NODATA

def close(self):
fmt = 'GTiff'
driver = gdal.GetDriverByName(fmt)
dst_ds = driver.Create(self.fileName, self.nx, self.ny, 1,
gdal.GDT_Float32)
dst_ds.SetProjection(str(self.crs.toWkt()))
if self.geotransform is None:
dst_ds.SetGeoTransform([self.minx, self.cellsize, 0,
self.maxy, self.cellsize, 0])
else:
dst_ds.SetGeoTransform(self.geotransform)
dst_ds.GetRasterBand(1).WriteArray(self.matrix)
dst_ds = None

0 comments on commit 27f4d42

Please sign in to comment.
You can’t perform that action at this time.