Skip to content

Commit e4554d5

Browse files
author
volayaf
committed
Severql bug fixes qnd smqll improvements in qgis bindings
git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@43 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
1 parent 1865097 commit e4554d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+574
-300
lines changed

.pydevproject

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
<?eclipse-pydev version="1.0"?>
33

44
<pydev_project>
5-
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
5+
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
6+
<path>/sextante/src</path>
7+
</pydev_pathproperty>
68
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
9+
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
710
</pydev_project>

src/sextante/SextantePlugin.py

+27
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from sextante.gui.ConfigDialog import ConfigDialog
1414
from sextante.modeler.ModelerDialog import ModelerDialog
1515
from sextante.gui.ResultsDialog import ResultsDialog
16+
from sextante.about.AboutDialog import AboutDialog
17+
import subprocess
1618

1719
cmd_folder = os.path.split(inspect.getfile( inspect.currentframe() ))[0]
1820
if cmd_folder not in sys.path:
@@ -63,6 +65,20 @@ def initGui(self):
6365
QObject.connect(self.resultsAction, SIGNAL("triggered()"), self.openResults)
6466
self.menu.addAction(self.resultsAction)
6567

68+
icon = QIcon(os.path.dirname(__file__) + "/images/help.png")
69+
self.helpAction = QAction(icon, \
70+
"&SEXTANTE help", self.iface.mainWindow())
71+
QObject.connect(self.helpAction, SIGNAL("triggered()"), self.openHelp)
72+
self.menu.addAction(self.helpAction)
73+
74+
icon = QIcon(os.path.dirname(__file__) + "/images/info.png")
75+
self.aboutAction = QAction(icon, \
76+
"&About SEXTANTE", self.iface.mainWindow())
77+
QObject.connect(self.aboutAction, SIGNAL("triggered()"), self.openAbout)
78+
self.menu.addAction(self.aboutAction)
79+
80+
81+
6682

6783
menuBar = self.iface.mainWindow().menuBar()
6884
menuBar.insertMenu(menuBar.actions()[-1], self.menu)
@@ -102,4 +118,15 @@ def openConfig(self):
102118
dlg = ConfigDialog(self.toolbox)
103119
dlg.exec_()
104120

121+
def openAbout(self):
122+
dlg = AboutDialog()
123+
dlg.exec_()
124+
125+
def openHelp(self):
126+
filename = os.path.dirname(__file__) + "/manual.pdf"
127+
if os.name == "nt":
128+
os.startfile(filename)
129+
else:
130+
subprocess.call(('xdg-open', filename))
131+
105132

src/sextante/about/AboutDialog.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from PyQt4 import QtCore, QtGui, QtWebKit
2+
from PyQt4.QtCore import *
3+
from PyQt4.QtGui import *
4+
import os
5+
6+
class AboutDialog(QtGui.QDialog):
7+
8+
def __init__(self):
9+
QtGui.QDialog.__init__(self)
10+
self.setModal(True)
11+
self.setupUi()
12+
13+
def setupUi(self):
14+
self.setObjectName("AboutDialog")
15+
self.resize(500, 400)
16+
self.webView = QtWebKit.QWebView()
17+
self.webView.setObjectName("webView")
18+
self.setWindowTitle("About SEXTANTE")
19+
self.horizontalLayout= QtGui.QHBoxLayout()
20+
self.horizontalLayout.setSpacing(2)
21+
self.horizontalLayout.setMargin(0)
22+
self.horizontalLayout.setObjectName("horizontalLayout")
23+
self.horizontalLayout.addWidget(self.webView)
24+
self.setLayout(self.horizontalLayout)
25+
filename = os.path.dirname(__file__) + "/about.htm"
26+
url = QtCore.QUrl(filename)
27+
self.webView.load(url)
28+

src/sextante/about/__init__.py

Whitespace-only changes.

src/sextante/about/about.htm

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
3+
<title>SEXTANTE Spatial Data Analysis Library</title>
4+
</head>
5+
<body>
6+
<img src="sextante_logo.png" />
7+
<h2>SEXTANTE for QGIS</h2>
8+
<p>SEXTANTE, a geoprocessing platform for QGIS</p>
9+
<p>A development by Victor Olaya (volayaf@gmail.com)</p>
10+
<p>You are currently using SEXTANTE v1.0</p>
11+
<p>For more information, please visit our website at <a href="http://sextantegis.com">http://sextantegis.com</a></p>
12+
</body>
13+
</html>

src/sextante/about/sextante_logo.png

9.99 KB
Loading

src/sextante/core/GeoAlgorithm.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ def setOutputValue(self, outputName, value):
7878
if out.name == outputName:
7979
out.value = value
8080

