Esempio n. 1
0
  def accept( self ):
    self.buttonOk.setEnabled( False )
    if self.leFileName.text().isEmpty():
      QMessageBox.warning( self, self.tr( "Error" ), self.tr( "Please specify output raster" ) )
      self.buttonOk.setEnabled( True )
      return

    rastercalcengine.exprStack = []
    usedRasters = rasterUtils.rasterList

    setRasters = dict()
    for r in usedRasters:
      setRasters[ r ] = self.layerInfo[ r ]
    rasterUtils.setRasters( setRasters )

    self.statusBar.showMessage( self.tr( "Running..." ) )
    QCoreApplication.processEvents()

    self.exp = rastercalcengine.pattern.parseString( str( self.commandTextEdit.toPlainText() ) )
    
    filePath = str(self.leFileName.text()[0:-2] + "tiff")
    self.outtif = os.path.normpath( str( filePath) )
    pixelFormat = str( self.cmbPixelFormat.currentText() )

    firstusedRaster=list( rastercalcengine.rasterNames )[ 0 ]
    etalon = self.layerInfo[firstusedRaster]

    ( sizeX, sizeY ) = rasterUtils.rasterSize( firstusedRaster )
    outData = rasterUtils.outDataset( self.outtif, pixelFormat, etalon, sizeX, sizeY )
    tmpStack = []
    tmpStack.extend( self.exp )
    tmpStack.reverse()
    result = rastercalcengine.evaluate( tmpStack, 0, sizeX, sizeY )
    rastercalcengine.yes = True
    outData.GetRasterBand( 1 ).WriteArray( result, 0, 0 )
    del tmpStack[ : ]

    outData = None
    self.convertFile()

    # add created layer to the map canvas if neсessary
    if self.loadCheckBox.isChecked():
      newLayer = QgsRasterLayer( self.outfile, QFileInfo( self.outfile ).baseName() )
      QgsMapLayerRegistry.instance().addMapLayer( newLayer )

    self.statusBar.showMessage( self.tr( "Completed" ) )
    self.buttonOk.setEnabled( True )
Esempio n. 2
0
  def accept( self ):
    self.buttonOk.setEnabled( False )
    if self.leFileName.text().isEmpty():
      QMessageBox.warning( self, self.tr( "Error" ), self.tr( "Please specify output raster" ) )
      self.buttonOk.setEnabled( True )
      return

    rastercalcengine.exprStack = []
    usedRasters = rasterUtils.rasterList

    setRasters = dict()
    for r in usedRasters:
      setRasters[ r ] = self.layerInfo[ r ]
    rasterUtils.setRasters( setRasters )

    self.statusBar.showMessage( self.tr( "Running..." ) )
    QCoreApplication.processEvents()

    self.exp = rastercalcengine.pattern.parseString( str( self.commandTextEdit.toPlainText() ) )
    
    filePath = str(self.leFileName.text()[0:-2] + "tiff")
    self.outtif = os.path.normpath( str( filePath) )
    pixelFormat = str( self.cmbPixelFormat.currentText() )

    firstusedRaster=list( rastercalcengine.rasterNames )[ 0 ]
    etalon = self.layerInfo[firstusedRaster]

    ( sizeX, sizeY ) = rasterUtils.rasterSize( firstusedRaster )
    outData = rasterUtils.outDataset( self.outtif, pixelFormat, etalon, sizeX, sizeY )
    tmpStack = []
    tmpStack.extend( self.exp )
    tmpStack.reverse()
    result = rastercalcengine.evaluate( tmpStack, 0, sizeX, sizeY )
    rastercalcengine.yes = True
    outData.GetRasterBand( 1 ).WriteArray( result, 0, 0 )
    del tmpStack[ : ]

    outData = None
    self.convertFile()

    # add created layer to the map canvas if neсessary
    if self.loadCheckBox.isChecked():
      newLayer = QgsRasterLayer( self.outfile, QFileInfo( self.outfile ).baseName() )
      QgsMapLayerRegistry.instance().addMapLayer( newLayer )

    self.statusBar.showMessage( self.tr( "Completed" ) )
    self.buttonOk.setEnabled( True )
