Skip to content
Permalink
Browse files

[processing] sync GDAL algorithm names with Raster menu

  • Loading branch information
alexbruy committed Sep 26, 2013
1 parent 77ca835 commit 7a720c2166a88b01fbd08971e15eaa3b0ee5386d
@@ -50,6 +50,7 @@
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 @@ def createAlgsList(self):
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()
@@ -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()
@@ -59,7 +59,7 @@ def getIcon(self):
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"))
@@ -46,7 +46,7 @@ def getIcon(self):
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))
@@ -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
@@ -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))
@@ -46,7 +46,7 @@ def getIcon(self):
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 = []
@@ -47,7 +47,7 @@ def getIcon(self):
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"))
@@ -55,7 +55,7 @@ def getIcon(self):
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", ""))
@@ -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))
@@ -46,7 +46,7 @@ def getIcon(self):
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))

This file was deleted.

0 comments on commit 7a720c2

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