81+
def getOutputValuesAsDictionary(self):
82+
d = {}
83+
for out in self.outputs:
84+
d[out.name] = out.value
85+
return d
86+
8187
def canBeExecuted(self, layersCount):
8288
return True
8389

@@ -108,12 +114,14 @@ def getParameterFromName(self, name):
108114
def getParameterValue(self, name):
109115
for param in self.parameters:
110116
if param.name == name:
111-
if isinstance(param, ParameterNumber):
112-
return float(param.value)
113-
elif isinstance(param, ParameterBoolean):
114-
return param.value == str(True)
115-
else:
116-
return param.value
117+
#===============================================================
118+
# if isinstance(param, ParameterNumber):
119+
# return float(param.value)
120+
# elif isinstance(param, ParameterBoolean):
121+
# return param.value == str(True)
122+
# else:
123+
#===============================================================
124+
return param.value
117125
return None
118126

119127
def getOutputValue(self, name):

src/sextante/core/Sextante.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def runalg(name, *args):
201201
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
202202
AlgorithmExecutor.runalg(alg, SilentProgress())
203203
QApplication.restoreOverrideCursor()
204-
return alg.getOuputsValuesAsMap()
204+
return alg.getOutputValuesAsDictionary()
205205
except GeoAlgorithmExecutionException, e:
206206
print "*****Error executing algorithm*****"
207207
print e.msg
@@ -218,7 +218,6 @@ def loadFromAlg(layersdict):
218218
def getObject(string):
219219
QGisLayers.getObjectFromUri(string)
220220

221-
222221
@staticmethod
223222
def runandload(name, *args):
224223
#a quick fix to call algorithms from the history dialog

src/sextante/core/SextanteLog.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def addToLog(msgtype, msg):
2828
if isinstance(msg, list):
2929
text=""
3030
for i in range(0, len(msg)):
31-
text+=msg[i] + "|"
31+
text+=msg[i].strip("\n") + "|"
3232
text = text[:-1]
3333
else:
3434
text = str(msg).replace("\n", "|")
+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from sextante.core.GeoAlgorithm import GeoAlgorithm
2+
import os.path
3+
from PyQt4 import QtGui
4+
from PyQt4.QtCore import *
5+
from PyQt4.QtGui import *
6+
from qgis.core import *
7+
from sextante.parameters.ParameterVector import ParameterVector
8+
from sextante.core.QGisLayers import QGisLayers
9+
from sextante.outputs.OutputVector import OutputVector
10+
11+
class ExtentFromLayer(GeoAlgorithm):
12+
13+
INPUT = "INPUT"
14+
OUTPUT = "OUTPUT"
15+
16+
def getIcon(self):
17+
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/layer_extent.png")
18+
19+
def processAlgorithm(self, progress):
20+
settings = QSettings()
21+
systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
22+
output = self.getOutputValue(ExtentFromLayer.OUTPUT)
23+
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(ExtentFromLayer.INPUT))
24+
fields = {
25+
0 : QgsField( "MINX", QVariant.Double ),
26+
1 : QgsField( "MINY", QVariant.Double ),
27+
2 : QgsField( "MAXX", QVariant.Double ),
28+
3 : QgsField( "MAXY", QVariant.Double ),
29+
4 : QgsField( "CNTX", QVariant.Double ),
30+
5 : QgsField( "CNTY", QVariant.Double ),
31+
6 : QgsField( "AREA", QVariant.Double ),
32+
7 : QgsField( "PERIM", QVariant.Double ),
33+
8 : QgsField( "HEIGHT", QVariant.Double ),
34+
9 : QgsField( "WIDTH", QVariant.Double ) }
35+
36+
writer = QgsVectorFileWriter(output, systemEncoding, fields, QGis.WKBPolygon, vlayer.crs() )
37+
rect = vlayer.extent()
38+
minx = rect.xMinimum()
39+
miny = rect.yMinimum()
40+
maxx = rect.xMaximum()
41+
maxy = rect.yMaximum()
42+
height = rect.height()
43+
width = rect.width()
44+
cntx = minx + ( width / 2.0 )
45+
cnty = miny + ( height / 2.0 )
46+
area = width * height
47+
perim = ( 2 * width ) + (2 * height )
48+
rect = [
49+
QgsPoint( minx, miny ),
50+
QgsPoint( minx, maxy ),
51+
QgsPoint( maxx, maxy ),
52+
QgsPoint( maxx, miny ),
53+
QgsPoint( minx, miny ) ]
54+
geometry = QgsGeometry().fromPolygon( [ rect ] )
55+
feat = QgsFeature()
56+
feat.setGeometry( geometry )
57+
feat.setAttributeMap( {
58+
0 : QVariant( minx ),
59+
1 : QVariant( miny ),
60+
2 : QVariant( maxx ),
61+
3 : QVariant( maxy ),
62+
4 : QVariant( cntx ),
63+
5 : QVariant( cnty ),
64+
6 : QVariant( area ),
65+
7 : QVariant( perim ),
66+
8 : QVariant( height ),
67+
9 : QVariant( width ) } )
68+
writer.addFeature( feat )
69+
del writer
70+
71+
72+
def defineCharacteristics(self):
73+
self.name = "Extent from layer"
74+
self.group = "Research tools"
75+
self.addParameter(ParameterVector(ExtentFromLayer.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
76+
self.addOutput(OutputVector(ExtentFromLayer.OUTPUT, "Extent layer"))
77+
#=========================================================

src/sextante/ftools/FToolsAlgorithmProvider.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
from sextante.ftools.Intersection import Intersection
2626
from sextante.ftools.Union import Union
2727
from sextante.ftools.Clip import Clip
28+
from sextante.ftools.ExtentFromLayer import ExtentFromLayer
29+
from sextante.ftools.RandomSelection import RandomSelection
30+
from sextante.ftools.SelectByLocation import SelectByLocation
31+
from sextante.ftools.RandomSelectionWithinSubsets import RandomSelectionWithinSubsets
2832

2933
class FToolsAlgorithmProvider(AlgorithmProvider):
3034

@@ -41,7 +45,8 @@ def _loadAlgorithms(self):
4145
SumLines(), BasicStatistics(), PointsInPolygon(),
4246
NearestNeighbourAnalysis(), MeanCoords(), LinesIntersection(),
4347
ConvexHull(), FixedDistanceBuffer(), VariableDistanceBuffer(),
44-
Dissolve(), Difference(), Intersection(), Union(), Clip()]
48+
Dissolve(), Difference(), Intersection(), Union(), Clip(), ExtentFromLayer(),
49+
RandomSelection(), RandomSelectionWithinSubsets(), SelectByLocation()]
4550
for alg in self.algs:
4651
alg.provider = self
4752

