From 7a720c2166a88b01fbd08971e15eaa3b0ee5386d Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Thu, 26 Sep 2013 21:03:10 +0300 Subject: [PATCH] [processing] sync GDAL algorithm names with Raster menu --- .../gdal/GdalOgrAlgorithmProvider.py | 20 +++-- .../processing/gdal/extractprojection.py | 79 ++++++++++++++++++ python/plugins/processing/gdal/gdaladdo.py | 2 +- ...ctprojection.png => projection-export.png} | Bin python/plugins/processing/gdal/nearblack.py | 2 +- python/plugins/processing/gdal/ogr2ogr.py | 4 +- python/plugins/processing/gdal/ogrinfo.py | 2 +- python/plugins/processing/gdal/pct2rgb.py | 2 +- python/plugins/processing/gdal/polygonize.py | 2 +- python/plugins/processing/gdal/proximity.py | 2 +- python/plugins/processing/gdal/rasterize.py | 4 +- python/plugins/processing/gdal/rgb2pct.py | 2 +- .../gdal/scripts/extractprojection.py | 67 --------------- 13 files changed, 100 insertions(+), 88 deletions(-) create mode 100644 python/plugins/processing/gdal/extractprojection.py rename python/plugins/processing/gdal/icons/{extractprojection.png => projection-export.png} (100%) delete mode 100644 python/plugins/processing/gdal/scripts/extractprojection.py diff --git a/python/plugins/processing/gdal/GdalOgrAlgorithmProvider.py b/python/plugins/processing/gdal/GdalOgrAlgorithmProvider.py index 23178bbc124..e2204f75ac7 100644 --- a/python/plugins/processing/gdal/GdalOgrAlgorithmProvider.py +++ b/python/plugins/processing/gdal/GdalOgrAlgorithmProvider.py @@ -50,6 +50,7 @@ from processing.gdal.rasterize import rasterize from processing.gdal.proximity import proximity from processing.gdal.sieve import sieve from processing.gdal.fillnodata import fillnodata +from processing.gdal.extractprojection import ExtractProjection from processing.gdal.ogr2ogr import Ogr2Ogr from processing.gdal.ogrinfo import OgrInfo @@ -100,19 +101,20 @@ class GdalOgrAlgorithmProvider(AlgorithmProvider): rgb2pct(), pct2rgb(), merge(), polygonize(), gdaladdo(), ClipByExtent(), ClipByMask(), contour(), rasterize(), proximity(), sieve(), - fillnodata(), + fillnodata(), ExtractProjection(), OgrInfo(), Ogr2Ogr(), OgrSql()] #And then we add those that are created as python scripts folder = self.scriptsFolder() - for descriptionFile in os.listdir(folder): - if descriptionFile.endswith("py"): - try: - fullpath = os.path.join(self.scriptsFolder(), descriptionFile) - alg = GdalAlgorithm(fullpath) - self.preloadedAlgs.append(alg) - except WrongScriptException,e: - ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,e.msg) + if os.path.exists(folder): + for descriptionFile in os.listdir(folder): + if descriptionFile.endswith("py"): + try: + fullpath = os.path.join(self.scriptsFolder(), descriptionFile) + alg = GdalAlgorithm(fullpath) + self.preloadedAlgs.append(alg) + except WrongScriptException,e: + ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,e.msg) def getSupportedOutputRasterLayerExtensions(self): return GdalUtils.getSupportedRasterExtensions() diff --git a/python/plugins/processing/gdal/extractprojection.py b/python/plugins/processing/gdal/extractprojection.py new file mode 100644 index 00000000000..56c4fee9d56 --- /dev/null +++ b/python/plugins/processing/gdal/extractprojection.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + extractprojection.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 osgeo import gdal, osr +from PyQt4.QtGui import * + +from processing.core.GeoAlgorithm import GeoAlgorithm +from processing.parameters.ParameterRaster import ParameterRaster +from processing.parameters.ParameterBoolean import ParameterBoolean + + +class ExtractProjection(GeoAlgorithm): + + INPUT = "INPUT" + PRJ_FILE = "PRJ_FILE" + + def getIcon(self): + return QIcon(os.path.dirname(__file__) + "/icons/projection-export.png") + + def defineCharacteristics(self): + self.name = "Extract projection" + self.group = "[GDAL] Projections" + self.addParameter(ParameterRaster(self.INPUT, "Input file")) + self.addParameter(ParameterBoolean(self.PRJ_FILE, "Create also .prj file", False)) + + def processAlgorithm(self, progress): + rasterPath = self.getParameterValue(self.INPUT) + createPrj = self.getParameterValue(self.PRJ_FILE) + + raster = gdal.Open(unicode(rasterPath)) + crs = raster.GetProjection() + geotransform = raster.GetGeoTransform() + raster = None + + outFileName = os.path.splitext(unicode(rasterPath))[0] + + if crs != "" and createPrj: + tmp = osr.SpatialReference() + tmp.ImportFromWkt( crs ) + tmp.MorphToESRI() + crs = tmp.ExportToWkt() + tmp = None + + prj = open(outFileName + '.prj', 'wt') + prj.write( crs ) + prj.close() + + wld = open(outFileName + '.wld', 'wt') + wld.write("%0.8f\n" % geotransform[1]) + wld.write("%0.8f\n" % geotransform[4]) + wld.write("%0.8f\n" % geotransform[2]) + wld.write("%0.8f\n" % geotransform[5]) + wld.write("%0.8f\n" % (geotransform[0] + 0.5 * geotransform[1] + 0.5 * geotransform[2])) + wld.write("%0.8f\n" % (geotransform[3] + 0.5 * geotransform[4] + 0.5 * geotransform[5])) + wld.close() diff --git a/python/plugins/processing/gdal/gdaladdo.py b/python/plugins/processing/gdal/gdaladdo.py index e5bf0ffe5aa..5eb22a72af7 100644 --- a/python/plugins/processing/gdal/gdaladdo.py +++ b/python/plugins/processing/gdal/gdaladdo.py @@ -59,7 +59,7 @@ class gdaladdo(GeoAlgorithm): return QtGui.QIcon(filepath) def defineCharacteristics(self): - self.name = "Build pyramids (overviews)" + self.name = "Build overviews (pyramids)" self.group = "[GDAL] Miscellaneous" self.addParameter(ParameterRaster(self.INPUT, "Input layer", False)) self.addParameter(ParameterString(self.LEVELS, "Overview levels", "2 4 8 16")) diff --git a/python/plugins/processing/gdal/icons/extractprojection.png b/python/plugins/processing/gdal/icons/projection-export.png similarity index 100% rename from python/plugins/processing/gdal/icons/extractprojection.png rename to python/plugins/processing/gdal/icons/projection-export.png diff --git a/python/plugins/processing/gdal/nearblack.py b/python/plugins/processing/gdal/nearblack.py index 4c54e3be84e..36e259d9d93 100644 --- a/python/plugins/processing/gdal/nearblack.py +++ b/python/plugins/processing/gdal/nearblack.py @@ -46,7 +46,7 @@ class nearblack(GeoAlgorithm): return QtGui.QIcon(filepath) def defineCharacteristics(self): - self.name = "Nearblack" + self.name = "Near black" self.group = "[GDAL] Analysis" self.addParameter(ParameterRaster(nearblack.INPUT, "Input layer", False)) self.addParameter(ParameterNumber(nearblack.NEAR, "How far from black (white)", 0, None, 15)) diff --git a/python/plugins/processing/gdal/ogr2ogr.py b/python/plugins/processing/gdal/ogr2ogr.py index 02980d5b84e..305217bd723 100644 --- a/python/plugins/processing/gdal/ogr2ogr.py +++ b/python/plugins/processing/gdal/ogr2ogr.py @@ -57,8 +57,8 @@ class Ogr2Ogr(OgrAlgorithm): DEST_DSCO = "DEST_DSCO" def defineCharacteristics(self): - self.name = "ogr2ogr" - self.group = "[OGR] Transformation" + self.name = "Convert format" + self.group = "[OGR] Conversion" #we add the input vector layer. It can have any kind of geometry #It is a mandatory (not optional) one, hence the False argument diff --git a/python/plugins/processing/gdal/ogrinfo.py b/python/plugins/processing/gdal/ogrinfo.py index da3ad337e3d..311965495dd 100644 --- a/python/plugins/processing/gdal/ogrinfo.py +++ b/python/plugins/processing/gdal/ogrinfo.py @@ -48,7 +48,7 @@ class OgrInfo(OgrAlgorithm): INPUT_LAYER = "INPUT_LAYER" def defineCharacteristics(self): - self.name = "ogrinfo" + self.name = "Information" self.group = "[OGR] Miscellaneous" self.addParameter(ParameterVector(self.INPUT_LAYER, "Input layer", [ParameterVector.VECTOR_TYPE_ANY], False)) diff --git a/python/plugins/processing/gdal/pct2rgb.py b/python/plugins/processing/gdal/pct2rgb.py index 3d7c63ddd4c..a50929a11cc 100644 --- a/python/plugins/processing/gdal/pct2rgb.py +++ b/python/plugins/processing/gdal/pct2rgb.py @@ -46,7 +46,7 @@ class pct2rgb(GeoAlgorithm): return QtGui.QIcon(filepath) def defineCharacteristics(self): - self.name = "pct2rgb" + self.name = "PCT to RGB" self.group = "[GDAL] Conversion" self.addParameter(ParameterRaster(pct2rgb.INPUT, "Input layer", False)) options = [] diff --git a/python/plugins/processing/gdal/polygonize.py b/python/plugins/processing/gdal/polygonize.py index 51609b04af7..0b6b13bcb67 100644 --- a/python/plugins/processing/gdal/polygonize.py +++ b/python/plugins/processing/gdal/polygonize.py @@ -47,7 +47,7 @@ class polygonize(GeoAlgorithm): return QtGui.QIcon(filepath) def defineCharacteristics(self): - self.name = "Polygonize" + self.name = "Polygonize (raster to vector)" self.group = "[GDAL] Conversion" self.addParameter(ParameterRaster(polygonize.INPUT, "Input layer", False)) self.addParameter(ParameterString(polygonize.FIELD, "Output field name", "DN")) diff --git a/python/plugins/processing/gdal/proximity.py b/python/plugins/processing/gdal/proximity.py index a8bb5e39a88..dd22016da4a 100644 --- a/python/plugins/processing/gdal/proximity.py +++ b/python/plugins/processing/gdal/proximity.py @@ -55,7 +55,7 @@ class proximity(GeoAlgorithm): return QtGui.QIcon(filepath) def defineCharacteristics(self): - self.name = "Proximity" + self.name = "Proximity (raster distance)" self.group = "[GDAL] Analysis" self.addParameter(ParameterRaster(self.INPUT, "Input layer", False)) self.addParameter(ParameterString(self.VALUES, "Values", "")) diff --git a/python/plugins/processing/gdal/rasterize.py b/python/plugins/processing/gdal/rasterize.py index b9c418ee21b..918f1c0c1c4 100644 --- a/python/plugins/processing/gdal/rasterize.py +++ b/python/plugins/processing/gdal/rasterize.py @@ -47,14 +47,12 @@ class rasterize(GeoAlgorithm): HEIGHT = "HEIGHT" OUTPUT = "OUTPUT" - - def getIcon(self): filepath = os.path.dirname(__file__) + "/icons/rasterize.png" return QtGui.QIcon(filepath) def defineCharacteristics(self): - self.name = "Rasterize" + self.name = "Rasterize (vector to raster)" self.group = "[GDAL] Conversion" self.addParameter(ParameterVector(self.INPUT, "Input layer")) self.addParameter(ParameterTableField(self.FIELD, "Attribute field", self.INPUT)) diff --git a/python/plugins/processing/gdal/rgb2pct.py b/python/plugins/processing/gdal/rgb2pct.py index c116ed3b3c0..7f87bc63472 100644 --- a/python/plugins/processing/gdal/rgb2pct.py +++ b/python/plugins/processing/gdal/rgb2pct.py @@ -46,7 +46,7 @@ class rgb2pct(GeoAlgorithm): return QtGui.QIcon(filepath) def defineCharacteristics(self): - self.name = "rgb2pct" + self.name = "RGB to PCT" self.group = "[GDAL] Conversion" self.addParameter(ParameterRaster(rgb2pct.INPUT, "Input layer", False)) self.addParameter(ParameterNumber(rgb2pct.NCOLORS, "Number of colors", 1, None, 2)) diff --git a/python/plugins/processing/gdal/scripts/extractprojection.py b/python/plugins/processing/gdal/scripts/extractprojection.py deleted file mode 100644 index b017f6efbb0..00000000000 --- a/python/plugins/processing/gdal/scripts/extractprojection.py +++ /dev/null @@ -1,67 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -*************************************************************************** - extractprojection.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$' - -##Input_file=raster -##Create_prj_file=boolean False -##[GDAL] Projections=group - -import os - -from osgeo import gdal, osr - -from processing.gdal.GdalUtils import GdalUtils - - -raster = gdal.Open(unicode(Input_file)) - -crs = raster.GetProjection() -geotransform = raster.GetGeoTransform() - -raster = None - -outFileName = os.path.splitext(unicode(Input_file))[0] - -# create prj file requested and if projection available -if crs != "" and Create_prj_file: - # convert CRS into ESRI format - tmp = osr.SpatialReference() - tmp.ImportFromWkt( crs ) - tmp.MorphToESRI() - crs = tmp.ExportToWkt() - tmp = None - - prj = open(outFileName + '.prj', 'wt') - prj.write( crs ) - prj.close() - -# create wld file -wld = open(outFileName + '.wld', 'wt') -wld.write("%0.8f\n" % geotransform[1]) -wld.write("%0.8f\n" % geotransform[4]) -wld.write("%0.8f\n" % geotransform[2]) -wld.write("%0.8f\n" % geotransform[5]) -wld.write("%0.8f\n" % (geotransform[0] + 0.5 * geotransform[1] + 0.5 * geotransform[2])) -wld.write("%0.8f\n" % (geotransform[3] + 0.5 * geotransform[4] + 0.5 * geotransform[5])) -wld.close()