Skip to content
Permalink
Browse files

add option to select shapefile geometry in merge shapes tool

git-svn-id: http://svn.osgeo.org/qgis/trunk@15370 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
alexbruy
alexbruy committed Mar 6, 2011
1 parent 19e123f commit 8d1b9e58533f9bc3f4ba91436306a614cfb7e6b0
@@ -74,10 +74,14 @@ def changeMode( self ):
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 @@ def accept( self ):
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

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()

# 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

QApplication.setOverrideCursor( QCursor( Qt.WaitCursor ) )
self.btnOk.setEnabled( False )

@@ -197,6 +204,8 @@ def run( self ):
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 )
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>377</width>
<height>273</height>
<height>302</height>
</rect>
</property>
<property name="windowTitle">
@@ -21,6 +21,36 @@
</property>
</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">
@@ -324,3 +324,23 @@ def getUniqueValuesCount( vlayer, fieldIndex, useSelection ):
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

0 comments on commit 8d1b9e5

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