[FEATURE] Densify geometries tool for fTools (fix #3628). Still without

icon
This commit is contained in:
Alexander Bruy 2011-11-12 12:50:51 +02:00
parent 48112cc1bc
commit ad1a4e2cde
3 changed files with 265 additions and 75 deletions

View File

@ -103,6 +103,7 @@ class fToolsPlugin:
self.voronoi.setIcon(QIcon(self.getThemeIcon("voronoi.png"))) self.voronoi.setIcon(QIcon(self.getThemeIcon("voronoi.png")))
self.extNodes.setIcon(QIcon(self.getThemeIcon("extract_nodes.png"))) self.extNodes.setIcon(QIcon(self.getThemeIcon("extract_nodes.png")))
self.simplify.setIcon(QIcon(self.getThemeIcon("simplify.png"))) self.simplify.setIcon(QIcon(self.getThemeIcon("simplify.png")))
self.densify.setIcon(QIcon(self.getThemeIcon("densify.png")))
self.multiToSingle.setIcon(QIcon(self.getThemeIcon("multi_to_single.png"))) self.multiToSingle.setIcon(QIcon(self.getThemeIcon("multi_to_single.png")))
self.singleToMulti.setIcon(QIcon(self.getThemeIcon("single_to_multi.png"))) self.singleToMulti.setIcon(QIcon(self.getThemeIcon("single_to_multi.png")))
self.polysToLines.setIcon(QIcon(self.getThemeIcon("to_lines.png"))) self.polysToLines.setIcon(QIcon(self.getThemeIcon("to_lines.png")))
@ -168,12 +169,14 @@ class fToolsPlugin:
self.voronoi = QAction(QCoreApplication.translate("fTools", "Voronoi Polygons"),self.iface.mainWindow()) self.voronoi = QAction(QCoreApplication.translate("fTools", "Voronoi Polygons"),self.iface.mainWindow())
self.extNodes = QAction(QCoreApplication.translate("fTools", "Extract nodes"),self.iface.mainWindow()) self.extNodes = QAction(QCoreApplication.translate("fTools", "Extract nodes"),self.iface.mainWindow())
self.simplify = QAction(QCoreApplication.translate("fTools", "Simplify geometries"),self.iface.mainWindow()) self.simplify = QAction(QCoreApplication.translate("fTools", "Simplify geometries"),self.iface.mainWindow())
self.densify = QAction(QCoreApplication.translate("fTools", "Densify geometries"),self.iface.mainWindow())
self.multiToSingle = QAction(QCoreApplication.translate("fTools", "Multipart to singleparts"),self.iface.mainWindow()) self.multiToSingle = QAction(QCoreApplication.translate("fTools", "Multipart to singleparts"),self.iface.mainWindow())
self.singleToMulti = QAction(QCoreApplication.translate("fTools", "Singleparts to multipart"),self.iface.mainWindow()) self.singleToMulti = QAction(QCoreApplication.translate("fTools", "Singleparts to multipart"),self.iface.mainWindow())
self.polysToLines = QAction(QCoreApplication.translate("fTools", "Polygons to lines"),self.iface.mainWindow()) self.polysToLines = QAction(QCoreApplication.translate("fTools", "Polygons to lines"),self.iface.mainWindow())
self.linesToPolys = QAction(QCoreApplication.translate("fTools", "Lines to polygons"),self.iface.mainWindow()) self.linesToPolys = QAction(QCoreApplication.translate("fTools", "Lines to polygons"),self.iface.mainWindow())
self.conversionMenu.addActions([self.checkGeom, self.compGeo, self.centroids, self.delaunay, self.voronoi, self.conversionMenu.addActions([self.checkGeom, self.compGeo, self.centroids, self.delaunay, self.voronoi,
self.simplify, self.multiToSingle, self.singleToMulti, self.polysToLines, self.linesToPolys, self.extNodes]) self.simplify, self.densify, self.multiToSingle, self.singleToMulti, self.polysToLines, self.linesToPolys,
self.extNodes])
self.dataManageMenu = QMenu(QCoreApplication.translate("fTools", "&Data Management Tools")) self.dataManageMenu = QMenu(QCoreApplication.translate("fTools", "&Data Management Tools"))
self.define = QAction(QCoreApplication.translate("fTools", "Define current projection"), self.iface.mainWindow()) self.define = QAction(QCoreApplication.translate("fTools", "Define current projection"), self.iface.mainWindow())
@ -224,7 +227,8 @@ class fToolsPlugin:
QObject.connect(self.multiToSingle, SIGNAL("triggered()"), self.domultiToSingle) QObject.connect(self.multiToSingle, SIGNAL("triggered()"), self.domultiToSingle)
QObject.connect(self.singleToMulti, SIGNAL("triggered()"), self.dosingleToMulti) QObject.connect(self.singleToMulti, SIGNAL("triggered()"), self.dosingleToMulti)
QObject.connect(self.checkGeom, SIGNAL("triggered()"), self.docheckGeom) QObject.connect(self.checkGeom, SIGNAL("triggered()"), self.docheckGeom)
QObject.connect(self.simplify, SIGNAL("triggered()"), self.dosimplify) QObject.connect(self.simplify, SIGNAL("triggered()"), self.doSimplify)
QObject.connect(self.densify, SIGNAL("triggered()"), self.doDensify)
QObject.connect(self.centroids, SIGNAL("triggered()"), self.docentroids) QObject.connect(self.centroids, SIGNAL("triggered()"), self.docentroids)
QObject.connect(self.delaunay, SIGNAL("triggered()"), self.dodelaunay) QObject.connect(self.delaunay, SIGNAL("triggered()"), self.dodelaunay)
QObject.connect(self.voronoi, SIGNAL("triggered()"), self.dovoronoi) QObject.connect(self.voronoi, SIGNAL("triggered()"), self.dovoronoi)
@ -242,8 +246,14 @@ class fToolsPlugin:
def unload(self): def unload(self):
pass pass
def dosimplify(self): def doSimplify(self):
d = doSimplify.Dialog(self.iface) d = doSimplify.Dialog(self.iface, 1)
d.show()
d.exec_()
def doDensify(self):
d = doSimplify.Dialog(self.iface, 2)
d.show()
d.exec_() d.exec_()
def dopolysToLines(self): def dopolysToLines(self):

View File

@ -39,17 +39,18 @@ import ftools_utils
from ui_frmSimplify import Ui_Dialog from ui_frmSimplify import Ui_Dialog
class Dialog( QDialog, Ui_Dialog ): class Dialog( QDialog, Ui_Dialog ):
def __init__( self, iface ): def __init__( self, iface, function ):
QDialog.__init__( self ) QDialog.__init__( self )
self.setupUi( self ) self.setupUi( self )
self.iface = iface self.iface = iface
self.myFunction = function
self.simplifyThread = None self.workThread = None
self.okButton = self.buttonBox.button( QDialogButtonBox.Ok ) self.btnOk = self.buttonBox.button( QDialogButtonBox.Ok )
self.closeButton = self.buttonBox.button( QDialogButtonBox.Close ) self.btnClose = self.buttonBox.button( QDialogButtonBox.Close )
QObject.connect( self.writeShapefileCheck, SIGNAL( "stateChanged( int )" ), self.updateGui ) QObject.connect( self.chkWriteShapefile, SIGNAL( "stateChanged( int )" ), self.updateGui )
QObject.connect( self.btnSelectOutputFile, SIGNAL( "clicked()" ), self.selectOutputFile ) QObject.connect( self.btnSelectOutputFile, SIGNAL( "clicked()" ), self.selectOutputFile )
self.manageGui() self.manageGui()
@ -58,90 +59,105 @@ class Dialog( QDialog, Ui_Dialog ):
layers = ftools_utils.getLayerNames( [ QGis.Polygon, QGis.Line ] ) layers = ftools_utils.getLayerNames( [ QGis.Polygon, QGis.Line ] )
self.cmbInputLayer.addItems( layers ) self.cmbInputLayer.addItems( layers )
if self.myFunction == 2:
self.setWindowTitle( self.tr( "Densify geometries" ) )
self.lblTolerance.setText( self.tr( "Vertices to add" ) )
self.spnTolerance.setDecimals( 0 )
self.spnTolerance.setMinimum( 1 )
self.spnTolerance.setSingleStep( 1 )
self.spnTolerance.setValue( 1.0 )
def updateGui( self ): def updateGui( self ):
if self.writeShapefileCheck.isChecked(): if self.chkWriteShapefile.isChecked():
self.outputFileEdit.setEnabled( True ) self.edOutputFile.setEnabled( True )
self.btnSelectOutputFile.setEnabled( True ) self.btnSelectOutputFile.setEnabled( True )
self.addToCanvasCheck.setEnabled( True ) self.chkAddToCanvas.setEnabled( True )
else: else:
self.outputFileEdit.setEnabled( False ) self.edOutputFile.setEnabled( False )
self.btnSelectOutputFile.setEnabled( False ) self.btnSelectOutputFile.setEnabled( False )
self.addToCanvasCheck.setEnabled( False ) self.chkAddToCanvas.setEnabled( False )
self.encoding = None self.encoding = None
def selectOutputFile( self ): def selectOutputFile( self ):
self.outputFileEdit.clear() self.edOutputFile.clear()
(self.shapefileName, self.encoding) = ftools_utils.saveDialog(self) ( self.shapeFileName, self.encoding ) = ftools_utils.saveDialog( self )
if self.shapefileName is None or self.encoding is None: if self.shapeFileName is None or self.encoding is None:
return return
self.outputFileEdit.setText(QString(self.shapefileName)) self.edOutputFile.setText( QString( self.shapeFileName ) )
def accept( self ): def accept( self ):
vLayer = ftools_utils.getVectorLayerByName( self.cmbInputLayer.currentText() ) vLayer = ftools_utils.getVectorLayerByName( self.cmbInputLayer.currentText() )
QApplication.setOverrideCursor( Qt.WaitCursor ) QApplication.setOverrideCursor( Qt.WaitCursor )
self.okButton.setEnabled( False ) self.btnOk.setEnabled( False )
if self.writeShapefileCheck.isChecked(): if self.chkWriteShapefile.isChecked():
outFileName = self.outputFileEdit.text() outFileName = self.edOutputFile.text()
outFile = QFile( outFileName ) outFile = QFile( outFileName )
if outFile.exists(): if outFile.exists():
if not QgsVectorFileWriter.deleteShapeFile( outFileName ): if not QgsVectorFileWriter.deleteShapeFile( outFileName ):
QmessageBox.warning( self, self.tr( "Delete error" ), self.tr( "Can't delete file %1" ).arg( outFileName ) ) QMessageBox.warning( self, self.tr( "Delete error" ),
self.tr( "Can't delete file %1" ).arg( outFileName ) )
return return
self.simplifyThread = GeneralizationThread( vLayer, self.useSelectionCheck.isChecked(), self.toleranceSpin.value(), True, outFileName, self.encoding )
self.workThread = GeomThread( self.myFunction, vLayer, self.chkUseSelection.isChecked(),
self.spnTolerance.value(), True, outFileName, self.encoding )
else: else:
self.simplifyThread = GeneralizationThread( vLayer, self.useSelectionCheck.isChecked(), self.toleranceSpin.value(), False, None, None ) self.workThread = GeomThread( self.myFunction, vLayer, self.chkUseSelection.isChecked(),
QObject.connect( self.simplifyThread, SIGNAL( "rangeCalculated( PyQt_PyObject )" ), self.setProgressRange ) self.spnTolerance.value(), False, None, None )
QObject.connect( self.simplifyThread, SIGNAL( "featureProcessed()" ), self.featureProcessed )
QObject.connect( self.simplifyThread, SIGNAL( "generalizationFinished( PyQt_PyObject )" ), self.generalizationFinished )
QObject.connect( self.simplifyThread, SIGNAL( "generalizationInterrupted()" ), self.generalizationInterrupted )
self.closeButton.setText( self.tr( "Cancel" ) ) QObject.connect( self.workThread, SIGNAL( "rangeCalculated( PyQt_PyObject )" ), self.setProgressRange )
QObject.connect( self.workThread, SIGNAL( "featureProcessed()" ), self.featureProcessed )
QObject.connect( self.workThread, SIGNAL( "processingFinished( PyQt_PyObject )" ), self.processFinished )
QObject.connect( self.workThread, SIGNAL( "processingInterrupted()" ), self.processInterrupted )
self.btnClose.setText( self.tr( "Cancel" ) )
QObject.disconnect( self.buttonBox, SIGNAL( "rejected()" ), self.reject ) QObject.disconnect( self.buttonBox, SIGNAL( "rejected()" ), self.reject )
QObject.connect( self.closeButton, SIGNAL( "clicked()" ), self.stopProcessing ) QObject.connect( self.btnClose, SIGNAL( "clicked()" ), self.stopProcessing )
self.simplifyThread.start() self.workThread.start()
def setProgressRange( self, max ): def setProgressRange( self, maximum ):
self.progressBar.setRange( 0, max ) self.progressBar.setRange( 0, maximum )
def featureProcessed( self ): def featureProcessed( self ):
self.progressBar.setValue( self.progressBar.value() + 1 ) self.progressBar.setValue( self.progressBar.value() + 1 )
def generalizationFinished( self, pointsCount ): def processFinished( self, pointsCount ):
self.stopProcessing() self.stopProcessing()
QMessageBox.information( self, if self.myFunction == 1:
self.tr( "Simplify results" ), QMessageBox.information( self, self.tr( "Simplify results" ),
self.tr( "There were %1 vertices in original dataset which\nwere reduced to %2 vertices after simplification" ) self.tr( "There were %1 vertices in original dataset which\nwere reduced to %2 vertices after simplification" )
.arg( pointsCount[ 0 ] ) .arg( pointsCount[ 0 ] )
.arg( pointsCount[ 1 ] ) ) .arg( pointsCount[ 1 ] ) )
self.restoreGui() self.restoreGui()
if self.addToCanvasCheck.isEnabled() and self.addToCanvasCheck.isChecked():
if not ftools_utils.addShapeToCanvas( unicode( self.shapefileName ) ): if self.chkAddToCanvas.isEnabled() and self.chkAddToCanvas.isChecked():
QMessageBox.warning( self, self.tr( "Merging" ), if not ftools_utils.addShapeToCanvas( unicode( self.shapeFileName ) ):
QMessageBox.warning( self, self.tr( "Error" ),
self.tr( "Error loading output shapefile:\n%1" ) self.tr( "Error loading output shapefile:\n%1" )
.arg( unicode( self.shapefileName ) ) ) .arg( unicode( self.shapeFileName ) ) )
QMessageBox.information( self, self.tr( "Finished" ), self.tr( "Processing completed." ) )
self.iface.mapCanvas().refresh() self.iface.mapCanvas().refresh()
#self.restoreGui()
def generalizationInterrupted( self ): def processInterrupted( self ):
self.restoreGui() self.restoreGui()
def stopProcessing( self ): def stopProcessing( self ):
if self.simplifyThread != None: if self.workThread != None:
self.simplifyThread.stop() self.workThread.stop()
self.simplifyThread = None self.workThread = None
def restoreGui( self ): def restoreGui( self ):
self.progressBar.setValue( 0 ) self.progressBar.setValue( 0 )
QApplication.restoreOverrideCursor() QApplication.restoreOverrideCursor()
QObject.connect( self.buttonBox, SIGNAL( "rejected()" ), self.reject ) QObject.connect( self.buttonBox, SIGNAL( "rejected()" ), self.reject )
self.closeButton.setText( self.tr( "Close" ) ) self.btnClose.setText( self.tr( "Close" ) )
self.okButton.setEnabled( True ) self.btnOk.setEnabled( True )
def geomVertexCount( geometry ): def geomVertexCount( geometry ):
geomType = geometry.type() geomType = geometry.type()
@ -157,8 +173,41 @@ def geomVertexCount( geometry ):
else: else:
return None return None
class GeneralizationThread( QThread ): def densify( polyline, pointsNumber ):
def __init__( self, inputLayer, useSelection, tolerance, writeShape, shapePath, shapeEncoding ): output = []
if pointsNumber != 1:
multiplier = 1.0 / float( pointsNumber + 1 )
else:
multiplier = 1
for i in xrange( len( polyline ) - 1 ):
p1 = polyline[ i ]
p2 = polyline[ i + 1 ]
output.append( p1 )
for j in xrange( pointsNumber ):
delta = multiplier * ( j + 1 )
x = p1.x() + delta * ( p2.x() - p1.x() )
y = p1.y() + delta * ( p2.y() - p1.y() )
output.append( QgsPoint( x, y ) )
if j + 1 == pointsNumber:
break
output.append( polyline[ len( polyline ) - 1 ] )
return output
def densifyGeometry( geometry, pointsNumber, isPolygon ):
if isPolygon:
rings = geometry.asPolygon()
output = []
for ring in rings:
ring = densify( ring, pointsNumber )
output.append( ring )
return QgsGeometry.fromPolygon( output )
else:
points = geometry.asPolyline()
output = densify( points, pointsNumber )
return QgsGeometry.fromPolyline( output )
class GeomThread( QThread ):
def __init__( self, function, inputLayer, useSelection, tolerance, writeShape, shapePath, shapeEncoding ):
QThread.__init__( self, QThread.currentThread() ) QThread.__init__( self, QThread.currentThread() )
self.inputLayer = inputLayer self.inputLayer = inputLayer
self.useSelection = useSelection self.useSelection = useSelection
@ -166,15 +215,18 @@ class GeneralizationThread( QThread ):
self.writeShape = writeShape self.writeShape = writeShape
self.outputFileName = shapePath self.outputFileName = shapePath
self.outputEncoding = shapeEncoding self.outputEncoding = shapeEncoding
self.myFunction = function
self.shapeFileWriter = None
self.pointsBefore = 0
self.pointsAfter = 0
self.mutex = QMutex() self.mutex = QMutex()
self.stopMe = 0 self.stopMe = 0
def run( self ): def run( self ):
if self.myFunction == 1:
self.runSimplify()
else:
self.runDensify()
def runSimplify( self ):
self.mutex.lock() self.mutex.lock()
self.stopMe = 0 self.stopMe = 0
self.mutex.unlock() self.mutex.unlock()
@ -183,6 +235,9 @@ class GeneralizationThread( QThread ):
shapeFileWriter = None shapeFileWriter = None
pointsBefore = 0
pointsAfter = 0
if self.writeShape: if self.writeShape:
vProvider = self.inputLayer.dataProvider() vProvider = self.inputLayer.dataProvider()
allAttrs = vProvider.attributeIndexes() allAttrs = vProvider.attributeIndexes()
@ -200,9 +255,11 @@ class GeneralizationThread( QThread ):
for f in selection: for f in selection:
featGeometry = QgsGeometry( f.geometry() ) featGeometry = QgsGeometry( f.geometry() )
attrMap = f.attributeMap() attrMap = f.attributeMap()
self.pointsBefore += geomVertexCount( featGeometry )
pointsBefore += geomVertexCount( featGeometry )
newGeometry = featGeometry.simplify( self.tolerance ) newGeometry = featGeometry.simplify( self.tolerance )
self.pointsAfter += geomVertexCount( newGeometry ) pointsAfter += geomVertexCount( newGeometry )
feature = QgsFeature() feature = QgsFeature()
feature.setGeometry( newGeometry ) feature.setGeometry( newGeometry )
feature.setAttributeMap( attrMap ) feature.setAttributeMap( attrMap )
@ -222,9 +279,11 @@ class GeneralizationThread( QThread ):
while vProvider.nextFeature( f ): while vProvider.nextFeature( f ):
featGeometry = QgsGeometry( f.geometry() ) featGeometry = QgsGeometry( f.geometry() )
attrMap = f.attributeMap() attrMap = f.attributeMap()
self.pointsBefore += geomVertexCount( featGeometry )
pointsBefore += geomVertexCount( featGeometry )
newGeometry = featGeometry.simplify( self.tolerance ) newGeometry = featGeometry.simplify( self.tolerance )
self.pointsAfter += geomVertexCount( newGeometry ) pointsAfter += geomVertexCount( newGeometry )
feature = QgsFeature() feature = QgsFeature()
feature.setGeometry( newGeometry ) feature.setGeometry( newGeometry )
feature.setAttributeMap( attrMap ) feature.setAttributeMap( attrMap )
@ -248,9 +307,11 @@ class GeneralizationThread( QThread ):
for f in selection: for f in selection:
featureId = f.id() featureId = f.id()
featGeometry = QgsGeometry( f.geometry() ) featGeometry = QgsGeometry( f.geometry() )
self.pointsBefore += geomVertexCount( featGeometry )
pointsBefore += geomVertexCount( featGeometry )
newGeometry = featGeometry.simplify( self.tolerance ) newGeometry = featGeometry.simplify( self.tolerance )
self.pointsAfter += geomVertexCount( newGeometry ) pointsAfter += geomVertexCount( newGeometry )
self.inputLayer.changeGeometry( featureId, newGeometry ) self.inputLayer.changeGeometry( featureId, newGeometry )
self.emit( SIGNAL( "featureProcessed()" ) ) self.emit( SIGNAL( "featureProcessed()" ) )
@ -267,9 +328,11 @@ class GeneralizationThread( QThread ):
while vProvider.nextFeature( f ): while vProvider.nextFeature( f ):
featureId = f.id() featureId = f.id()
featGeometry = QgsGeometry( f.geometry() ) featGeometry = QgsGeometry( f.geometry() )
self.pointsBefore += geomVertexCount( featGeometry )
pointsBefore += geomVertexCount( featGeometry )
newGeometry = featGeometry.simplify( self.tolerance ) newGeometry = featGeometry.simplify( self.tolerance )
self.pointsAfter += geomVertexCount( newGeometry ) pointsAfter += geomVertexCount( newGeometry )
self.inputLayer.changeGeometry( featureId, newGeometry ) self.inputLayer.changeGeometry( featureId, newGeometry )
self.emit( SIGNAL( "featureProcessed()" ) ) self.emit( SIGNAL( "featureProcessed()" ) )
@ -288,9 +351,129 @@ class GeneralizationThread( QThread ):
del shapeFileWriter del shapeFileWriter
if not interrupted: if not interrupted:
self.emit( SIGNAL( "generalizationFinished( PyQt_PyObject )" ), ( self.pointsBefore, self.pointsAfter ) ) self.emit( SIGNAL( "processingFinished( PyQt_PyObject )" ), ( pointsBefore, pointsAfter ) )
else: else:
self.emit( SIGNAL( "generalizationInterrupted()" ) ) self.emit( SIGNAL( "processingInterrupted()" ) )
def runDensify( self ):
self.mutex.lock()
self.stopMe = 0
self.mutex.unlock()
interrupted = False
shapeFileWriter = None
isPolygon = self.inputLayer.geometryType() == QGis.Polygon
if self.writeShape:
# prepare writer
vProvider = self.inputLayer.dataProvider()
allAttrs = vProvider.attributeIndexes()
vProvider.select( allAttrs )
shapeFields = vProvider.fields()
crs = vProvider.crs()
wkbType = self.inputLayer.wkbType()
if not crs.isValid():
crs = None
shapeFileWriter = QgsVectorFileWriter( self.outputFileName, self.outputEncoding, shapeFields, wkbType, crs )
featureId = 0
if self.useSelection:
selection = self.inputLayer.selectedFeatures()
self.emit( SIGNAL( "rangeCalculated( PyQt_PyObject )" ), len( selection ) )
for f in selection:
featGeometry = QgsGeometry( f.geometry() )
attrMap = f.attributeMap()
newGeometry = densifyGeometry( featGeometry, self.tolerance, isPolygon )
feature = QgsFeature()
feature.setGeometry( newGeometry )
feature.setAttributeMap( attrMap )
shapeFileWriter.addFeature( feature )
featureId += 1
self.emit( SIGNAL( "featureProcessed()" ) )
self.mutex.lock()
s = self.stopMe
self.mutex.unlock()
if s == 1:
interrupted = True
break
else:
self.emit( SIGNAL( "rangeCalculated( PyQt_PyObject )" ), vProvider.featureCount() )
f = QgsFeature()
while vProvider.nextFeature( f ):
featGeometry = QgsGeometry( f.geometry() )
attrMap = f.attributeMap()
newGeometry = densifyGeometry( featGeometry, self.tolerance, isPolygon )
feature = QgsFeature()
feature.setGeometry( newGeometry )
feature.setAttributeMap( attrMap )
shapeFileWriter.addFeature( feature )
featureId += 1
self.emit( SIGNAL( "featureProcessed()" ) )
self.mutex.lock()
s = self.stopMe
self.mutex.unlock()
if s == 1:
interrupted = True
break
else: # modify existing shapefile
if not self.inputLayer.isEditable():
self.inputLayer.startEditing()
self.inputLayer.beginEditCommand( QString( "Densify line(s)" ) )
if self.useSelection:
selection = self.inputLayer.selectedFeatures()
self.emit( SIGNAL( "rangeCalculated( PyQt_PyObject )" ), len( selection ) )
for f in selection:
featureId = f.id()
featGeometry = QgsGeometry( f.geometry() )
newGeometry = densifyGeometry( featGeometry, self.tolerance, isPolygon )
self.inputLayer.changeGeometry( featureId, newGeometry )
self.emit( SIGNAL( "featureProcessed()" ) )
self.mutex.lock()
s = self.stopMe
self.mutex.unlock()
if s == 1:
interrupted = True
break
else:
vProvider = self.inputLayer.dataProvider()
self.emit( SIGNAL( "rangeCalculated( PyQt_PyObject )" ), vProvider.featureCount() )
f = QgsFeature()
while vProvider.nextFeature( f ):
featureId = f.id()
featGeometry = QgsGeometry( f.geometry() )
newGeometry = densifyGeometry( featGeometry, self.tolerance, isPolygon )
self.inputLayer.changeGeometry( featureId, newGeometry )
self.emit( SIGNAL( "featureProcessed()" ) )
self.mutex.lock()
s = self.stopMe
self.mutex.unlock()
if s == 1:
interrupted = True
break
# cleanup
if self.inputLayer.isEditable():
self.inputLayer.endEditCommand()
if shapeFileWriter != None:
del shapeFileWriter
if not interrupted:
self.emit( SIGNAL( "processingFinished( PyQt_PyObject )" ), None )
else:
self.emit( SIGNAL( "processingInterrupted()" ) )
def stop( self ): def stop( self ):
self.mutex.lock() self.mutex.lock()

View File

@ -2,9 +2,6 @@
<ui version="4.0"> <ui version="4.0">
<class>Dialog</class> <class>Dialog</class>
<widget class="QDialog" name="Dialog"> <widget class="QDialog" name="Dialog">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
@ -35,7 +32,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="useSelectionCheck"> <widget class="QCheckBox" name="chkUseSelection">
<property name="text"> <property name="text">
<string>Use only selected features</string> <string>Use only selected features</string>
</property> </property>
@ -44,14 +41,14 @@
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<item> <item>
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="lblTolerance">
<property name="text"> <property name="text">
<string>Simplify tolerance</string> <string>Simplify tolerance</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QDoubleSpinBox" name="toleranceSpin"> <widget class="QDoubleSpinBox" name="spnTolerance">
<property name="decimals"> <property name="decimals">
<number>4</number> <number>4</number>
</property> </property>
@ -71,14 +68,14 @@
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<widget class="QCheckBox" name="writeShapefileCheck"> <widget class="QCheckBox" name="chkWriteShapefile">
<property name="text"> <property name="text">
<string>Save to new file</string> <string>Save to new file</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="outputFileEdit"> <widget class="QLineEdit" name="edOutputFile">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -97,7 +94,7 @@
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="addToCanvasCheck"> <widget class="QCheckBox" name="chkAddToCanvas">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>