Skip to content

Commit 7a720c2

Browse files
committedSep 26, 2013
[processing] sync GDAL algorithm names with Raster menu
1 parent 77ca835 commit 7a720c2

File tree

13 files changed

+100
-88
lines changed

13 files changed

+100
-88
lines changed
 

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
from processing.gdal.proximity import proximity
5151
from processing.gdal.sieve import sieve
5252
from processing.gdal.fillnodata import fillnodata
53+
from processing.gdal.extractprojection import ExtractProjection
5354

5455
from processing.gdal.ogr2ogr import Ogr2Ogr
5556
from processing.gdal.ogrinfo import OgrInfo
@@ -100,19 +101,20 @@ def createAlgsList(self):
100101
rgb2pct(), pct2rgb(), merge(), polygonize(),
101102
gdaladdo(), ClipByExtent(), ClipByMask(),
102103
contour(), rasterize(), proximity(), sieve(),
103-
fillnodata(),
104+
fillnodata(), ExtractProjection(),
104105
OgrInfo(), Ogr2Ogr(), OgrSql()]
105106

106107
#And then we add those that are created as python scripts
107108
folder = self.scriptsFolder()
108-
for descriptionFile in os.listdir(folder):
109-
if descriptionFile.endswith("py"):
110-
try:
111-
fullpath = os.path.join(self.scriptsFolder(), descriptionFile)
112-
alg = GdalAlgorithm(fullpath)
113-
self.preloadedAlgs.append(alg)
114-
except WrongScriptException,e:
115-
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,e.msg)
109+
if os.path.exists(folder):
110+
for descriptionFile in os.listdir(folder):
111+
if descriptionFile.endswith("py"):
112+
try:
113+
fullpath = os.path.join(self.scriptsFolder(), descriptionFile)
114+
alg = GdalAlgorithm(fullpath)
115+
self.preloadedAlgs.append(alg)
116+
except WrongScriptException,e:
117+
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,e.msg)
116118

117119
def getSupportedOutputRasterLayerExtensions(self):
118120
return GdalUtils.getSupportedRasterExtensions()
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
extractprojection.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+
# This will get replaced with a git SHA1 when you do a git archive
24+
__revision__ = '$Format:%H$'
25+
26+
import os
27+
28+
from osgeo import gdal, osr
29+
from PyQt4.QtGui import *
30+
31+
from processing.core.GeoAlgorithm import GeoAlgorithm
32+
from processing.parameters.ParameterRaster import ParameterRaster
33+
from processing.parameters.ParameterBoolean import ParameterBoolean
34+
35+
36+
class ExtractProjection(GeoAlgorithm):
37+
38+
INPUT = "INPUT"
39+
PRJ_FILE = "PRJ_FILE"
40+
41+
def getIcon(self):
42+
return QIcon(os.path.dirname(__file__) + "/icons/projection-export.png")
43+
44+
def defineCharacteristics(self):
45+
self.name = "Extract projection"
46+
self.group = "[GDAL] Projections"
47+
self.addParameter(ParameterRaster(self.INPUT, "Input file"))
48+
self.addParameter(ParameterBoolean(self.PRJ_FILE, "Create also .prj file", False))
49+
50+
def processAlgorithm(self, progress):
51+
rasterPath = self.getParameterValue(self.INPUT)
52+
createPrj = self.getParameterValue(self.PRJ_FILE)
53+
54+
raster = gdal.Open(unicode(rasterPath))
55+
crs = raster.GetProjection()
56+
geotransform = raster.GetGeoTransform()
57+
raster = None
58+
59+
outFileName = os.path.splitext(unicode(rasterPath))[0]
60+
61+
if crs != "" and createPrj:
62+
tmp = osr.SpatialReference()
63+
tmp.ImportFromWkt( crs )
64+
tmp.MorphToESRI()
65+
crs = tmp.ExportToWkt()
66+
tmp = None
67+
68+
prj = open(outFileName + '.prj', 'wt')
69+
prj.write( crs )
70+
prj.close()
71+
72+
wld = open(outFileName + '.wld', 'wt')
73+
wld.write("%0.8f\n" % geotransform[1])
74+
wld.write("%0.8f\n" % geotransform[4])
75+
wld.write("%0.8f\n" % geotransform[2])
76+
wld.write("%0.8f\n" % geotransform[5])
77+
wld.write("%0.8f\n" % (geotransform[0] + 0.5 * geotransform[1] + 0.5 * geotransform[2]))
78+
wld.write("%0.8f\n" % (geotransform[3] + 0.5 * geotransform[4] + 0.5 * geotransform[5]))
79+
wld.close()

‎python/plugins/processing/gdal/gdaladdo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def getIcon(self):
5959
return QtGui.QIcon(filepath)
6060

