Skip to content
Permalink
Browse files

Update GDAL extractprojection.py to QGIS 3

  • Loading branch information
havatv committed Oct 30, 2018
1 parent 296df2e commit 79731715ed9622064b1557fe6b34f9c40a54eb9c
Showing with 14 additions and 10 deletions.
  1. +14 −10 python/plugins/processing/algs/gdal/extractprojection.py
@@ -32,8 +32,8 @@
from osgeo import gdal, osr

from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.core.parameters import ParameterRaster
from processing.core.parameters import ParameterBoolean
from qgis.core import (QgsProcessingParameterRasterLayer,
QgsProcessingParameterBoolean)

pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]

@@ -47,8 +47,8 @@ def __init__(self):
super().__init__()

def initAlgorithm(self, config=None):
self.addParameter(ParameterRaster(self.INPUT, self.tr('Input file')))
self.addParameter(ParameterBoolean(self.PRJ_FILE,
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input file')))
self.addParameter(QgsProcessingParameterBoolean(self.PRJ_FILE,
self.tr('Create also .prj file'), False))

def name(self):
@@ -73,13 +73,15 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
return [self.commandName()]

def processAlgorithm(self, parameters, context, feedback):
rasterPath = self.getParameterValue(self.INPUT)
createPrj = self.getParameterValue(self.PRJ_FILE)

raster = gdal.Open(str(rasterPath))
crs = raster.GetProjection()
geotransform = raster.GetGeoTransform()
createPrj = QgsProcessingParameterBoolean(self.PRJ_FILE)
raster = self.parameterAsRasterLayer(parameters, self.INPUT, context)
rasterPath = raster.source()
rasterDS = gdal.Open(rasterPath, gdal.GA_ReadOnly)
geotransform = rasterDS.GetGeoTransform()
inputcrs = raster.crs()
crs = inputcrs.toWkt()
raster = None
rasterDS = None

outFileName = os.path.splitext(str(rasterPath))[0]

@@ -104,3 +106,5 @@ def processAlgorithm(self, parameters, context, feedback):
wld.write('%0.8f\n' % (geotransform[3] +
0.5 * geotransform[4] +
0.5 * geotransform[5]))
return {}

0 comments on commit 7973171

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