Skip to content
Permalink
Browse files
New warning when creating empty multipart layer; Ok button disabled o…
…n all functions while running; General bug fixes. Fixes #2260, #2057, and #1986. Another great patch from alexbruy :-)

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13481 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
cfarmer committed May 13, 2010
1 parent 208c706 commit a270bde06ba1cb5e8adfe23d599edd11d334a15d
@@ -19,6 +19,7 @@ def __init__(self, iface):
self.label_2.setVisible(False)
self.label_2.setEnabled(False)
self.setWindowTitle(self.tr("Define current projection"))
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
QObject.connect(self.btnProjection, SIGNAL("clicked()"), self.outProjFile)
QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.updateProj1)
QObject.connect(self.cmbLayer, SIGNAL("currentIndexChanged(QString)"), self.updateProj2)
@@ -42,6 +43,7 @@ def updateProj2(self, layerName):
self.outRef.insert(unicode(crs))

def accept(self):
self.buttonOk.setEnabled( False )
if self.inShape.currentText() == "":
QMessageBox.information(self, self.tr("Define current projection"), self.tr("No input shapefile specified"))
elif self.txtProjection.text() == "" and self.rdoProjection.isChecked():
@@ -103,6 +105,7 @@ def accept(self):
self.progressBar.setValue(100)
QMessageBox.information(self, self.tr("Define current projection"), self.tr("Defined Projection For:\n%1.shp").arg( inPath ) )
self.progressBar.setValue(0)
self.buttonOk.setEnabled( True )

def outProjFile(self):
format = QString( "<h2>%1</h2>%2 <br/> %3" )
@@ -14,6 +14,7 @@ def __init__(self, iface, function):
self.iface = iface
self.setupUi(self)
self.myFunction = function
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
if self.myFunction == 1:
QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
@@ -126,7 +127,7 @@ def manageGui(self):
elif self.myFunction == 9:
myList = ftools_utils.getLayerNames( "all" )
else:
myList = ftools_utils.getLayerNames( [ QGis.Point, QGis.Line, QGis.Polygon ] )
myList = ftools_utils.getLayerNames( [ QGis.Point, QGis.Line, QGis.Polygon ] )
self.inShape.addItems( myList )
return

@@ -151,6 +152,7 @@ def geometry( self, myLayer, myParam, myField ):
if not QgsVectorFileWriter.deleteShapeFile( self.shapefileName ):
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Unable to delete existing shapefile." ) )
return
self.buttonOk.setEnabled( False )
self.testThread = geometryThread( self.iface.mainWindow(), self, self.myFunction, vlayer, myParam,
myField, self.shapefileName, self.encoding )
QObject.connect( self.testThread, SIGNAL( "runFinished(PyQt_PyObject)" ), self.runFinishedFromThread )
@@ -162,13 +164,19 @@ def geometry( self, myLayer, myParam, myField ):

def cancelThread( self ):
self.testThread.stop()
self.buttonOk.setEnabled( True )

def runFinishedFromThread( self, success ):
self.testThread.stop()
self.buttonOk.setEnabled( True )
if success == "math_error":
QMessageBox.warning( self, self.tr("Geometry"), self.tr("Error processing specified tolerance!\nPlease choose larger tolerance...") )
if not QgsVectorFileWriter.deleteShapeFile( self.shapefileName ):
QMessageBox.warning( self, self.tr("Geometry"), self.tr( "Unable to delete incomplete shapefile." ) )
elif success == "attr_error":
QMessageBox.warning( self, self.tr("Geometry"), self.tr("At least two features must have same attribute value!\nPlease choose another field...") )
if not QgsVectorFileWriter.deleteShapeFile( self.shapefileName ):
QMessageBox.warning( self, self.tr("Geometry"), self.tr( "Unable to delete incomplete shapefile." ) )
else:
self.cancel_close.setText( "Close" )
QObject.disconnect( self.cancel_close, SIGNAL( "clicked()" ), self.cancelThread )
@@ -267,6 +275,8 @@ def single_to_multi( self ):
outFeat.setGeometry( outGeom )
writer.addFeature( outFeat )
del writer
else:
return "attr_error"
return True

