[QGIS Commit] r15370 - trunk/qgis/python/plugins/fTools/tools
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sun Mar 6 14:35:26 EST 2011
Author: alexbruy
Date: 2011-03-06 11:35:26 -0800 (Sun, 06 Mar 2011)
New Revision: 15370
Modified:
trunk/qgis/python/plugins/fTools/tools/doMergeShapes.py
trunk/qgis/python/plugins/fTools/tools/frmMergeShapes.ui
trunk/qgis/python/plugins/fTools/tools/ftools_utils.py
Log:
add option to select shapefile geometry in merge shapes tool
Modified: trunk/qgis/python/plugins/fTools/tools/doMergeShapes.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/doMergeShapes.py 2011-03-06 19:33:54 UTC (rev 15369)
+++ trunk/qgis/python/plugins/fTools/tools/doMergeShapes.py 2011-03-06 19:35:26 UTC (rev 15370)
@@ -74,10 +74,14 @@
self.label.setText( self.tr( "Input files" ) )
QObject.disconnect( self.btnSelectDir, SIGNAL( "clicked()" ), self.inputDir )
QObject.connect( self.btnSelectDir, SIGNAL( "clicked()" ), self.inputFile )
+ self.lblGeometry.setEnabled( False )
+ self.cmbGeometry.setEnabled( False )
else:
self.label.setText( self.tr( "Input directory" ) )
QObject.disconnect( self.btnSelectDir, SIGNAL( "clicked()" ), self.inputFile )
QObject.connect( self.btnSelectDir, SIGNAL( "clicked()" ), self.inputDir )
+ self.lblGeometry.setEnabled( True )
+ self.cmbGeometry.setEnabled( True )
def reject( self ):
QDialog.reject( self )
@@ -95,25 +99,28 @@
self.inputFiles = None
return
- self.progressFiles.setRange( 0, self.inputFiles.count() )
-
if self.outFileName is None:
QMessageBox.warning( self, self.tr( "No output file" ),
self.tr( "Please specify output file." ) )
return
+ if self.chkListMode.isChecked():
+ files = self.leInputDir.text().split( ";" )
+ baseDir = QFileInfo( files[ 0 ] ).absolutePath()
+ else:
+ baseDir = self.leInputDir.text()
+
+ # look for shapes with specified geometry type
+ self.inputFiles = ftools_utils.getShapesByGeometryType( baseDir, self.inputFiles, self.cmbGeometry.currentIndex() )
+
+ self.progressFiles.setRange( 0, self.inputFiles.count() )
+
outFile = QFile( self.outFileName )
if outFile.exists():
if not QgsVectorFileWriter.deleteShapeFile( self.outFileName ):
QMessageBox.warning( self, self.tr( "Delete error" ), self.tr( "Can't delete file %1" ).arg( outFileName ) )
return
- 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 )
@@ -197,6 +204,8 @@
for fileName in self.shapes:
layerPath = QFileInfo( self.baseDir + "/" + fileName ).absoluteFilePath()
newLayer = QgsVectorLayer( layerPath, QFileInfo( layerPath ).baseName(), "ogr" )
+ if not newLayer.isValid():
+ continue
vprovider = newLayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
Modified: trunk/qgis/python/plugins/fTools/tools/frmMergeShapes.ui
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/frmMergeShapes.ui 2011-03-06 19:33:54 UTC (rev 15369)
+++ trunk/qgis/python/plugins/fTools/tools/frmMergeShapes.ui 2011-03-06 19:35:26 UTC (rev 15370)
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>377</width>
- <height>273</height>
+ <height>302</height>
</rect>
</property>
<property name="windowTitle">
@@ -22,6 +22,36 @@
</widget>
</item>
<item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="QLabel" name="lblGeometry">
+ <property name="text">
+ <string>Shapefile type</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="cmbGeometry">
+ <item>
+ <property name="text">
+ <string>Polygon</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Line</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Point</string>
+ </property>
+ </item>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
<widget class="QLabel" name="label">
<property name="text">
<string>Input directory</string>
Modified: trunk/qgis/python/plugins/fTools/tools/ftools_utils.py
===================================================================
--- trunk/qgis/python/plugins/fTools/tools/ftools_utils.py 2011-03-06 19:33:54 UTC (rev 15369)
+++ trunk/qgis/python/plugins/fTools/tools/ftools_utils.py 2011-03-06 19:35:26 UTC (rev 15370)
@@ -324,3 +324,23 @@
values.append( feat.attributeMap()[ fieldIndex ].toString() )
count += 1
return count
+
+def getShapesByGeometryType( baseDir, inShapes, geomType ):
+ outShapes = QStringList()
+ for fileName in inShapes:
+ layerPath = QFileInfo( baseDir + "/" + fileName ).absoluteFilePath()
+ vLayer = QgsVectorLayer( layerPath, QFileInfo( layerPath ).baseName(), "ogr" )
+ if not vLayer.isValid():
+ continue
+ layerGeometry = vLayer.geometryType()
+ if layerGeometry == QGis.Polygon and geomType == 0:
+ outShapes << fileName
+ elif layerGeometry == QGis.Line and geomType == 1:
+ outShapes << fileName
+ elif layerGeometry == QGis.Point and geomType == 2:
+ outShapes << fileName
+
+ if outShapes.count() == 0:
+ return None
+
+ return outShapes
More information about the QGIS-commit
mailing list