2010-06-04 00:31:48 +00:00
# -*- coding: utf-8 -*-
2012-10-06 13:10:25 +02:00
"""
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
doContour . py
- - - - - - - - - - - - - - - - - - - - -
Date : June 2010
Copyright : ( C ) 2010 by Giuseppe Sucameli
Email : brush dot tyler at gmail dot com
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* This program is free software ; you can redistribute it and / or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation ; either version 2 of the License , or *
* ( at your option ) any later version . *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
"""
__author__ = ' Giuseppe Sucameli '
__date__ = ' June 2010 '
__copyright__ = ' (C) 2010, Giuseppe Sucameli '
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = ' $Format: % H$ '
2010-06-04 00:31:48 +00:00
from PyQt4 . QtCore import *
from PyQt4 . QtGui import *
from qgis . core import *
from qgis . gui import *
from ui_widgetContour import Ui_GdalToolsWidget as Ui_Widget
from widgetPluginBase import GdalToolsBasePluginWidget as BasePluginWidget
import GdalTools_utils as Utils
class GdalToolsDialog ( QWidget , Ui_Widget , BasePluginWidget ) :
def __init__ ( self , iface ) :
QWidget . __init__ ( self )
self . iface = iface
self . setupUi ( self )
BasePluginWidget . __init__ ( self , self . iface , " gdal_contour " )
2011-04-15 18:30:10 +00:00
gdalVersion = Utils . GdalConfig . version ( )
self . useDirAsOutput = gdalVersion < " 1.7.0 "
2011-06-16 01:51:22 +02:00
if self . useDirAsOutput :
self . label_2 . setText ( QApplication . translate ( " GdalToolsWidget " , " &Output directory for contour lines (shapefile) " ) )
2011-04-15 18:30:10 +00:00
self . outSelector . setType ( self . outSelector . FILE )
2010-06-04 00:31:48 +00:00
# set the default QSpinBoxes value
self . intervalDSpinBox . setValue ( 10.0 )
self . setParamsStatus (
[
2011-04-15 18:30:10 +00:00
( self . inSelector , SIGNAL ( " filenameChanged() " ) ) ,
( self . outSelector , SIGNAL ( " filenameChanged() " ) ) ,
2010-06-04 00:31:48 +00:00
( self . intervalDSpinBox , SIGNAL ( " valueChanged(double) " ) ) ,
( self . attributeEdit , SIGNAL ( " textChanged(const QString &) " ) , self . attributeCheck )
]
)
2011-04-15 18:30:10 +00:00
self . connect ( self . inSelector , SIGNAL ( " selectClicked() " ) , self . fillInputFileEdit )
self . connect ( self . outSelector , SIGNAL ( " selectClicked() " ) , self . fillOutputFileEdit )
2010-06-04 00:31:48 +00:00
2011-03-16 07:40:58 +00:00
def onLayersChanged ( self ) :
2011-04-15 18:30:10 +00:00
self . inSelector . setLayers ( Utils . LayerRegistry . instance ( ) . getRasterLayers ( ) )
2010-06-04 00:31:48 +00:00
def fillInputFileEdit ( self ) :
lastUsedFilter = Utils . FileFilter . lastUsedRasterFilter ( )
inputFile = Utils . FileDialog . getOpenFileName ( self , self . tr ( " Select the input file for Contour " ) , Utils . FileFilter . allRastersFilter ( ) , lastUsedFilter )
if inputFile . isEmpty ( ) :
return
Utils . FileFilter . setLastUsedRasterFilter ( lastUsedFilter )
2011-04-15 18:30:10 +00:00
self . inSelector . setFilename ( inputFile )
def fillOutputFileEdit ( self ) :
if not self . useDirAsOutput :
lastUsedFilter = Utils . FileFilter . lastUsedVectorFilter ( )
2011-05-10 13:38:46 +02:00
outputFile , encoding = Utils . FileDialog . getSaveFileName ( self , self . tr ( " Select where to save the Contour output " ) , Utils . FileFilter . allVectorsFilter ( ) , lastUsedFilter , True )
2011-04-15 18:30:10 +00:00
else :
outputFile , encoding = Utils . FileDialog . getExistingDirectory ( self , self . tr ( " Select where to save the Contour output " ) , True )
2010-06-04 00:31:48 +00:00
2011-04-15 18:30:10 +00:00
if outputFile . isEmpty ( ) :
2010-06-04 00:31:48 +00:00
return
2011-04-15 18:30:10 +00:00
if not self . useDirAsOutput :
Utils . FileFilter . setLastUsedVectorFilter ( lastUsedFilter )
self . outSelector . setFilename ( outputFile )
2010-06-04 00:31:48 +00:00
self . lastEncoding = encoding
def getArguments ( self ) :
arguments = QStringList ( )
if self . attributeCheck . isChecked ( ) and not self . attributeEdit . text ( ) . isEmpty ( ) :
arguments << " -a "
arguments << self . attributeEdit . text ( )
if True : # XXX in this moment the -i argument is not optional
arguments << " -i "
arguments << QString ( str ( self . intervalDSpinBox . value ( ) ) )
2011-04-15 18:30:10 +00:00
arguments << self . getInputFileName ( )
arguments << self . outSelector . filename ( )
2010-06-04 00:31:48 +00:00
return arguments
2011-04-15 18:30:10 +00:00
def getInputFileName ( self ) :
return self . inSelector . filename ( )
2010-06-04 00:31:48 +00:00
def getOutputFileName ( self ) :
2011-04-15 18:30:10 +00:00
if self . useDirAsOutput :
fn = self . outSelector . filename ( )
return fn if fn . isEmpty ( ) else fn + QDir . separator ( ) + " contour.shp "
return self . outSelector . filename ( )
2010-06-04 00:31:48 +00:00
def addLayerIntoCanvas ( self , fileInfo ) :
2011-04-15 18:30:10 +00:00
vl = self . iface . addVectorLayer ( fileInfo . filePath ( ) , fileInfo . baseName ( ) , " ogr " )
2011-03-23 01:14:41 +00:00
if vl != None and vl . isValid ( ) :
2010-08-06 16:15:15 +00:00
if hasattr ( self , ' lastEncoding ' ) :
vl . setProviderEncoding ( self . lastEncoding )