Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' of github.com:qgis/QGIS
  • Loading branch information
pcav committed Sep 27, 2013
2 parents 94d7389 + 9d8d317 commit b2396f6
Show file tree
Hide file tree
Showing 17 changed files with 364 additions and 227 deletions.
325 changes: 197 additions & 128 deletions python/plugins/processing/algs/ftools/Eliminate.py

Large diffs are not rendered by default.

70 changes: 62 additions & 8 deletions python/plugins/processing/algs/mmqgisx/MMQGISXAlgorithms.py
Expand Up @@ -1061,18 +1061,72 @@ def processAlgorithm(self, progress):

selectindex = layer.dataProvider().fieldNameIndex(attribute)

selectType = layer.dataProvider().fields()[selectindex].type()
selectionError = False

if selectType == 2:
try:
y = int(comparisonvalue)
except ValueError:
selectionError = True
msg = "Cannot convert \"" + unicode(comparisonvalue) + "\" to integer"
elif selectType == 6:
try:
y = float(comparisonvalue)
except ValueError:
selectionError = True
msg = "Cannot convert \"" + unicode(comparisonvalue) + "\" to float"
elif selectType == 10: # 10: string, boolean
try:
y = unicode(comparisonvalue)
except ValueError:
selectionError = True
msg = "Cannot convert \"" + unicode(comparisonvalue) + "\" to unicode"
elif selectType == 14: # date
dateAndFormat = comparisonvalue.split(" ")

if len(dateAndFormat) == 1:
y = QLocale.system().toDate(dateAndFormat[0]) # QtCore.QDate object

if y.isNull():
msg = "Cannot convert \"" + unicode(dateAndFormat) + "\" to date with system date format " + QLocale.system().dateFormat()
elif len(dateAndFormat) == 2:
y = QDate.fromString(dateAndFormat[0], dateAndFormat[1])

if y.isNull():
msg = "Cannot convert \"" + unicode(dateAndFormat[0]) + "\" to date with format string \"" + unicode(dateAndFormat[1] + "\". ")
else:
y = QDate()
msg = ""

if y.isNull(): # conversion was unsuccessfull
selectionError = True
msg += "Enter the date and the date format, e.g. \"07.26.2011\" \"MM.dd.yyyy\"."

if ((comparison == 'begins with') or (comparison == 'contains')) and selectType != 10:
selectionError = True
msg = "\"" + comparison + "\" can only be used with string fields"

if selectionError:
raise GeoAlgorithmExecutionException("Error in selection input: " + msg)

readcount = 0
selected = []
totalcount = layer.featureCount()
for feature in layer.getFeatures():
if (comparison == 'begins with') or (comparison == 'contains') or \
isinstance(feature.attributes()[selectindex], basestring) or \
isinstance(comparisonvalue, basestring):
x = unicode(feature.attributes()[selectindex])
y = unicode(comparisonvalue)
else:
x = float(feature.attributes()[selectindex])
y = float(comparisonvalue)
aValue = feature[selectindex]

if aValue == None:
continue

if selectType == 2:
x = int(aValue)
elif selectType == 6:
x = float(aValue)
elif selectType == 10: # 10: string, boolean
x = unicode(aValue)
elif selectType == 14: # date
x = aValue # should be date

match = False
if (comparison == '=='):
Expand Down
20 changes: 11 additions & 9 deletions python/plugins/processing/gdal/GdalOgrAlgorithmProvider.py
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
79 changes: 79 additions & 0 deletions 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()
2 changes: 1 addition & 1 deletion python/plugins/processing/gdal/gdaladdo.py
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gdal/nearblack.py
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/gdal/ogr2ogr.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gdal/ogrinfo.py
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gdal/pct2rgb.py
Expand Up @@ -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 = []
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gdal/polygonize.py
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gdal/proximity.py
Expand Up @@ -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", ""))
Expand Down
4 changes: 1 addition & 3 deletions python/plugins/processing/gdal/rasterize.py
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gdal/rgb2pct.py
Expand Up @@ -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))
Expand Down
67 changes: 0 additions & 67 deletions python/plugins/processing/gdal/scripts/extractprojection.py

This file was deleted.

6 changes: 4 additions & 2 deletions src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp
Expand Up @@ -21,11 +21,13 @@
#include "qgsmessagelog.h"


QgsEditorWidgetRegistry QgsEditorWidgetRegistry::sInstance;
QgsEditorWidgetRegistry *QgsEditorWidgetRegistry::sInstance = 0;

QgsEditorWidgetRegistry* QgsEditorWidgetRegistry::instance()
{
return &sInstance;
if( !sInstance )
sInstance = new QgsEditorWidgetRegistry();
return sInstance;
}

QgsEditorWidgetRegistry::QgsEditorWidgetRegistry()
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/core/qgseditorwidgetregistry.h
Expand Up @@ -112,7 +112,7 @@ class GUI_EXPORT QgsEditorWidgetRegistry : public QObject

private:
QMap<QString, QgsEditorWidgetFactory*> mWidgetFactories;
static QgsEditorWidgetRegistry sInstance;
static QgsEditorWidgetRegistry *sInstance;
};


Expand Down

0 comments on commit b2396f6

Please sign in to comment.