Skip to content
Permalink
Browse files

option to select separate shapefiles for merging with fTools

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14616 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
alexbruy
alexbruy committed Nov 13, 2010
1 parent 0931de1 commit ef77d9cb737c49162c7e55e5d199c436e9f8068c
Showing with 51 additions and 14 deletions.
  1. +43 −13 python/plugins/fTools/tools/doMergeShapes.py
  2. +8 −1 python/plugins/fTools/tools/frmMergeShapes.ui
@@ -24,6 +24,7 @@ def __init__( self, iface ):

QObject.connect( self.btnSelectDir, SIGNAL( "clicked()" ), self.inputDir )
QObject.connect( self.btnSelectFile, SIGNAL( "clicked()" ), self.outFile )
QObject.connect( self.chkListMode, SIGNAL( "stateChanged( int )" ), self.changeMode )

def inputDir( self ):
inDir = QFileDialog.getExistingDirectory( self,
@@ -33,18 +34,18 @@ def inputDir( self ):
if inDir.isEmpty():
return

#workDir = QDir( inDir )
#workDir.setFilter( QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot )
#nameFilter = QStringList() << "*.shp" << "*.SHP"
#workDir.setNameFilters( nameFilter )
#self.inputFiles = workDir.entryList()
#if self.inputFiles.count() == 0:
# QMessageBox.warning( self, self.tr( "No shapefiles found" ),
# self.tr( "There are no shapefiles in this directory. Please select another one." ) )
# self.inputFiles = None
# return

#self.progressFiles.setRange( 0, self.inputFiles.count() )
workDir = QDir( inDir )
workDir.setFilter( QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot )
nameFilter = QStringList() << "*.shp" << "*.SHP"
workDir.setNameFilters( nameFilter )
self.inputFiles = workDir.entryList()
if self.inputFiles.count() == 0:
QMessageBox.warning( self, self.tr( "No shapefiles found" ),
self.tr( "There are no shapefiles in this directory. Please select another one." ) )
self.inputFiles = None
return

self.progressFiles.setRange( 0, self.inputFiles.count() )
self.leInputDir.setText( inDir )

def outFile( self ):
@@ -53,6 +54,30 @@ def outFile( self ):
return
self.leOutShape.setText( self.outFileName )

def inputFile( self ):
files = QFileDialog.getOpenFileNames( self, self.tr( "Select files to merge" ), ".", "Shapefiles(*.shp *.SHP)" )
if files.isEmpty():
self.inputFiles = None
return

self.inputFiles = QStringList()
for f in files:
fileName = QFileInfo( f ).fileName()
self.inputFiles.append( fileName )

self.progressFiles.setRange( 0, self.inputFiles.count() )
self.leInputDir.setText( files.join( ";" ) )

def changeMode( self ):
if self.chkListMode.isChecked():
self.label.setText( self.tr( "Input files" ) )
QObject.disconnect( self.btnSelectDir, SIGNAL( "clicked()" ), self.inputDir )
QObject.connect( self.btnSelectDir, SIGNAL( "clicked()" ), self.inputFile )
else:
self.label.setText( self.tr( "Input directory" ) )
QObject.disconnect( self.btnSelectDir, SIGNAL( "clicked()" ), self.inputFile )
QObject.connect( self.btnSelectDir, SIGNAL( "clicked()" ), self.inputDir )

def reject( self ):
QDialog.reject( self )

@@ -77,7 +102,11 @@ def accept( self ):
QMessageBox.warning( self, self.tr( "Delete error" ), self.tr( "Can't delete file %1" ).arg( outFileName ) )
return

baseDir = self.leInputDir.text()
if self.chkListMode.isChecked():
files = self.leInputDir.text().split( ";" )
baseDir = QFileInfo( files[ 0 ] ).absolutePath()
else:
baseDir = self.leInputDir.text()

QApplication.setOverrideCursor( QCursor( Qt.WaitCursor ) )
self.btnOk.setEnabled( False )
@@ -97,6 +126,7 @@ def accept( self ):

def setProgressRange( self, max ):
self.progressFeatures.setRange( 0, max )
self.progressFeatures.setValue( 0 )

def featureProcessed( self ):
self.progressFeatures.setValue( self.progressFeatures.value() + 1 )
@@ -7,13 +7,20 @@
<x>0</x>
<y>0</y>
<width>377</width>
<height>246</height>
<height>273</height>
</rect>
</property>
<property name="windowTitle">
<string>Merge shapefiles</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="chkListMode">
<property name="text">
<string>Select by layers in the folder</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">

0 comments on commit ef77d9c

Please sign in to comment.
You can’t perform that action at this time.