Ejemplo n.º 1
0
 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() == "":
         QMessageBox.information(self, self.tr("Random Points"),
                                 self.tr("Please specify output shapefile"))
     else:
         inName = self.inShape.currentText()
         self.progressBar.setValue(1)
         outPath = self.outShape.text()
         self.progressBar.setValue(2.5)
         outName = ftools_utils.getShapefileName(outPath)
         self.progressBar.setValue(5)
         mLayer = ftools_utils.getMapLayerByName(unicode(inName))
         if mLayer.type() == mLayer.VectorLayer:
             inLayer = ftools_utils.getVectorLayerByName(unicode(inName))
             if self.rdoUnstratified.isChecked():
                 design = self.tr("unstratified")
                 value = self.spnUnstratified.value()
             elif self.rdoStratified.isChecked():
                 design = self.tr("stratified")
                 value = self.spnStratified.value()
             elif self.rdoDensity.isChecked():
                 design = self.tr("density")
                 value = self.spnDensity.value()
             else:
                 design = self.tr("field")
                 value = unicode(self.cmbField.currentText())
         elif mLayer.type() == mLayer.RasterLayer:
             inLayer = ftools_utils.getRasterLayerByName(unicode(inName))
             design = self.tr("unstratified")
             value = self.spnUnstratified.value()
         else:
             QMessageBox.information(self, self.tr("Random Points"),
                                     self.tr("Unknown layer type..."))
         minimum = 0.00
         self.progressBar.setValue(10)
         if self.randomize(inLayer, outPath, minimum, design, value):
             self.progressBar.setValue(100)
             self.outShape.clear()
             if self.addToCanvasCheck.isChecked():
                 addCanvasCheck = ftools_utils.addShapeToCanvas(
                     unicode(outPath))
                 if not addCanvasCheck:
                     QMessageBox.warning(
                         self, self.tr("Random Points"),
                         self.tr("Error loading output shapefile:\n%s") %
                         (unicode(outPath)))
                 self.populateLayers()
             else:
                 QMessageBox.information(
                     self, self.tr("Random Points"),
                     self.tr("Created output shapefile:\n%s") %
                     (unicode(outPath)))
     self.progressBar.setValue(0)
     self.buttonOk.setEnabled(True)
Ejemplo n.º 2
0
 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() == "":
         QMessageBox.information(self, self.tr("Random Points"),
                                 self.tr("Please specify output shapefile"))
     else:
         inName = self.inShape.currentText()
         self.progressBar.setValue(1)
         outPath = self.outShape.text()
         self.progressBar.setValue(2.5)
         outName = ftools_utils.getShapefileName(outPath)
         self.progressBar.setValue(5)
         mLayer = ftools_utils.getMapLayerByName(unicode(inName))
         if mLayer.type() == mLayer.VectorLayer:
             inLayer = ftools_utils.getVectorLayerByName(unicode(inName))
             if self.rdoUnstratified.isChecked():
                 design = self.tr("unstratified")
                 value = self.spnUnstratified.value()
             elif self.rdoStratified.isChecked():
                 design = self.tr("stratified")
                 value = self.spnStratified.value()
             elif self.rdoDensity.isChecked():
                 design = self.tr("density")
                 value = self.spnDensity.value()
             else:
                 design = self.tr("field")
                 value = unicode(self.cmbField.currentText())
         elif mLayer.type() == mLayer.RasterLayer:
             inLayer = ftools_utils.getRasterLayerByName(unicode(inName))
             design = self.tr("unstratified")
             value = self.spnUnstratified.value()
         else:
             QMessageBox.information(self, self.tr("Random Points"),
                                     self.tr("Unknown layer type..."))
         minimum = 0.00
         self.progressBar.setValue(10)
         if self.randomize(inLayer, outPath, minimum, design, value):
             self.progressBar.setValue(100)
             self.outShape.clear()
             addToTOC = QMessageBox.question(
                 self, self.tr("Random Points"),
                 self.
                 tr("Created output point shapefile:\n%s\n\nWould you like to add the new layer to the TOC?"
                    ) % (outPath), QMessageBox.Yes, QMessageBox.No,
                 QMessageBox.NoButton)
             if addToTOC == QMessageBox.Yes:
                 self.vlayer = QgsVectorLayer(outPath, unicode(outName),
                                              "ogr")
                 QgsMapLayerRegistry.instance().addMapLayers([self.vlayer])
                 self.populateLayers()
     self.progressBar.setValue(0)
     self.buttonOk.setEnabled(True)