def multi_to_single( self ):
@@ -22,6 +22,7 @@ def __init__( self, iface, function ):
self.manageGui()
self.success = False
self.cancel_close = self.buttonBox_2.button( QDialogButtonBox.Close )
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
self.progressBar.setValue (0 )

def checkA( self ):
@@ -180,6 +181,7 @@ def geoprocessing( self, myLayerA, myLayerB, myParam, myMerge, mySelectionA,
if not QgsVectorFileWriter.deleteShapeFile( self.shapefileName ):
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Unable to delete existing shapefile." ) )
return
self.buttonOk.setEnabled( False )
self.testThread = geoprocessingThread( self.iface.mainWindow(), self, self.myFunction, myLayerA,
myLayerB, myParam, myMerge, mySelectionA, mySelectionB, self.shapefileName, self.encoding )
QObject.connect( self.testThread, SIGNAL( "runFinished(PyQt_PyObject)" ), self.runFinishedFromThread )
@@ -192,9 +194,11 @@ def geoprocessing( self, myLayerA, myLayerB, myParam, myMerge, mySelectionA,

def cancelThread( self ):
self.testThread.stop()
self.buttonOk.setEnabled( True )

def runFinishedFromThread( self, results ):
self.testThread.stop()
self.buttonOk.setEnabled( True )
self.cancel_close.setText( self.tr("Close") )
QObject.disconnect( self.cancel_close, SIGNAL( "clicked()" ), self.cancelThread )
out_text = ""
@@ -48,6 +48,7 @@ def __init__(self, iface):
QObject.connect(self.inLine1, SIGNAL("currentIndexChanged(QString)"), self.update1)
QObject.connect(self.inLine2, SIGNAL("currentIndexChanged(QString)"), self.update2)
self.setWindowTitle( self.tr("Line intersections") )
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
# populate layer list
self.progressBar.setValue(0)
mapCanvas = self.iface.mapCanvas()
@@ -70,6 +71,7 @@ def update2(self, inputLayer):
self.inField2.addItem(unicode(changedField[i].name()))

def accept(self):
self.buttonOk.setEnabled( False )
if self.inLine1.currentText() == "":
QMessageBox.information(self, self.tr("Locate Line Intersections"), self.tr("Please specify input line layer") )
elif self.outShape.text() == "":
@@ -94,6 +96,7 @@ def accept(self):
if not ftools_utils.addShapeToCanvas( unicode( outPath ) ):
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( outPath ) ))
self.progressBar.setValue(0)
self.buttonOk.setEnabled( True )

def outFile(self):
self.outShape.clear()
@@ -15,6 +15,7 @@ def __init__(self, iface, function):
self.updateUi()
QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )

# populate layer list
self.progressBar.setValue(0)
@@ -44,6 +45,7 @@ def update(self, inputLayer):
self.uniqueField.addItem(unicode(changedField[i].name()))

def accept(self):
self.buttonOk.setEnabled( False )
if self.inShape.currentText() == "":
QMessageBox.information(self, self.tr("Coordinate statistics"), self.tr("No input vector layer specified"))
elif self.outShape.text() == "":
@@ -74,7 +76,8 @@ def accept(self):
render.addSymbol(symbol)
self.vlayer.setRenderer(render)
QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
self.progressBar.setValue(0)
self.progressBar.setValue(0)
self.buttonOk.setEnabled( True )

def outFile(self):
self.outShape.clear()
@@ -137,7 +140,7 @@ def compute(self, inName, outName, weightField="", times=1, uniqueField=""):
else:
weight = float(feat.attributeMap()[weightIndex].toDouble()[0])
geom = QgsGeometry(feat.geometry())
geom = self.extract(geom)
geom = ftools_utils.extractPoints(geom)
for i in geom:
cx += i.x()
cy += i.y()
@@ -180,31 +183,3 @@ def compute(self, inName, outName, weightField="", times=1, uniqueField=""):
if single:
break
del writer

