Exemplo n.º 1
0
    def runProfile(self):
        self.progressBar.show()

        rasterName = self.comboDEM.currentText()
        self.rLayer = self.getLayerByName(rasterName)
        XSlayer = self.getLayerByName(
            str(QCoreApplication.translate("dialog", "Sezioni")))
        profiler = ProfilerTool()
        profiler.setRaster(self.rLayer)
        leftPoints = []
        rightPoints = []
        ringPoints = []
        nfeats = int(XSlayer.featureCount())
        self.progressBar.setMaximum(nfeats)
        i = 0
        self.progressBar.setValue(i)
        nVsteps = self.nVsteps.value()
        minVdep = self.minVdep.value()
        for feat in XSlayer.getFeatures():
            #~ feat = feats[0]
            geom = feat.geometry()
            profileList, e = profiler.doProfile(geom)
            self.iface.mainWindow().statusBar().showMessage("Elaboro la sez " +
                                                            str(i))
            startDis, endDis = mainFun(profileList, nVsteps, minVdep, Graph=0)

            StartPoint = geom.interpolate(startDis)
            EndPoint = geom.interpolate(endDis)

            leftPoints.append(StartPoint.asPoint())
            rightPoints.append(EndPoint.asPoint())
            #~ rightPoints reversing
            ringPoints = leftPoints + rightPoints[::-1]
            i = i + 1
            self.progressBar.setValue(i)

        vl = QgsVectorLayer("Polygon", self.vlName, "memory")
        pr = vl.dataProvider()
        fet = QgsFeature()
        fet.setGeometry(QgsGeometry.fromPolygon([ringPoints]))
        pr.addFeatures([fet])
        QgsMapLayerRegistry.instance().addMapLayer(vl)

        #check if output file is selected
        shapefilename = self.ShpSaveLine.text()
        if shapefilename == None:
            QMessageBox.critical(
                self.iface.mainWindow(),
                QCoreApplication.translate("message", "Error"),
                QCoreApplication.translate(
                    "message", "You have to select output file first"))
        else:
            #~ save vector layer to shapefile
            error = QgsVectorFileWriter.writeAsVectorFormat(
                vl, shapefilename, "CP1250", None, "ESRI Shapefile")
            if error == QgsVectorFileWriter.NoError:
                QMessageBox.information(
                    self.iface.mainWindow(), "Info",
                    str("File %s " % (str(unicode(vl.name())).upper())) +
                    QCoreApplication.translate("message", "succesfully saved"))
Exemplo n.º 2
0
    def runProfileXS(self):
        from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar

        #~ take input parameters fron GUI
        rasterName = self.comboDEM.currentText()
        self.rLayer = self.getLayerByName(rasterName)
        nVsteps = self.nVsteps.value()
        minVdep = self.minVdep.value()
        profiler = ProfilerTool()
        profiler.setRaster(self.rLayer)
        layer = self.iface.activeLayer()
        if layer.selectedFeatureCount() == 1:
            feat = layer.selectedFeatures()[0]
            geomSinXS = feat.geometry()
            profileList, e = profiler.doProfile(geomSinXS)
            canvasPlot = mainFun(profileList, nVsteps, minVdep, Graph=1)
            self.clearLayout(self.layout_plot)
            toolbar = NavigationToolbar(canvasPlot, self.layout_plot.widget())
            #~ self.layout_plot.insertWidget(0, canvasPlot )
            self.layout_plot.addWidget(canvasPlot)
            self.layout_plot.addWidget(toolbar)
            #~ self.setLayout( self.layout_plot)

        else:
            QMessageBox.information(
                self.iface.mainWindow(), "Info",
                str('select feature for ' +
                    str(unicode(layer.name().upper()))))
    def runProfileXS(self):
        from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar

        #~ take input parameters fron GUI
        rasterName = self.comboDEM.currentText()
        self.rLayer = self.getLayerByName(rasterName)
        nVsteps = self.nVsteps.value()
        minVdep = self.minVdep.value()
        profiler = ProfilerTool()
        profiler.setRaster( self.rLayer )
        layer = self.iface.activeLayer()
        if layer.selectedFeatureCount() == 1:
            feat = layer.selectedFeatures()[0]
            geomSinXS = feat.geometry()
            profileList,e = profiler.doProfile(geomSinXS)
            canvasPlot = mainFun(profileList,nVsteps,minVdep,Graph=1)
            self.clearLayout(self.layout_plot)
            toolbar = NavigationToolbar(canvasPlot,self.layout_plot.widget())
            #~ self.layout_plot.insertWidget(0, canvasPlot )
            self.layout_plot.addWidget( canvasPlot )
            self.layout_plot.addWidget( toolbar )
            #~ self.setLayout( self.layout_plot)
            
        else:
            QMessageBox.information( self.iface.mainWindow(),"Info",
            str('select feature for ' + str( unicode(layer.name().upper() ) ) ) )
 def runProfile(self):
     self.progressBar.show()
     
     rasterName = self.comboDEM.currentText()
     self.rLayer = self.getLayerByName(rasterName)
     XSlayer = self.getLayerByName(str(QCoreApplication.translate( "dialog","Sezioni")))
     profiler = ProfilerTool()
     profiler.setRaster( self.rLayer )
     leftPoints = []
     rightPoints = []
     ringPoints = []
     nfeats = int( XSlayer.featureCount() )
     self.progressBar.setMaximum(nfeats)
     i = 0
     self.progressBar.setValue(i)
     nVsteps = self.nVsteps.value()
     minVdep = self.minVdep.value()
     for feat in XSlayer.getFeatures():
         #~ feat = feats[0]
         geom = feat.geometry()
         profileList,e = profiler.doProfile(geom)
         self.iface.mainWindow().statusBar().showMessage( "Elaboro la sez "+str(i) )
         startDis, endDis = mainFun(profileList,nVsteps,minVdep,Graph=0)
         
         StartPoint = geom.interpolate( startDis)
         EndPoint = geom.interpolate(endDis)
         
         leftPoints.append(StartPoint.asPoint() )
         rightPoints.append(EndPoint.asPoint() )
         #~ rightPoints reversing
         ringPoints = leftPoints+rightPoints[::-1]
         i = i +1 
         self.progressBar.setValue(i)
     
     vl = QgsVectorLayer("Polygon", self.vlName, "memory")
     pr = vl.dataProvider()
     fet = QgsFeature()
     fet.setGeometry( QgsGeometry.fromPolygon( [ ringPoints ] ) )
     pr.addFeatures( [fet] )
     QgsMapLayerRegistry.instance().addMapLayer(vl)
     
     #check if output file is selected
     shapefilename = self.ShpSaveLine.text()
     if shapefilename == None:
         QMessageBox.critical(self.iface.mainWindow(),QCoreApplication.translate( "message","Error"), QCoreApplication.translate( "message","You have to select output file first"))
     else:
         #~ save vector layer to shapefile
         error = QgsVectorFileWriter.writeAsVectorFormat(vl, shapefilename, "CP1250", None, "ESRI Shapefile")
         if error == QgsVectorFileWriter.NoError:
             QMessageBox.information( self.iface.mainWindow(),"Info",
             str("File %s " %(str(unicode(vl.name())).upper())) + QCoreApplication.translate( "message","succesfully saved"))