Esempio n. 3
0
    def accept(self):
        self.buttonOk.setEnabled(False)
        if self.leFileName.text().isEmpty():
            QMessageBox.warning(self, self.tr("Error"),
                                self.tr("Please specify output raster"))
            self.buttonOk.setEnabled(True)
            return

        rastercalcengine.exprStack = []
        usedRasters = rasterUtils.rasterList

        setRasters = dict()
        for r in usedRasters:
            setRasters[r] = self.layerInfo[r]
        rasterUtils.setRasters(setRasters)

        self.statusBar.showMessage(self.tr("Running..."))
        QCoreApplication.processEvents()

        expression = rastercalcengine.pattern.parseString(
            str(self.commandTextEdit.toPlainText()))

        #result = rastercalcengine.evaluateStack( rastercalcengine.exprStack )

        # check is the result array
        #if not rasterUtils.isArray( result ):
        #  QMessageBox.warning( self, self.tr( "Error" ), self.tr( "Result is not an array." ) )
        #  self.statusBar.showMessage( self.tr( "Failed" ) )
        #  self.buttonOk.setEnabled( True )
        #  return

        # time to write results on disk as raster file
        # use the extent of the first layer referenced
        #extent = rasterUtils.Extent( self.layerInfo[ list( usedRasters )[ 0 ] ] )

        # make sure result is numpy/Numeric
        #etalonLayer = rasterUtils.getRaster( list( usedRasters )[ 0 ] )
        #print "Etalon layer", etalonLayer
        #( testFlag, res ) = rasterUtils.checkSameAs( result, setRasters[ list( usedRasters )[ 0 ] ] )
        #( testFlag, res ) = rasterUtils.checkSameAs( result, etalonLayer )
        #if not testFlag:
        #  result = res

        fileName = os.path.normpath(str(self.leFileName.text()))
        pixelFormat = str(self.cmbPixelFormat.currentText())

        firstusedRaster = list(rastercalcengine.rasterNames)[0]
        etalon = self.layerInfo[firstusedRaster]
        #rasterUtils.writeGeoTiff( result, [ extent.xMinimum(), extent.yMinimum(), extent.xMaximum(), extent.yMaximum() ], pixelFormat, fileName, etalon )

        (sizeX, sizeY) = rasterUtils.rasterSize(firstusedRaster)
        blk = 250
        blk_num = sizeY / blk
        overhead = sizeY - (blk_num * blk)
        outData = rasterUtils.outDataset(fileName, pixelFormat, etalon, sizeX,
                                         sizeY)
        tmpStack = []
        iter = 0
        for row in range(blk_num):
            tmpStack.extend(rastercalcengine.exprStack)
            result = rastercalcengine.evaluateStack(tmpStack, iter, sizeX, blk)
            outData.GetRasterBand(1).WriteArray(result, 0, iter)
            iter = iter + blk
            del tmpStack[:]
        if overhead != 0:
            tmpStack.extend(rastercalcengine.exprStack)
            result = rastercalcengine.evaluateStack(tmpStack, blk_num * blk,
                                                    sizeX, overhead)
            outData.GetRasterBand(1).WriteArray(result, 0, blk_num * blk)
            del tmpStack[:]

        outData = None

        # add created layer to the map canvas if neсessary
        if self.loadCheckBox.isChecked():
            newLayer = QgsRasterLayer(fileName, QFileInfo(fileName).baseName())
            QgsMapLayerRegistry.instance().addMapLayer(newLayer)

        self.statusBar.showMessage(self.tr("Completed"))
        self.buttonOk.setEnabled(True)
Esempio n. 4
0
  def accept( self ):
    self.buttonOk.setEnabled( False )
    if self.leFileName.text().isEmpty():
      QMessageBox.warning( self, self.tr( "Error" ), self.tr( "Please specify output raster" ) )
      self.buttonOk.setEnabled( True )
      return

    rastercalcengine.exprStack = []
    usedRasters = rasterUtils.rasterList

    setRasters = dict()
    for r in usedRasters:
      setRasters[ r ] = self.layerInfo[ r ]
    rasterUtils.setRasters( setRasters )

    self.statusBar.showMessage( self.tr( "Running..." ) )
    QCoreApplication.processEvents()

    expression = rastercalcengine.pattern.parseString( str( self.commandTextEdit.toPlainText() ) )

    #result = rastercalcengine.evaluateStack( rastercalcengine.exprStack )

    # check is the result array
    #if not rasterUtils.isArray( result ):
    #  QMessageBox.warning( self, self.tr( "Error" ), self.tr( "Result is not an array." ) )
    #  self.statusBar.showMessage( self.tr( "Failed" ) )
    #  self.buttonOk.setEnabled( True )
    #  return

    # time to write results on disk as raster file
    # use the extent of the first layer referenced
    #extent = rasterUtils.Extent( self.layerInfo[ list( usedRasters )[ 0 ] ] )

    # make sure result is numpy/Numeric
    #etalonLayer = rasterUtils.getRaster( list( usedRasters )[ 0 ] )
    #print "Etalon layer", etalonLayer
    #( testFlag, res ) = rasterUtils.checkSameAs( result, setRasters[ list( usedRasters )[ 0 ] ] )
    #( testFlag, res ) = rasterUtils.checkSameAs( result, etalonLayer )
    #if not testFlag:
    #  result = res

    fileName = os.path.normpath( str( self.leFileName.text() ) )
    pixelFormat = str( self.cmbPixelFormat.currentText() )

    firstusedRaster=list( rastercalcengine.rasterNames )[ 0 ]
    etalon = self.layerInfo[firstusedRaster]
    #rasterUtils.writeGeoTiff( result, [ extent.xMinimum(), extent.yMinimum(), extent.xMaximum(), extent.yMaximum() ], pixelFormat, fileName, etalon )

    ( sizeX, sizeY ) = rasterUtils.rasterSize( firstusedRaster )
    blk = 250
    blk_num = sizeY / blk
    overhead = sizeY - ( blk_num * blk )
    outData = rasterUtils.outDataset( fileName, pixelFormat, etalon, sizeX, sizeY )
    tmpStack = []
    iter = 0
    for row in range( blk_num ):
      tmpStack.extend( rastercalcengine.exprStack )
      result = rastercalcengine.evaluateStack( tmpStack, iter, sizeX, blk )
      outData.GetRasterBand( 1 ).WriteArray( result, 0, iter )
      iter = iter + blk
      del tmpStack[ : ]
    if overhead !=0:
      tmpStack.extend( rastercalcengine.exprStack )
      result = rastercalcengine.evaluateStack( tmpStack, blk_num*blk, sizeX, overhead )
      outData.GetRasterBand( 1 ).WriteArray( result, 0, blk_num*blk )
      del tmpStack[ : ]

    outData = None

    # add created layer to the map canvas if neсessary
    if self.loadCheckBox.isChecked():
      newLayer = QgsRasterLayer( fileName, QFileInfo( fileName ).baseName() )
      QgsMapLayerRegistry.instance().addMapLayer( newLayer )

    self.statusBar.showMessage( self.tr( "Completed" ) )
    self.buttonOk.setEnabled( True )