def extract(self, geom):
multi_geom = QgsGeometry()
temp_geom = []
if geom.type() == 0: # it's a point
if geom.isMultipart():
temp_geom = geom.asMultiPoint()
else:
temp_geom.append(geom.asPoint())
if geom.type() == 1: # it's a line
if geom.isMultipart():
multi_geom = geom.asMultiPolyline() #multi_geog is a multiline
for i in multi_geom: #i is a line
temp_geom.extend(i)
else:
temp_geom = geom.asPolyline()
elif geom.type() == 2: # it's a polygon
if geom.isMultipart():
multi_geom = geom.asMultiPolygon() #multi_geom is a multipolygon
for i in multi_geom: #i is a polygon
for j in i: #j is a line
temp_geom.extend(j)
else:
multi_geom = geom.asPolygon() #multi_geom is a polygon
for i in multi_geom: #i is a line
temp_geom.extend(i)
return temp_geom

@@ -46,6 +46,7 @@ def __init__(self, iface):
self.setupUi(self)
QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
self.setWindowTitle(self.tr("Count Points in Polygon"))
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
# populate layer list
self.progressBar.setValue(0)
mapCanvas = self.iface.mapCanvas()
@@ -55,6 +56,7 @@ def __init__(self, iface):
self.inPoint.addItems(layers)

def accept(self):
self.buttonOk.setEnabled( False )
if self.inPolygon.currentText() == "":
QMessageBox.information(self, self.tr("Count Points In Polygon"), self.tr("Please specify input polygon vector layer"))
elif self.outShape.text() == "":
@@ -81,6 +83,7 @@ def accept(self):
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
self.progressBar.setValue(0)
self.buttonOk.setEnabled( True )

def outFile(self):
self.outShape.clear()
@@ -48,11 +48,12 @@ def __init__(self, iface):
QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
self.progressBar.setValue(0)
self.setWindowTitle(self.tr("Random Points"))
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
self.mapCanvas = self.iface.mapCanvas()
layers = ftools_utils.getLayerNames([QGis.Polygon, "Raster"])
self.inShape.addItems(layers)

# If input layer is changed, update field list
# If input layer is changed, update field list
def update(self, inputLayer):
self.cmbField.clear()
changedLayer = ftools_utils.getMapLayerByName(unicode(inputLayer))
@@ -75,8 +76,9 @@ def update(self, inputLayer):
self.cmbField.setEnabled(False)
self.label_4.setEnabled(False)

# when 'OK' button is pressed, gather required inputs, and initiate random points generation
# when 'OK' button is pressed, gather required inputs, and initiate random points generation
def accept(self):
self.buttonOk.setEnabled( False )
if self.inShape.currentText() == "":
QMessageBox.information(self, self.tr("Random Points"), self.tr("No input layer specified"))
elif self.outShape.text() == "":
@@ -127,7 +129,8 @@ def accept(self):
if addToTOC == QMessageBox.Yes:
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
self.progressBar.setValue(0)
self.progressBar.setValue(0)
self.buttonOk.setEnabled( True )

def outFile(self):
self.outShape.clear()
@@ -136,7 +139,7 @@ def outFile(self):
return
self.outShape.setText( QString( self.shapefileName ) )

# combine all polygons in layer to create single polygon (slow for complex polygons)
# combine all polygons in layer to create single polygon (slow for complex polygons)
def createSinglePolygon(self, vlayer):
provider = vlayer.dataProvider()
allAttrs = provider.attributeIndexes()
@@ -157,7 +160,7 @@ def createSinglePolygon(self, vlayer):
self.progressBar.setValue(count)
return geom

# Generate list of random points
# Generate list of random points
def simpleRandom(self, n, bound, xmin, xmax, ymin, ymax):
seed()
points = []
@@ -17,36 +17,39 @@ def __init__(self, iface):
# populate layer list
self.progressBar.setValue(0)
mapCanvas = self.iface.mapCanvas()
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon])
self.inShape.addItems(layers)

def changed(self, inputLayer):
changedLayer = ftools_utils.getVectorLayerByName(inputLayer)
changedProvider = changedLayer.dataProvider()
upperVal = changedProvider.featureCount()
self.spnNumber.setMaximum(upperVal)
changedLayer = ftools_utils.getVectorLayerByName(inputLayer)
changedProvider = changedLayer.dataProvider()
upperVal = changedProvider.featureCount()
self.spnNumber.setMaximum(upperVal)