src/sextante/ftools/PointsInPolygon.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def processAlgorithm(self, progress):
4242
index = polyProvider.fieldNameIndex(unicode(inField))
4343
if index == -1:
4444
index = polyProvider.fieldCount()
45-
field = QgsField(unicode(inField), QVariant.Double, "real", 24, 15, self.tr("point count field"))
45+
field = QgsField(unicode(inField), QVariant.Double, "real", 24, 15, "point count field")
4646
fieldList[index] = field
4747
sRs = polyProvider.crs()
4848
check = QFile(self.shapefileName)
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from sextante.core.GeoAlgorithm import GeoAlgorithm
2+
import os.path
3+
from PyQt4 import QtGui
4+
from PyQt4.QtCore import *
5+
from PyQt4.QtGui import *
6+
from qgis.core import *
7+
from sextante.parameters.ParameterVector import ParameterVector
8+
from sextante.core.QGisLayers import QGisLayers
9+
from sextante.outputs.OutputVector import OutputVector
10+
from sextante.parameters.ParameterSelection import ParameterSelection
11+
from sextante.parameters.ParameterNumber import ParameterNumber
12+
import random
13+
14+
class RandomSelection(GeoAlgorithm):
15+
16+
INPUT = "INPUT"
17+
OUTPUT = "OUTPUT"
18+
METHOD = "METHOD"
19+
NUMBER = "NUMBER"
20+
PERCENTAGE = "PERCENTAGE"
21+
22+
def getIcon(self):
23+
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/random_selection.png")
24+
25+
def processAlgorithm(self, progress):
26+
filename = self.getParameterValue(RandomSelection.INPUT)
27+
layer = QGisLayers.getObjectFromUri(filename)
28+
method = self.getParameterValue(self.METHOD)
29+
if method == 0:
30+
value = int(self.getParameterValue(self.NUMBER))
31+
else:
32+
value = self.getParameterValue(self.PERCENTAGE)
33+
value = int(round((value / 100.0000), 4) * layer.featureCount())
34+
selran = random.sample(xrange(0, layer.featureCount()), value)
35+
layer.setSelectedFeatures(selran)
36+
self.setOutputValue(self.OUTPUT, filename)
37+
38+
39+
def defineCharacteristics(self):
40+
self.name = "Random selection"
41+
self.group = "Research tools"
42+
self.addParameter(ParameterVector(RandomSelection.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
43+
self.addParameter(ParameterSelection(RandomSelection.METHOD, "Method", ["Number of selected features", "Percentage of selected features"]))
44+
self.addParameter(ParameterNumber(RandomSelection.NUMBER, "Number of selected features", 1, None, 10))
45+
self.addParameter(ParameterNumber(RandomSelection.PERCENTAGE, "Percentage of selected features", 0, 100, 50))
46+
self.addOutput(OutputVector(RandomSelection.OUTPUT, "Selection", True))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from sextante.core.GeoAlgorithm import GeoAlgorithm
2+
import os.path
3+
from PyQt4 import QtGui
4+
from PyQt4.QtCore import *
5+
from PyQt4.QtGui import *
6+
from qgis.core import *
7+
from sextante.parameters.ParameterVector import ParameterVector
8+
from sextante.core.QGisLayers import QGisLayers
9+
from sextante.outputs.OutputVector import OutputVector
10+
from sextante.parameters.ParameterSelection import ParameterSelection
11+
from sextante.parameters.ParameterNumber import ParameterNumber
12+
import random
13+
from sextante.parameters.ParameterTableField import ParameterTableField
14+
from sextante.ftools import ftools_utils
15+
16+
class RandomSelectionWithinSubsets(GeoAlgorithm):
17+
18+
INPUT = "INPUT"
19+
OUTPUT = "OUTPUT"
20+
METHOD = "METHOD"
21+
NUMBER = "NUMBER"
22+
PERCENTAGE = "PERCENTAGE"
23+
FIELD = "FIELD"
24+
25+
def getIcon(self):
26+
return QtGui.QIcon(os.path.dirname(__file__) + "/icons/random_selection.png")
27+
28+
def processAlgorithm(self, progress):
29+
method = self.getParameterValue(self.METHOD)
30+
field = self.getParameterValue(RandomSelectionWithinSubsets.FIELD)
31+
filename = self.getParameterValue(RandomSelectionWithinSubsets.INPUT)
32+
vlayer = QGisLayers.getObjectFromUri(filename)
33+
vlayer.removeSelection(True)
34+
vprovider = vlayer.dataProvider()
35+
allAttrs = vprovider.attributeIndexes()
36+
vprovider.select(allAttrs)
37+
index = vprovider.fieldNameIndex(field)
38+
unique = ftools_utils.getUniqueValues(vprovider, int(index))
39+
inFeat = QgsFeature()
40+
selran = []
41+
nFeat = vprovider.featureCount() * len(unique)
42+
nElement = 0
43+
if not len(unique) == vlayer.featureCount():
44+
for i in unique:
45+
vprovider.rewind()
46+
FIDs= []
47+
while vprovider.nextFeature(inFeat):
48+
atMap = inFeat.attributeMap()
49+
if atMap[index] == QVariant(i):
50+
FID = inFeat.id()
51+
FIDs.append(FID)
52+
nElement += 1
53+
progress.setPercentage(nElement/nFeat * 100)
54+
if method == 0:
55+
value = int(self.getParameterValue(self.NUMBER))
56+
else:
57+
value = self.getParameterValue(self.PERCENTAGE)
58+
value = int(round((value / 100.0000) * len(FIDs), 0))
59+
if value >= len(FIDs):
60+
selFeat = FIDs
61+
else:
62+
selFeat = random.sample(FIDs, value)
63+
selran.extend(selFeat)
64+
vlayer.setSelectedFeatures(selran)
65+
else:
66+
vlayer.setSelectedFeatures(range(0, vlayer.featureCount()))
67+
self.setOutputValue(RandomSelectionWithinSubsets.OUTPUT, filename)
68+
69+
70+
def defineCharacteristics(self):
71+
self.name = "Random selection within subsets"
72+
self.group = "Research tools"
73+
self.addParameter(ParameterVector(RandomSelectionWithinSubsets.INPUT, "Input layer", ParameterVector.VECTOR_TYPE_ANY))
74+
self.addParameter(ParameterTableField(RandomSelectionWithinSubsets.FIELD, "ID Field", RandomSelectionWithinSubsets.INPUT))
75+
self.addParameter(ParameterSelection(RandomSelectionWithinSubsets.METHOD, "Method", ["Number of selected features", "Percentage of selected features"]))
76+
self.addParameter(ParameterNumber(RandomSelectionWithinSubsets.NUMBER, "Number of selected features", 1, None, 10))
77+
self.addParameter(ParameterNumber(RandomSelectionWithinSubsets.PERCENTAGE, "Percentage of selected features", 0, 100, 50))
78+
self.addOutput(OutputVector(RandomSelectionWithinSubsets.OUTPUT, "Selection", True))

0 commit comments

Comments
 (0)