Skip to content

Commit b2396f6

Browse files
committed
Merge branch 'master' of github.com:qgis/QGIS
2 parents 94d7389 + 9d8d317 commit b2396f6

17 files changed

+364
-227
lines changed

python/plugins/processing/algs/ftools/Eliminate.py

Lines changed: 197 additions & 128 deletions
Large diffs are not rendered by default.

python/plugins/processing/algs/mmqgisx/MMQGISXAlgorithms.py

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,18 +1061,72 @@ def processAlgorithm(self, progress):
10611061

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

1064+
selectType = layer.dataProvider().fields()[selectindex].type()
1065+
selectionError = False
1066+
1067+
if selectType == 2:
1068+
try:
1069+
y = int(comparisonvalue)
1070+
except ValueError:
1071+
selectionError = True
1072+
msg = "Cannot convert \"" + unicode(comparisonvalue) + "\" to integer"
1073+
elif selectType == 6:
1074+
try:
1075+
y = float(comparisonvalue)
1076+
except ValueError:
1077+
selectionError = True
1078+
msg = "Cannot convert \"" + unicode(comparisonvalue) + "\" to float"
1079+
elif selectType == 10: # 10: string, boolean
1080+
try:
1081+
y = unicode(comparisonvalue)
1082+
except ValueError:
1083+
selectionError = True
1084+
msg = "Cannot convert \"" + unicode(comparisonvalue) + "\" to unicode"
1085+
elif selectType == 14: # date
1086+
dateAndFormat = comparisonvalue.split(" ")
1087+
1088+
if len(dateAndFormat) == 1:
1089+
y = QLocale.system().toDate(dateAndFormat[0]) # QtCore.QDate object
1090+
1091+
if y.isNull():
1092+
msg = "Cannot convert \"" + unicode(dateAndFormat) + "\" to date with system date format " + QLocale.system().dateFormat()
1093+
elif len(dateAndFormat) == 2:
1094+
y = QDate.fromString(dateAndFormat[0], dateAndFormat[1])
1095+
1096+
if y.isNull():
1097+
msg = "Cannot convert \"" + unicode(dateAndFormat[0]) + "\" to date with format string \"" + unicode(dateAndFormat[1] + "\". ")
1098+
else:
1099+
y = QDate()
1100+
msg = ""
1101+
1102+
if y.isNull(): # conversion was unsuccessfull
1103+
selectionError = True
1104+
msg += "Enter the date and the date format, e.g. \"07.26.2011\" \"MM.dd.yyyy\"."
1105+
1106+
if ((comparison == 'begins with') or (comparison == 'contains')) and selectType != 10:
1107+
selectionError = True
1108+
msg = "\"" + comparison + "\" can only be used with string fields"
1109+
1110+
if selectionError:
1111+
raise GeoAlgorithmExecutionException("Error in selection input: " + msg)
1112+
10641113
readcount = 0
10651114
selected = []
10661115
totalcount = layer.featureCount()
10671116
for feature in layer.getFeatures():
1068-
if (comparison == 'begins with') or (comparison == 'contains') or \
1069-
isinstance(feature.attributes()[selectindex], basestring) or \
1070-
isinstance(comparisonvalue, basestring):
1071-
x = unicode(feature.attributes()[selectindex])
1072-
y = unicode(comparisonvalue)
1073-
else:
1074-
x = float(feature.attributes()[selectindex])
1075-
y = float(comparisonvalue)
1117+
aValue = feature[selectindex]
1118+
1119+
if aValue == None:
1120+
continue
1121+
1122+
if selectType == 2:
1123+
x = int(aValue)
1124+
elif selectType == 6:
1125+
x = float(aValue)
1126+
elif selectType == 10: # 10: string, boolean
1127+
x = unicode(aValue)
1128+
elif selectType == 14: # date
1129+
x = aValue # should be date
10761130

10771131
match = False
10781132
if (comparison == '=='):

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.

src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
#include "qgsmessagelog.h"
2222

2323

24-
QgsEditorWidgetRegistry QgsEditorWidgetRegistry::sInstance;
24+
QgsEditorWidgetRegistry *QgsEditorWidgetRegistry::sInstance = 0;
2525

2626
QgsEditorWidgetRegistry* QgsEditorWidgetRegistry::instance()
2727
{
28-
return &sInstance;
28+
if( !sInstance )
29+
sInstance = new QgsEditorWidgetRegistry();
30+
return sInstance;
2931
}
3032

3133
QgsEditorWidgetRegistry::QgsEditorWidgetRegistry()

src/gui/editorwidgets/core/qgseditorwidgetregistry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class GUI_EXPORT QgsEditorWidgetRegistry : public QObject
112112

113113
private:
114114
QMap<QString, QgsEditorWidgetFactory*> mWidgetFactories;
115-
static QgsEditorWidgetRegistry sInstance;
115+
static QgsEditorWidgetRegistry *sInstance;
116116
};
117117

118118

0 commit comments

Comments
 (0)