mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-16 00:05:45 -04:00
[processing] sync GDAL algorithm names with Raster menu
This commit is contained in:
parent
77ca8358ab
commit
7a720c2166
@ -50,6 +50,7 @@ from processing.gdal.rasterize import rasterize
|
|||||||
from processing.gdal.proximity import proximity
|
from processing.gdal.proximity import proximity
|
||||||
from processing.gdal.sieve import sieve
|
from processing.gdal.sieve import sieve
|
||||||
from processing.gdal.fillnodata import fillnodata
|
from processing.gdal.fillnodata import fillnodata
|
||||||
|
from processing.gdal.extractprojection import ExtractProjection
|
||||||
|
|
||||||
from processing.gdal.ogr2ogr import Ogr2Ogr
|
from processing.gdal.ogr2ogr import Ogr2Ogr
|
||||||
from processing.gdal.ogrinfo import OgrInfo
|
from processing.gdal.ogrinfo import OgrInfo
|
||||||
@ -100,19 +101,20 @@ class GdalOgrAlgorithmProvider(AlgorithmProvider):
|
|||||||
rgb2pct(), pct2rgb(), merge(), polygonize(),
|
rgb2pct(), pct2rgb(), merge(), polygonize(),
|
||||||
gdaladdo(), ClipByExtent(), ClipByMask(),
|
gdaladdo(), ClipByExtent(), ClipByMask(),
|
||||||
contour(), rasterize(), proximity(), sieve(),
|
contour(), rasterize(), proximity(), sieve(),
|
||||||
fillnodata(),
|
fillnodata(), ExtractProjection(),
|
||||||
OgrInfo(), Ogr2Ogr(), OgrSql()]
|
OgrInfo(), Ogr2Ogr(), OgrSql()]
|
||||||
|
|
||||||
#And then we add those that are created as python scripts
|
#And then we add those that are created as python scripts
|
||||||
folder = self.scriptsFolder()
|
folder = self.scriptsFolder()
|
||||||
for descriptionFile in os.listdir(folder):
|
if os.path.exists(folder):
|
||||||
if descriptionFile.endswith("py"):
|
for descriptionFile in os.listdir(folder):
|
||||||
try:
|
if descriptionFile.endswith("py"):
|
||||||
fullpath = os.path.join(self.scriptsFolder(), descriptionFile)
|
try:
|
||||||
alg = GdalAlgorithm(fullpath)
|
fullpath = os.path.join(self.scriptsFolder(), descriptionFile)
|
||||||
self.preloadedAlgs.append(alg)
|
alg = GdalAlgorithm(fullpath)
|
||||||
except WrongScriptException,e:
|
self.preloadedAlgs.append(alg)
|
||||||
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,e.msg)
|
except WrongScriptException,e:
|
||||||
|
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,e.msg)
|
||||||
|
|
||||||
def getSupportedOutputRasterLayerExtensions(self):
|
def getSupportedOutputRasterLayerExtensions(self):
|
||||||
return GdalUtils.getSupportedRasterExtensions()
|
return GdalUtils.getSupportedRasterExtensions()
|
||||||
|
79
python/plugins/processing/gdal/extractprojection.py
Normal file
79
python/plugins/processing/gdal/extractprojection.py
Normal file
@ -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 @@ class gdaladdo(GeoAlgorithm):
|
|||||||
return QtGui.QIcon(filepath)
|
return QtGui.QIcon(filepath)
|
||||||
|
|
||||||
def defineCharacteristics(self):
|
def defineCharacteristics(self):
|
||||||
self.name = "Build pyramids (overviews)"
|
self.name = "Build overviews (pyramids)"
|
||||||
self.group = "[GDAL] Miscellaneous"
|
self.group = "[GDAL] Miscellaneous"
|
||||||
self.addParameter(ParameterRaster(self.INPUT, "Input layer", False))
|
self.addParameter(ParameterRaster(self.INPUT, "Input layer", False))
|
||||||
self.addParameter(ParameterString(self.LEVELS, "Overview levels", "2 4 8 16"))
|
self.addParameter(ParameterString(self.LEVELS, "Overview levels", "2 4 8 16"))
|
||||||
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
@ -46,7 +46,7 @@ class nearblack(GeoAlgorithm):
|
|||||||
return QtGui.QIcon(filepath)
|
return QtGui.QIcon(filepath)
|
||||||
|
|
||||||
def defineCharacteristics(self):
|
def defineCharacteristics(self):
|
||||||
self.name = "Nearblack"
|
self.name = "Near black"
|
||||||
self.group = "[GDAL] Analysis"
|
self.group = "[GDAL] Analysis"
|
||||||
self.addParameter(ParameterRaster(nearblack.INPUT, "Input layer", False))
|
self.addParameter(ParameterRaster(nearblack.INPUT, "Input layer", False))
|
||||||
self.addParameter(ParameterNumber(nearblack.NEAR, "How far from black (white)", 0, None, 15))
|
self.addParameter(ParameterNumber(nearblack.NEAR, "How far from black (white)", 0, None, 15))
|
||||||
|
@ -57,8 +57,8 @@ class Ogr2Ogr(OgrAlgorithm):
|
|||||||
DEST_DSCO = "DEST_DSCO"
|
DEST_DSCO = "DEST_DSCO"
|
||||||
|
|
||||||
def defineCharacteristics(self):
|
def defineCharacteristics(self):
|
||||||
self.name = "ogr2ogr"
|
self.name = "Convert format"
|
||||||
self.group = "[OGR] Transformation"
|
self.group = "[OGR] Conversion"
|
||||||
|
|
||||||
#we add the input vector layer. It can have any kind of geometry
|
#we add the input vector layer. It can have any kind of geometry
|
||||||
#It is a mandatory (not optional) one, hence the False argument
|
#It is a mandatory (not optional) one, hence the False argument
|
||||||
|
@ -48,7 +48,7 @@ class OgrInfo(OgrAlgorithm):
|
|||||||
INPUT_LAYER = "INPUT_LAYER"
|
INPUT_LAYER = "INPUT_LAYER"
|
||||||
|
|
||||||
def defineCharacteristics(self):
|
def defineCharacteristics(self):
|
||||||
self.name = "ogrinfo"
|
self.name = "Information"
|
||||||
self.group = "[OGR] Miscellaneous"
|
self.group = "[OGR] Miscellaneous"
|
||||||
|
|
||||||
self.addParameter(ParameterVector(self.INPUT_LAYER, "Input layer", [ParameterVector.VECTOR_TYPE_ANY], False))
|
self.addParameter(ParameterVector(self.INPUT_LAYER, "Input layer", [ParameterVector.VECTOR_TYPE_ANY], False))
|
||||||
|
@ -46,7 +46,7 @@ class pct2rgb(GeoAlgorithm):
|
|||||||
return QtGui.QIcon(filepath)
|
return QtGui.QIcon(filepath)
|
||||||
|
|
||||||
def defineCharacteristics(self):
|
def defineCharacteristics(self):
|
||||||
self.name = "pct2rgb"
|
self.name = "PCT to RGB"
|
||||||
self.group = "[GDAL] Conversion"
|
self.group = "[GDAL] Conversion"
|
||||||
self.addParameter(ParameterRaster(pct2rgb.INPUT, "Input layer", False))
|
self.addParameter(ParameterRaster(pct2rgb.INPUT, "Input layer", False))
|
||||||
options = []
|
options = []
|
||||||
|
@ -47,7 +47,7 @@ class polygonize(GeoAlgorithm):
|
|||||||
return QtGui.QIcon(filepath)
|
return QtGui.QIcon(filepath)
|
||||||
|
|
||||||
def defineCharacteristics(self):
|
def defineCharacteristics(self):
|
||||||
self.name = "Polygonize"
|
self.name = "Polygonize (raster to vector)"
|
||||||
self.group = "[GDAL] Conversion"
|
self.group = "[GDAL] Conversion"
|
||||||
self.addParameter(ParameterRaster(polygonize.INPUT, "Input layer", False))
|
self.addParameter(ParameterRaster(polygonize.INPUT, "Input layer", False))
|
||||||
self.addParameter(ParameterString(polygonize.FIELD, "Output field name", "DN"))
|
self.addParameter(ParameterString(polygonize.FIELD, "Output field name", "DN"))
|
||||||
|
@ -55,7 +55,7 @@ class proximity(GeoAlgorithm):
|
|||||||
return QtGui.QIcon(filepath)
|
return QtGui.QIcon(filepath)
|
||||||
|
|
||||||
def defineCharacteristics(self):
|
def defineCharacteristics(self):
|
||||||
self.name = "Proximity"
|
self.name = "Proximity (raster distance)"
|
||||||
self.group = "[GDAL] Analysis"
|
self.group = "[GDAL] Analysis"
|
||||||
self.addParameter(ParameterRaster(self.INPUT, "Input layer", False))
|
self.addParameter(ParameterRaster(self.INPUT, "Input layer", False))
|
||||||
self.addParameter(ParameterString(self.VALUES, "Values", ""))
|
self.addParameter(ParameterString(self.VALUES, "Values", ""))
|
||||||
|
@ -47,14 +47,12 @@ class rasterize(GeoAlgorithm):
|
|||||||
HEIGHT = "HEIGHT"
|
HEIGHT = "HEIGHT"
|
||||||
OUTPUT = "OUTPUT"
|
OUTPUT = "OUTPUT"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getIcon(self):
|
def getIcon(self):
|
||||||
filepath = os.path.dirname(__file__) + "/icons/rasterize.png"
|
filepath = os.path.dirname(__file__) + "/icons/rasterize.png"
|
||||||
return QtGui.QIcon(filepath)
|
return QtGui.QIcon(filepath)
|
||||||
|
|
||||||
def defineCharacteristics(self):
|
def defineCharacteristics(self):
|
||||||
self.name = "Rasterize"
|
self.name = "Rasterize (vector to raster)"
|
||||||
self.group = "[GDAL] Conversion"
|
self.group = "[GDAL] Conversion"
|
||||||
self.addParameter(ParameterVector(self.INPUT, "Input layer"))
|
self.addParameter(ParameterVector(self.INPUT, "Input layer"))
|
||||||
self.addParameter(ParameterTableField(self.FIELD, "Attribute field", self.INPUT))
|
self.addParameter(ParameterTableField(self.FIELD, "Attribute field", self.INPUT))
|
||||||
|
@ -46,7 +46,7 @@ class rgb2pct(GeoAlgorithm):
|
|||||||
return QtGui.QIcon(filepath)
|
return QtGui.QIcon(filepath)
|
||||||
|
|
||||||
def defineCharacteristics(self):
|
def defineCharacteristics(self):
|
||||||
self.name = "rgb2pct"
|
self.name = "RGB to PCT"
|
||||||
self.group = "[GDAL] Conversion"
|
self.group = "[GDAL] Conversion"
|
||||||
self.addParameter(ParameterRaster(rgb2pct.INPUT, "Input layer", False))
|
self.addParameter(ParameterRaster(rgb2pct.INPUT, "Input layer", False))
|
||||||
self.addParameter(ParameterNumber(rgb2pct.NCOLORS, "Number of colors", 1, None, 2))
|
self.addParameter(ParameterNumber(rgb2pct.NCOLORS, "Number of colors", 1, None, 2))
|
||||||
|
@ -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()
|
|
Loading…
x
Reference in New Issue
Block a user