Ejemplo n.º 3
0
 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() == "":
         QMessageBox.information(self, self.tr("Random Points"), self.tr("Please specify output shapefile"))
     else:
         inName = self.inShape.currentText()
         self.progressBar.setValue(1)
         outPath = self.outShape.text()
         self.progressBar.setValue(2.5)
         if outPath.contains("\\"):
             outName = outPath.right((outPath.length() - outPath.lastIndexOf("\\")) - 1)
         else:
             outName = outPath.right((outPath.length() - outPath.lastIndexOf("/")) - 1)
         if outName.endsWith(".shp"):
             outName = outName.left(outName.length() - 4)
         self.progressBar.setValue(5)
         mLayer = ftools_utils.getMapLayerByName(unicode(inName))
         if mLayer.type() == mLayer.VectorLayer:
             inLayer = ftools_utils.getVectorLayerByName(unicode(inName))
             if self.rdoUnstratified.isChecked():
                 design = self.tr("unstratified")
                 value = self.spnUnstratified.value()
             elif self.rdoStratified.isChecked():
                 design = self.tr("stratified")
                 value = self.spnStratified.value()
             elif self.rdoDensity.isChecked():
                 design = self.tr("density")
                 value = self.spnDensity.value()
             else:
                 design = self.tr("field")
                 value = unicode(self.cmbField.currentText())
         elif mLayer.type() == mLayer.RasterLayer:
             inLayer = ftools_utils.getRasterLayerByName(unicode(inName))
             design = self.tr("unstratified")
             value = self.spnUnstratified.value()
         else:
             QMessageBox.information(self, self.tr("Random Points"), self.tr("Unknown layer type..."))
         minimum = 0.00
         self.progressBar.setValue(10)
         self.randomize(inLayer, outPath, minimum, design, value)
         self.progressBar.setValue(100)
         self.outShape.clear()
         addToTOC = QMessageBox.question(self, self.tr("Random Points"),
         self.tr("Created output point shapefile:\n%1\n\nWould you like to add the new layer to the TOC?").arg(outPath), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
         if addToTOC == QMessageBox.Yes:
             self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
             QgsMapLayerRegistry.instance().addMapLayers([self.vlayer])
             self.populateLayers()
     self.progressBar.setValue(0)
     self.buttonOk.setEnabled( True )
Ejemplo n.º 4
0
 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() == "":
         QMessageBox.information(self, self.tr("Random Points"), self.tr("Please specify output shapefile"))
     else:
         inName = self.inShape.currentText()
         self.progressBar.setValue(1)
         outPath = self.outShape.text()
         self.progressBar.setValue(2.5)
         outName = ftools_utils.getShapefileName( outPath )
         self.progressBar.setValue(5)
         mLayer = ftools_utils.getMapLayerByName(unicode(inName))
         if mLayer.type() == mLayer.VectorLayer:
             inLayer = ftools_utils.getVectorLayerByName(unicode(inName))
             if self.rdoUnstratified.isChecked():
                 design = self.tr("unstratified")
                 value = self.spnUnstratified.value()
             elif self.rdoStratified.isChecked():
                 design = self.tr("stratified")
                 value = self.spnStratified.value()
             elif self.rdoDensity.isChecked():
                 design = self.tr("density")
                 value = self.spnDensity.value()
             else:
                 design = self.tr("field")
                 value = unicode(self.cmbField.currentText())
         elif mLayer.type() == mLayer.RasterLayer:
             inLayer = ftools_utils.getRasterLayerByName(unicode(inName))
             design = self.tr("unstratified")
             value = self.spnUnstratified.value()
         else:
             QMessageBox.information(self, self.tr("Random Points"), self.tr("Unknown layer type..."))
         minimum = 0.00
         self.progressBar.setValue(10)
         if self.randomize(inLayer, outPath, minimum, design, value):
           self.progressBar.setValue(100)
           self.outShape.clear()
           if self.addToCanvasCheck.isChecked():
             addCanvasCheck = ftools_utils.addShapeToCanvas(unicode(outPath))
             if not addCanvasCheck:
                 QMessageBox.warning( self, self.tr("Random Points"), self.tr( "Error loading output shapefile:\n%s" ) % ( unicode( outPath ) ))
             self.populateLayers()
           else:
             QMessageBox.information(self, self.tr("Random Points"),self.tr("Created output shapefile:\n%s" ) % ( unicode( outPath )))
     self.progressBar.setValue(0)
     self.buttonOk.setEnabled( True )