6161
def defineCharacteristics(self):
62-
self.name = "Build pyramids (overviews)"
62+
self.name = "Build overviews (pyramids)"
6363
self.group = "[GDAL] Miscellaneous"
6464
self.addParameter(ParameterRaster(self.INPUT, "Input layer", False))
6565
self.addParameter(ParameterString(self.LEVELS, "Overview levels", "2 4 8 16"))

‎python/plugins/processing/gdal/nearblack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def getIcon(self):
4646
return QtGui.QIcon(filepath)
4747

4848
def defineCharacteristics(self):
49-
self.name = "Nearblack"
49+
self.name = "Near black"
5050
self.group = "[GDAL] Analysis"
5151
self.addParameter(ParameterRaster(nearblack.INPUT, "Input layer", False))
5252
self.addParameter(ParameterNumber(nearblack.NEAR, "How far from black (white)", 0, None, 15))

‎python/plugins/processing/gdal/ogr2ogr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ class Ogr2Ogr(OgrAlgorithm):
5757
DEST_DSCO = "DEST_DSCO"
5858

5959
def defineCharacteristics(self):
60-
self.name = "ogr2ogr"
61-
self.group = "[OGR] Transformation"
60+
self.name = "Convert format"
61+
self.group = "[OGR] Conversion"
6262

6363
#we add the input vector layer. It can have any kind of geometry
6464
#It is a mandatory (not optional) one, hence the False argument

‎python/plugins/processing/gdal/ogrinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class OgrInfo(OgrAlgorithm):
4848
INPUT_LAYER = "INPUT_LAYER"
4949

5050
def defineCharacteristics(self):
51-
self.name = "ogrinfo"
51+
self.name = "Information"
5252
self.group = "[OGR] Miscellaneous"
5353

5454
self.addParameter(ParameterVector(self.INPUT_LAYER, "Input layer", [ParameterVector.VECTOR_TYPE_ANY], False))

‎python/plugins/processing/gdal/pct2rgb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def getIcon(self):
4646
return QtGui.QIcon(filepath)
4747

4848
def defineCharacteristics(self):
49-
self.name = "pct2rgb"
49+
self.name = "PCT to RGB"
5050
self.group = "[GDAL] Conversion"
5151
self.addParameter(ParameterRaster(pct2rgb.INPUT, "Input layer", False))
5252
options = []

‎python/plugins/processing/gdal/polygonize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def getIcon(self):
4747
return QtGui.QIcon(filepath)
4848

4949
def defineCharacteristics(self):
50-
self.name = "Polygonize"
50+
self.name = "Polygonize (raster to vector)"
5151
self.group = "[GDAL] Conversion"
5252
self.addParameter(ParameterRaster(polygonize.INPUT, "Input layer", False))
5353
self.addParameter(ParameterString(polygonize.FIELD, "Output field name", "DN"))

‎python/plugins/processing/gdal/proximity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def getIcon(self):
5555
return QtGui.QIcon(filepath)
5656

5757
def defineCharacteristics(self):
58-
self.name = "Proximity"
58+
self.name = "Proximity (raster distance)"
5959
self.group = "[GDAL] Analysis"
6060
self.addParameter(ParameterRaster(self.INPUT, "Input layer", False))
6161
self.addParameter(ParameterString(self.VALUES, "Values", ""))

‎python/plugins/processing/gdal/rasterize.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,12 @@ class rasterize(GeoAlgorithm):
4747
HEIGHT = "HEIGHT"
4848
OUTPUT = "OUTPUT"
4949

50-
51-
5250
def getIcon(self):
5351
filepath = os.path.dirname(__file__) + "/icons/rasterize.png"
5452
return QtGui.QIcon(filepath)
5553

5654
def defineCharacteristics(self):
57-
self.name = "Rasterize"
55+
self.name = "Rasterize (vector to raster)"
5856
self.group = "[GDAL] Conversion"
5957
self.addParameter(ParameterVector(self.INPUT, "Input layer"))
6058
self.addParameter(ParameterTableField(self.FIELD, "Attribute field", self.INPUT))

‎python/plugins/processing/gdal/rgb2pct.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def getIcon(self):
4646
return QtGui.QIcon(filepath)
4747

4848
def defineCharacteristics(self):
49-
self.name = "rgb2pct"
49+
self.name = "RGB to PCT"
5050
self.group = "[GDAL] Conversion"
5151
self.addParameter(ParameterRaster(rgb2pct.INPUT, "Input layer", False))
5252
self.addParameter(ParameterNumber(rgb2pct.NCOLORS, "Number of colors", 1, None, 2))

‎python/plugins/processing/gdal/scripts/extractprojection.py

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.