2011-02-08 00:09:24 +00:00
# -*- coding: utf-8 -*-
2012-10-06 13:10:25 +02:00
"""
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
doTileIndex . py
- - - - - - - - - - - - - - - - - - - - -
Date : February 2011
Copyright : ( C ) 2011 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__ = ' February 2011 '
__copyright__ = ' (C) 2011, Giuseppe Sucameli '
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = ' $Format: % H$ '
2011-02-08 00:09:24 +00:00
from PyQt4 . QtCore import *
from PyQt4 . QtGui import *
from qgis . core import *
from qgis . gui import *
from ui_widgetTileIndex import Ui_GdalToolsWidget as Ui_Widget
from widgetPluginBase import GdalToolsBasePluginWidget as BasePluginWidget
import GdalTools_utils as Utils
import os . path
class GdalToolsDialog ( QWidget , Ui_Widget , BasePluginWidget ) :
def __init__ ( self , iface ) :
QWidget . __init__ ( self )
self . iface = iface
self . setupUi ( self )
BasePluginWidget . __init__ ( self , self . iface , " gdaltindex " )
2011-04-15 18:30:10 +00:00
self . inSelector . setType ( self . inSelector . FILE )
self . outSelector . setType ( self . outSelector . FILE )
2011-02-08 00:09:24 +00:00
self . setParamsStatus (
[
2011-04-15 18:30:10 +00:00
( self . inSelector , SIGNAL ( " filenameChanged() " ) ) ,
2011-02-08 00:09:24 +00:00
#( self.recurseCheck, SIGNAL( "stateChanged( int )" ),
2011-04-15 18:30:10 +00:00
( self . outSelector , SIGNAL ( " filenameChanged() " ) ) ,
2011-02-08 00:09:24 +00:00
( self . indexFieldEdit , SIGNAL ( " textChanged( const QString & ) " ) , self . indexFieldCheck ) ,
2011-03-13 23:21:00 +00:00
( self . absolutePathCheck , SIGNAL ( " stateChanged( int ) " ) , None , " 1.5.0 " ) ,
( self . skipDifferentProjCheck , SIGNAL ( " stateChanged( int ) " ) , None , " 1.5.0 " )
2011-02-08 00:09:24 +00:00
]
)
2011-04-15 18:30:10 +00:00
self . connect ( self . inSelector , SIGNAL ( " selectClicked() " ) , self . fillInputDirEdit )
self . connect ( self . outSelector , SIGNAL ( " selectClicked() " ) , self . fillOutputFileEdit )
2011-02-08 00:09:24 +00:00
def fillInputDirEdit ( self ) :
inputDir = Utils . FileDialog . getExistingDirectory ( self , self . tr ( " Select the input directory with raster files " ) )
if inputDir . isEmpty ( ) :
return
2011-04-15 18:30:10 +00:00
self . inSelector . setFilename ( inputDir )
2011-02-08 00:09:24 +00:00
def fillOutputFileEdit ( self ) :
lastUsedFilter = Utils . FileFilter . lastUsedVectorFilter ( )
outputFile , encoding = Utils . FileDialog . getSaveFileName ( self , self . tr ( " Select where to save the TileIndex output " ) , Utils . FileFilter . allVectorsFilter ( ) , lastUsedFilter , True )
if outputFile . isEmpty ( ) :
return
Utils . FileFilter . setLastUsedVectorFilter ( lastUsedFilter )
self . outputFormat = Utils . fillVectorOutputFormat ( lastUsedFilter , outputFile )
2011-04-15 18:30:10 +00:00
self . outSelector . setFilename ( outputFile )
2011-02-08 00:09:24 +00:00
self . lastEncoding = encoding
def getArguments ( self ) :
arguments = QStringList ( )
if self . indexFieldCheck . isChecked ( ) and not self . indexFieldEdit . text ( ) . isEmpty ( ) :
arguments << " -tileindex "
arguments << self . indexFieldEdit . text ( )
if self . absolutePathCheck . isChecked ( ) :
arguments << " -write_absolute_path "
if self . skipDifferentProjCheck . isChecked ( ) :
arguments << " -skip_different_projection "
2011-04-15 18:30:10 +00:00
arguments << self . getOutputFileName ( )
arguments << Utils . getRasterFiles ( self . getInputFileName ( ) , self . recurseCheck . isChecked ( ) )
2011-02-08 00:09:24 +00:00
return arguments
def getOutputFileName ( self ) :
2011-04-15 18:30:10 +00:00
return self . outSelector . filename ( )
def getInputFileName ( self ) :
return self . inSelector . filename ( )
2011-02-08 00:09:24 +00:00
def addLayerIntoCanvas ( self , fileInfo ) :
vl = self . iface . addVectorLayer ( fileInfo . filePath ( ) , fileInfo . baseName ( ) , " ogr " )
2011-03-23 01:14:41 +00:00
if vl != None and vl . isValid ( ) :
2011-02-08 00:09:24 +00:00
if hasattr ( self , ' lastEncoding ' ) :
vl . setProviderEncoding ( self . lastEncoding )
2011-04-15 18:30:10 +00:00