def accept(self):
if self.inShape.currentText() == "":
QMessageBox.information(self, self.tr("Random Selection Tool"), self.tr("No input shapefile specified"))
else:
self.buttonOk.setEnabled( False )
if self.inShape.currentText() == "":
QMessageBox.information(self, self.tr("Random Selection Tool"), self.tr("No input shapefile specified"))
else:
self.progressBar.setValue(10)
inName = self.inShape.currentText()
self.progressBar.setValue(20)
layer = ftools_utils.getVectorLayerByName(inName)
self.progressBar.setValue(30)
if self.rdoNumber.isChecked():
value = self.spnNumber.value()
self.progressBar.setValue(60)
else:
value = self.spnPercent.value()
self.progressBar.setValue(50)
value = int(round((value / 100.0000), 4) * layer.featureCount())
self.progressBar.setValue(60)
selran = random.sample(xrange(0, layer.featureCount()), value)
self.progressBar.setValue(70)
self.progressBar.setValue(80)
self.progressBar.setValue(90)
self.progressBar.setValue(100)
layer.setSelectedFeatures(selran)
self.progressBar.setValue(0)
self.progressBar.setValue(20)
layer = ftools_utils.getVectorLayerByName(inName)
self.progressBar.setValue(30)
if self.rdoNumber.isChecked():
value = self.spnNumber.value()
self.progressBar.setValue(60)
else:
value = self.spnPercent.value()
self.progressBar.setValue(50)
value = int(round((value / 100.0000), 4) * layer.featureCount())
self.progressBar.setValue(60)
selran = random.sample(xrange(0, layer.featureCount()), value)
self.progressBar.setValue(70)
self.progressBar.setValue(80)
self.progressBar.setValue(90)
self.progressBar.setValue(100)
layer.setSelectedFeatures(selran)
self.progressBar.setValue(0)
self.buttonOk.setEnabled( True )
@@ -18,6 +18,7 @@ def __init__(self, iface):
QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.updateProj1)
QObject.connect(self.cmbLayer, SIGNAL("currentIndexChanged(QString)"), self.updateProj2)
self.setWindowTitle( self.tr("Export to new projection") )
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
self.progressBar.setValue(0)
mapCanvas = self.iface.mapCanvas()
layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon])
@@ -37,6 +38,7 @@ def updateProj2(self, layerName):
self.outRef.insert(unicode(crs))

def accept(self):
self.buttonOk.setEnabled( False )
if self.inShape.currentText() == "":
QMessageBox.information(self, self.tr("Export to new projection"), self.tr("No input layer specified"))
elif self.outShape.text() == "":
@@ -64,6 +66,7 @@ def accept(self):
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
self.progressBar.setValue(0)
self.buttonOk.setEnabled( True )

def outProjFile(self):
format = QString( "<h2>%1</h2>%2 <br/> %3" )
@@ -50,12 +50,14 @@ def __init__(self, iface):
self.yMax.setValidator(QDoubleValidator(self.yMax))
QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
self.setWindowTitle( self.tr("Regular points") )
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
self.progressBar.setValue(0)
self.mapCanvas = self.iface.mapCanvas()
layers = ftools_utils.getLayerNames("all")
self.inShape.addItems(layers)

def accept(self):
self.buttonOk.setEnabled( False )
if not self.rdoCoordinates.isChecked() and self.inShape.currentText() == "":
QMessageBox.information(self, self.tr("Generate Regular Points"), self.tr("Please specify input layer"))
elif self.rdoCoordinates.isChecked() and (self.xMin.text() == "" or self.xMax.text() == "" or self.yMin.text() == "" or self.yMax.text() == ""):
@@ -90,7 +92,8 @@ def accept(self):
if addToTOC == QMessageBox.Yes:
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
self.progressBar.setValue(0)
self.progressBar.setValue(0)
self.buttonOk.setEnabled( True )

def outFile(self):
self.outShape.clear()
@@ -99,7 +102,7 @@ def outFile(self):
return
self.outShape.setText( QString( self.shapefileName ) )

# Generate list of random points
# Generate list of random points
def simpleRandom(self, n, bound, xmin, xmax, ymin, ymax):
seed()
points = []

0 comments on commit a270bde

Please sign in to comment.