mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Merge branch 'master' of github.com:qgis/Quantum-GIS
This commit is contained in:
commit
6274cd112f
0
python/plugins/fTools/__init__.py
Executable file → Normal file
0
python/plugins/fTools/__init__.py
Executable file → Normal file
32
python/plugins/fTools/fTools.py
Executable file → Normal file
32
python/plugins/fTools/fTools.py
Executable file → Normal file
@ -43,7 +43,7 @@ import doGeometry, doGeoprocessing, doVisual
|
||||
import doIntersectLines, doSelectByLocation, doVectorSplit, doMeanCoords
|
||||
import doPointDistance, doPointsInPolygon, doRandom, doRandPoints, doRegPoints
|
||||
import doSpatialJoin, doSubsetSelect, doSumLines, doVectorGrid, doMergeShapes
|
||||
import doValidate, doSimplify, doDefineProj
|
||||
import doValidate, doSimplify, doDefineProj, doSpatialIndex
|
||||
|
||||
class fToolsPlugin:
|
||||
def __init__(self,iface):
|
||||
@ -103,6 +103,7 @@ class fToolsPlugin:
|
||||
self.voronoi.setIcon(QIcon(self.getThemeIcon("voronoi.png")))
|
||||
self.extNodes.setIcon(QIcon(self.getThemeIcon("extract_nodes.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.singleToMulti.setIcon(QIcon(self.getThemeIcon("single_to_multi.png")))
|
||||
self.polysToLines.setIcon(QIcon(self.getThemeIcon("to_lines.png")))
|
||||
@ -113,6 +114,7 @@ class fToolsPlugin:
|
||||
self.spatJoin.setIcon(QIcon(self.getThemeIcon("join_location.png")))
|
||||
self.splitVect.setIcon(QIcon(self.getThemeIcon("split_layer.png")))
|
||||
self.mergeShapes.setIcon(QIcon(self.getThemeIcon("merge_shapes.png")))
|
||||
self.spatialIndex.setIcon(QIcon(self.getThemeIcon("spatial_index.png")))
|
||||
|
||||
def initGui(self):
|
||||
if int(self.QgisVersion) < 1:
|
||||
@ -167,19 +169,22 @@ class fToolsPlugin:
|
||||
self.voronoi = QAction(QCoreApplication.translate("fTools", "Voronoi Polygons"),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.densify = QAction(QCoreApplication.translate("fTools", "Densify geometries"),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.polysToLines = QAction(QCoreApplication.translate("fTools", "Polygons to lines"),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.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.define = QAction(QCoreApplication.translate("fTools", "Define current projection"), self.iface.mainWindow())
|
||||
self.spatJoin = QAction(QCoreApplication.translate("fTools", "Join attributes by location"), self.iface.mainWindow())
|
||||
self.splitVect = QAction(QCoreApplication.translate("fTools", "Split vector layer"), self.iface.mainWindow())
|
||||
self.mergeShapes = QAction(QCoreApplication.translate("fTools", "Merge shapefiles to one"), self.iface.mainWindow())
|
||||
self.dataManageMenu.addActions([self.define, self.spatJoin, self.splitVect, self.mergeShapes])
|
||||
self.spatialIndex = QAction(QCoreApplication.translate("fTools", "Create spatial index"), self.iface.mainWindow())
|
||||
self.dataManageMenu.addActions([self.define, self.spatJoin, self.splitVect, self.mergeShapes, self.spatialIndex])
|
||||
self.updateThemeIcons("theme")
|
||||
|
||||
self.menu.addMenu(self.analysisMenu)
|
||||
@ -222,7 +227,8 @@ class fToolsPlugin:
|
||||
QObject.connect(self.multiToSingle, SIGNAL("triggered()"), self.domultiToSingle)
|
||||
QObject.connect(self.singleToMulti, SIGNAL("triggered()"), self.dosingleToMulti)
|
||||
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.delaunay, SIGNAL("triggered()"), self.dodelaunay)
|
||||
QObject.connect(self.voronoi, SIGNAL("triggered()"), self.dovoronoi)
|
||||
@ -235,12 +241,19 @@ class fToolsPlugin:
|
||||
QObject.connect(self.spatJoin, SIGNAL("triggered()"), self.dospatJoin)
|
||||
QObject.connect(self.splitVect, SIGNAL("triggered()"), self.dosplitVect)
|
||||
QObject.connect(self.mergeShapes, SIGNAL("triggered()"), self.doMergeShapes)
|
||||
QObject.connect(self.spatialIndex, SIGNAL("triggered()"), self.doSpatIndex)
|
||||
|
||||
def unload(self):
|
||||
pass
|
||||
|
||||
def dosimplify(self):
|
||||
d = doSimplify.Dialog(self.iface)
|
||||
def doSimplify(self):
|
||||
d = doSimplify.Dialog(self.iface, 1)
|
||||
d.show()
|
||||
d.exec_()
|
||||
|
||||
def doDensify(self):
|
||||
d = doSimplify.Dialog(self.iface, 2)
|
||||
d.show()
|
||||
d.exec_()
|
||||
|
||||
def dopolysToLines(self):
|
||||
@ -319,7 +332,7 @@ class fToolsPlugin:
|
||||
def dodelaunay(self):
|
||||
d = doGeometry.GeometryDialog(self.iface, 8)
|
||||
d.exec_()
|
||||
|
||||
|
||||
def dovoronoi(self):
|
||||
d = doGeometry.GeometryDialog(self.iface, 10)
|
||||
d.exec_()
|
||||
@ -390,5 +403,10 @@ class fToolsPlugin:
|
||||
|
||||
def doMergeShapes(self):
|
||||
d = doMergeShapes.Dialog(self.iface)
|
||||
d.show()
|
||||
d.exec_()
|
||||
|
||||
def doSpatIndex(self):
|
||||
d = doSpatialIndex.Dialog(self.iface)
|
||||
d.show()
|
||||
d.exec_()
|
||||
|
0
python/plugins/fTools/tools/doDefineProj.py
Executable file → Normal file
0
python/plugins/fTools/tools/doDefineProj.py
Executable file → Normal file
6
python/plugins/fTools/tools/doGeometry.py
Executable file → Normal file
6
python/plugins/fTools/tools/doGeometry.py
Executable file → Normal file
@ -161,7 +161,9 @@ class GeometryDialog(QDialog, Ui_Dialog):
|
||||
self.cmbField.setVisible( False )
|
||||
self.field_label.setVisible( False )
|
||||
self.resize( 381, 100 )
|
||||
myList = []
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
self.inShape.clear()
|
||||
if self.myFunction == 3 or self.myFunction == 6:
|
||||
myList = ftools_utils.getLayerNames( [ QGis.Polygon, QGis.Line ] )
|
||||
@ -176,7 +178,6 @@ class GeometryDialog(QDialog, Ui_Dialog):
|
||||
else:
|
||||
myList = ftools_utils.getLayerNames( [ QGis.Point, QGis.Line, QGis.Polygon ] )
|
||||
self.inShape.addItems( myList )
|
||||
return
|
||||
|
||||
#1: Singleparts to multipart
|
||||
#2: Multipart to singleparts
|
||||
@ -241,6 +242,7 @@ class GeometryDialog(QDialog, Ui_Dialog):
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
if not ftools_utils.addShapeToCanvas( unicode( self.shapefileName ) ):
|
||||
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( self.shapefileName ) ))
|
||||
self.populateLayers()
|
||||
else:
|
||||
QMessageBox.warning( self, self.tr("Geometry"), self.tr( "Error writing output shapefile." ) )
|
||||
|
||||
|
9
python/plugins/fTools/tools/doGeoprocessing.py
Executable file → Normal file
9
python/plugins/fTools/tools/doGeoprocessing.py
Executable file → Normal file
@ -182,6 +182,9 @@ class GeoprocessingDialog( QDialog, Ui_Dialog ):
|
||||
self.label_2.setText( self.tr( "Union layer" ) )
|
||||
self.setWindowTitle( self.tr( "Union" ) )
|
||||
self.resize(381, 100)
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
myListA = []
|
||||
myListB = []
|
||||
self.inShapeA.clear()
|
||||
@ -195,7 +198,6 @@ class GeoprocessingDialog( QDialog, Ui_Dialog ):
|
||||
myListB = ftools_utils.getLayerNames( [ QGis.Point, QGis.Line, QGis.Polygon ] )
|
||||
self.inShapeA.addItems( myListA )
|
||||
self.inShapeB.addItems( myListB )
|
||||
return
|
||||
|
||||
#1: Buffer
|
||||
#2: Convex Hull
|
||||
@ -257,6 +259,7 @@ class GeoprocessingDialog( QDialog, Ui_Dialog ):
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
if not ftools_utils.addShapeToCanvas( unicode( self.shapefileName ) ):
|
||||
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( self.shapefileName ) ))
|
||||
self.populateLayers()
|
||||
|
||||
def runStatusFromThread( self, status ):
|
||||
self.progressBar.setValue( status )
|
||||
@ -1103,7 +1106,7 @@ class geoprocessingThread( QThread ):
|
||||
writer.addFeature( outFeat )
|
||||
except:
|
||||
FEATURE_EXCEPT = False
|
||||
# this really shouldn't happen, as we
|
||||
# this really shouldn't happen, as we
|
||||
# haven't edited the input geom at all
|
||||
# continue
|
||||
else:
|
||||
@ -1144,7 +1147,7 @@ class geoprocessingThread( QThread ):
|
||||
# print str(err)
|
||||
FEATURE_EXCEPT = False
|
||||
# else:
|
||||
# # this only happends if the bounding box
|
||||
# # this only happends if the bounding box
|
||||
# # intersects, but the geometry doesn't
|
||||
# try:
|
||||
# outFeat.setGeometry( geom )
|
||||
|
8
python/plugins/fTools/tools/doIntersectLines.py
Executable file → Normal file
8
python/plugins/fTools/tools/doIntersectLines.py
Executable file → Normal file
@ -46,10 +46,13 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
QObject.connect(self.inLine2, SIGNAL("currentIndexChanged(QString)"), self.update2)
|
||||
self.setWindowTitle( self.tr("Line intersections") )
|
||||
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
|
||||
# populate layer list
|
||||
self.progressBar.setValue(0)
|
||||
mapCanvas = self.iface.mapCanvas()
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
layers = ftools_utils.getLayerNames([QGis.Line])
|
||||
self.inLine1.clear()
|
||||
self.inLine2.clear()
|
||||
self.inLine1.addItems(layers)
|
||||
self.inLine2.addItems(layers)
|
||||
|
||||
@ -92,6 +95,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
if not ftools_utils.addShapeToCanvas( unicode( outPath ) ):
|
||||
QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( outPath ) ))
|
||||
self.populateLayers()
|
||||
self.progressBar.setValue(0)
|
||||
self.buttonOk.setEnabled( True )
|
||||
|
||||
|
10
python/plugins/fTools/tools/doMeanCoords.py
Executable file → Normal file
10
python/plugins/fTools/tools/doMeanCoords.py
Executable file → Normal file
@ -45,12 +45,15 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
|
||||
QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
|
||||
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
|
||||
|
||||
# populate layer list
|
||||
self.progressBar.setValue(0)
|
||||
mapCanvas = self.iface.mapCanvas()
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon])
|
||||
QObject.disconnect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
|
||||
self.inShape.clear()
|
||||
self.inShape.addItems(layers)
|
||||
QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
|
||||
|
||||
def updateUi(self):
|
||||
if self.function == 1:
|
||||
@ -96,6 +99,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
|
||||
QgsMapLayerRegistry.instance().addMapLayer(vlayer)
|
||||
self.populateLayers()
|
||||
self.progressBar.setValue(0)
|
||||
self.buttonOk.setEnabled( True )
|
||||
|
||||
|
0
python/plugins/fTools/tools/doMergeShapes.py
Executable file → Normal file
0
python/plugins/fTools/tools/doMergeShapes.py
Executable file → Normal file
0
python/plugins/fTools/tools/doPointDistance.py
Executable file → Normal file
0
python/plugins/fTools/tools/doPointDistance.py
Executable file → Normal file
12
python/plugins/fTools/tools/doPointsInPolygon.py
Executable file → Normal file
12
python/plugins/fTools/tools/doPointsInPolygon.py
Executable file → Normal file
@ -44,14 +44,18 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
|
||||
self.setWindowTitle(self.tr("Count Points in Polygon"))
|
||||
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
|
||||
# populate layer list
|
||||
self.progressBar.setValue(0)
|
||||
mapCanvas = self.iface.mapCanvas()
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
layers = ftools_utils.getLayerNames([QGis.Polygon])
|
||||
self.inPolygon.clear()
|
||||
self.inPolygon.addItems(layers)
|
||||
|
||||
self.inPoint.clear()
|
||||
layers = ftools_utils.getLayerNames([QGis.Point])
|
||||
self.inPoint.addItems(layers)
|
||||
|
||||
|
||||
def accept(self):
|
||||
self.buttonOk.setEnabled( False )
|
||||
if self.inPolygon.currentText() == "":
|
||||
@ -79,6 +83,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
|
||||
QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
|
||||
self.populateLayers()
|
||||
self.progressBar.setValue(0)
|
||||
self.buttonOk.setEnabled( True )
|
||||
|
||||
@ -112,7 +117,6 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
if not QgsVectorFileWriter.deleteShapeFile(self.shapefileName):
|
||||
return
|
||||
writer = QgsVectorFileWriter(self.shapefileName, self.encoding, fieldList, polyProvider.geometryType(), sRs)
|
||||
#writer = QgsVectorFileWriter(outPath, "UTF-8", fieldList, polyProvider.geometryType(), sRs)
|
||||
inFeat = QgsFeature()
|
||||
inFeatB = QgsFeature()
|
||||
outFeat = QgsFeature()
|
||||
|
10
python/plugins/fTools/tools/doRandPoints.py
Executable file → Normal file
10
python/plugins/fTools/tools/doRandPoints.py
Executable file → Normal file
@ -46,9 +46,14 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
self.progressBar.setValue(0)
|
||||
self.setWindowTitle(self.tr("Random Points"))
|
||||
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
|
||||
self.mapCanvas = self.iface.mapCanvas()
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
layers = ftools_utils.getLayerNames([QGis.Polygon, "Raster"])
|
||||
QObject.disconnect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
|
||||
self.inShape.clear()
|
||||
self.inShape.addItems(layers)
|
||||
QObject.connect(self.inShape, SIGNAL("currentIndexChanged(QString)"), self.update)
|
||||
|
||||
# If input layer is changed, update field list
|
||||
def update(self, inputLayer):
|
||||
@ -123,6 +128,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
|
||||
QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
|
||||
self.populateLayers()
|
||||
self.progressBar.setValue(0)
|
||||
self.buttonOk.setEnabled( True )
|
||||
|
||||
@ -208,7 +214,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
points = self.vectorRandom(int(value), inLayer,
|
||||
ext.xMinimum(), ext.xMaximum(), ext.yMinimum(), ext.yMaximum())
|
||||
else: points = self.loopThruPolygons(inLayer, value, design)
|
||||
crs = self.mapCanvas.mapRenderer().destinationSrs()
|
||||
crs = self.iface.mapCanvas().mapRenderer().destinationSrs()
|
||||
if not crs.isValid(): crs = None
|
||||
fields = { 0 : QgsField("ID", QVariant.Int) }
|
||||
check = QFile(self.shapefileName)
|
||||
|
0
python/plugins/fTools/tools/doRandom.py
Executable file → Normal file
0
python/plugins/fTools/tools/doRandom.py
Executable file → Normal file
9
python/plugins/fTools/tools/doRegPoints.py
Executable file → Normal file
9
python/plugins/fTools/tools/doRegPoints.py
Executable file → Normal file
@ -50,7 +50,11 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
|
||||
self.progressBar.setValue(0)
|
||||
self.mapCanvas = self.iface.mapCanvas()
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
layers = ftools_utils.getLayerNames("all")
|
||||
self.inShape.clear()
|
||||
self.inShape.addItems(layers)
|
||||
|
||||
def accept(self):
|
||||
@ -89,6 +93,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
|
||||
QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
|
||||
self.populateLayers()
|
||||
self.progressBar.setValue(0)
|
||||
self.buttonOk.setEnabled( True )
|
||||
|
||||
@ -98,7 +103,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
if self.shapefileName is None or self.encoding is None:
|
||||
return
|
||||
self.outShape.setText( QString( self.shapefileName ) )
|
||||
|
||||
|
||||
# Generate list of random points
|
||||
def simpleRandom(self, n, bound, xmin, xmax, ymin, ymax):
|
||||
seed()
|
||||
@ -109,7 +114,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
if pGeom.intersects(bound):
|
||||
points.append(pGeom)
|
||||
i = i + 1
|
||||
return points
|
||||
return points
|
||||
|
||||
def regularize(self, bound, outPath, offset, value, gridType, inset, crs):
|
||||
area = bound.width() * bound.height()
|
||||
|
0
python/plugins/fTools/tools/doSelectByLocation.py
Executable file → Normal file
0
python/plugins/fTools/tools/doSelectByLocation.py
Executable file → Normal file
@ -39,109 +39,127 @@ import ftools_utils
|
||||
from ui_frmSimplify import Ui_Dialog
|
||||
|
||||
class Dialog( QDialog, Ui_Dialog ):
|
||||
def __init__( self, iface ):
|
||||
def __init__( self, iface, function ):
|
||||
QDialog.__init__( self )
|
||||
self.setupUi( self )
|
||||
self.iface = iface
|
||||
self.myFunction = function
|
||||
|
||||
self.simplifyThread = None
|
||||
self.workThread = None
|
||||
|
||||
self.okButton = self.buttonBox.button( QDialogButtonBox.Ok )
|
||||
self.closeButton = self.buttonBox.button( QDialogButtonBox.Close )
|
||||
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 )
|
||||
|
||||
QObject.connect( self.writeShapefileCheck, SIGNAL( "stateChanged( int )" ), self.updateGui )
|
||||
self.btnOk = self.buttonBox.button( QDialogButtonBox.Ok )
|
||||
self.btnClose = self.buttonBox.button( QDialogButtonBox.Close )
|
||||
|
||||
QObject.connect( self.chkWriteShapefile, SIGNAL( "stateChanged( int )" ), self.updateGui )
|
||||
QObject.connect( self.btnSelectOutputFile, SIGNAL( "clicked()" ), self.selectOutputFile )
|
||||
|
||||
self.manageGui()
|
||||
self.populateLayers()
|
||||
|
||||
def manageGui( self ):
|
||||
def populateLayers( self ):
|
||||
layers = ftools_utils.getLayerNames( [ QGis.Polygon, QGis.Line ] )
|
||||
self.cmbInputLayer.clear()
|
||||
self.cmbInputLayer.addItems( layers )
|
||||
|
||||
def updateGui( self ):
|
||||
if self.writeShapefileCheck.isChecked():
|
||||
self.outputFileEdit.setEnabled( True )
|
||||
if self.chkWriteShapefile.isChecked():
|
||||
self.edOutputFile.setEnabled( True )
|
||||
self.btnSelectOutputFile.setEnabled( True )
|
||||
self.addToCanvasCheck.setEnabled( True )
|
||||
self.chkAddToCanvas.setEnabled( True )
|
||||
else:
|
||||
self.outputFileEdit.setEnabled( False )
|
||||
self.edOutputFile.setEnabled( False )
|
||||
self.btnSelectOutputFile.setEnabled( False )
|
||||
self.addToCanvasCheck.setEnabled( False )
|
||||
self.chkAddToCanvas.setEnabled( False )
|
||||
|
||||
self.encoding = None
|
||||
|
||||
def selectOutputFile( self ):
|
||||
self.outputFileEdit.clear()
|
||||
(self.shapefileName, self.encoding) = ftools_utils.saveDialog(self)
|
||||
if self.shapefileName is None or self.encoding is None:
|
||||
self.edOutputFile.clear()
|
||||
( self.shapeFileName, self.encoding ) = ftools_utils.saveDialog( self )
|
||||
if self.shapeFileName is None or self.encoding is None:
|
||||
return
|
||||
self.outputFileEdit.setText(QString(self.shapefileName))
|
||||
self.edOutputFile.setText( QString( self.shapeFileName ) )
|
||||
|
||||
def accept( self ):
|
||||
vLayer = ftools_utils.getVectorLayerByName( self.cmbInputLayer.currentText() )
|
||||
|
||||
QApplication.setOverrideCursor( Qt.WaitCursor )
|
||||
self.okButton.setEnabled( False )
|
||||
self.btnOk.setEnabled( False )
|
||||
|
||||
if self.writeShapefileCheck.isChecked():
|
||||
outFileName = self.outputFileEdit.text()
|
||||
if self.chkWriteShapefile.isChecked():
|
||||
outFileName = self.edOutputFile.text()
|
||||
outFile = QFile( outFileName )
|
||||
if outFile.exists():
|
||||
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
|
||||
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:
|
||||
self.simplifyThread = GeneralizationThread( vLayer, self.useSelectionCheck.isChecked(), self.toleranceSpin.value(), False, None, None )
|
||||
QObject.connect( self.simplifyThread, SIGNAL( "rangeCalculated( PyQt_PyObject )" ), self.setProgressRange )
|
||||
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.workThread = GeomThread( self.myFunction, vLayer, self.chkUseSelection.isChecked(),
|
||||
self.spnTolerance.value(), False, None, None )
|
||||
|
||||
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.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 ):
|
||||
self.progressBar.setRange( 0, max )
|
||||
def setProgressRange( self, maximum ):
|
||||
self.progressBar.setRange( 0, maximum )
|
||||
|
||||
def featureProcessed( self ):
|
||||
self.progressBar.setValue( self.progressBar.value() + 1 )
|
||||
|
||||
def generalizationFinished( self, pointsCount ):
|
||||
def processFinished( self, pointsCount ):
|
||||
self.stopProcessing()
|
||||
|
||||
QMessageBox.information( self,
|
||||
self.tr( "Simplify results" ),
|
||||
self.tr( "There were %1 vertices in original dataset which\nwere reduced to %2 vertices after simplification" )
|
||||
.arg( pointsCount[ 0 ] )
|
||||
.arg( pointsCount[ 1 ] ) )
|
||||
if self.myFunction == 1:
|
||||
QMessageBox.information( self, self.tr( "Simplify results" ),
|
||||
self.tr( "There were %1 vertices in original dataset which\nwere reduced to %2 vertices after simplification" )
|
||||
.arg( pointsCount[ 0 ] )
|
||||
.arg( pointsCount[ 1 ] ) )
|
||||
|
||||
self.restoreGui()
|
||||
if self.addToCanvasCheck.isEnabled() and self.addToCanvasCheck.isChecked():
|
||||
if not ftools_utils.addShapeToCanvas( unicode( self.shapefileName ) ):
|
||||
QMessageBox.warning( self, self.tr( "Merging" ),
|
||||
|
||||
if self.chkAddToCanvas.isEnabled() and self.chkAddToCanvas.isChecked():
|
||||
if not ftools_utils.addShapeToCanvas( unicode( self.shapeFileName ) ):
|
||||
QMessageBox.warning( self, self.tr( "Error" ),
|
||||
self.tr( "Error loading output shapefile:\n%1" )
|
||||
.arg( unicode( self.shapefileName ) ) )
|
||||
.arg( unicode( self.shapeFileName ) ) )
|
||||
self.populateLayers()
|
||||
|
||||
QMessageBox.information( self, self.tr( "Finished" ), self.tr( "Processing completed." ) )
|
||||
self.iface.mapCanvas().refresh()
|
||||
#self.restoreGui()
|
||||
|
||||
def generalizationInterrupted( self ):
|
||||
def processInterrupted( self ):
|
||||
self.restoreGui()
|
||||
|
||||
def stopProcessing( self ):
|
||||
if self.simplifyThread != None:
|
||||
self.simplifyThread.stop()
|
||||
self.simplifyThread = None
|
||||
if self.workThread != None:
|
||||
self.workThread.stop()
|
||||
self.workThread = None
|
||||
|
||||
def restoreGui( self ):
|
||||
self.progressBar.setValue( 0 )
|
||||
QApplication.restoreOverrideCursor()
|
||||
QObject.connect( self.buttonBox, SIGNAL( "rejected()" ), self.reject )
|
||||
self.closeButton.setText( self.tr( "Close" ) )
|
||||
self.okButton.setEnabled( True )
|
||||
self.btnClose.setText( self.tr( "Close" ) )
|
||||
self.btnOk.setEnabled( True )
|
||||
|
||||
def geomVertexCount( geometry ):
|
||||
geomType = geometry.type()
|
||||
@ -157,8 +175,41 @@ def geomVertexCount( geometry ):
|
||||
else:
|
||||
return None
|
||||
|
||||
class GeneralizationThread( QThread ):
|
||||
def __init__( self, inputLayer, useSelection, tolerance, writeShape, shapePath, shapeEncoding ):
|
||||
def densify( polyline, pointsNumber ):
|
||||
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() )
|
||||
self.inputLayer = inputLayer
|
||||
self.useSelection = useSelection
|
||||
@ -166,15 +217,18 @@ class GeneralizationThread( QThread ):
|
||||
self.writeShape = writeShape
|
||||
self.outputFileName = shapePath
|
||||
self.outputEncoding = shapeEncoding
|
||||
|
||||
self.shapeFileWriter = None
|
||||
self.pointsBefore = 0
|
||||
self.pointsAfter = 0
|
||||
self.myFunction = function
|
||||
|
||||
self.mutex = QMutex()
|
||||
self.stopMe = 0
|
||||
|
||||
def run( self ):
|
||||
if self.myFunction == 1:
|
||||
self.runSimplify()
|
||||
else:
|
||||
self.runDensify()
|
||||
|
||||
def runSimplify( self ):
|
||||
self.mutex.lock()
|
||||
self.stopMe = 0
|
||||
self.mutex.unlock()
|
||||
@ -183,6 +237,9 @@ class GeneralizationThread( QThread ):
|
||||
|
||||
shapeFileWriter = None
|
||||
|
||||
pointsBefore = 0
|
||||
pointsAfter = 0
|
||||
|
||||
if self.writeShape:
|
||||
vProvider = self.inputLayer.dataProvider()
|
||||
allAttrs = vProvider.attributeIndexes()
|
||||
@ -200,9 +257,11 @@ class GeneralizationThread( QThread ):
|
||||
for f in selection:
|
||||
featGeometry = QgsGeometry( f.geometry() )
|
||||
attrMap = f.attributeMap()
|
||||
self.pointsBefore += geomVertexCount( featGeometry )
|
||||
|
||||
pointsBefore += geomVertexCount( featGeometry )
|
||||
newGeometry = featGeometry.simplify( self.tolerance )
|
||||
self.pointsAfter += geomVertexCount( newGeometry )
|
||||
pointsAfter += geomVertexCount( newGeometry )
|
||||
|
||||
feature = QgsFeature()
|
||||
feature.setGeometry( newGeometry )
|
||||
feature.setAttributeMap( attrMap )
|
||||
@ -222,9 +281,11 @@ class GeneralizationThread( QThread ):
|
||||
while vProvider.nextFeature( f ):
|
||||
featGeometry = QgsGeometry( f.geometry() )
|
||||
attrMap = f.attributeMap()
|
||||
self.pointsBefore += geomVertexCount( featGeometry )
|
||||
|
||||
pointsBefore += geomVertexCount( featGeometry )
|
||||
newGeometry = featGeometry.simplify( self.tolerance )
|
||||
self.pointsAfter += geomVertexCount( newGeometry )
|
||||
pointsAfter += geomVertexCount( newGeometry )
|
||||
|
||||
feature = QgsFeature()
|
||||
feature.setGeometry( newGeometry )
|
||||
feature.setAttributeMap( attrMap )
|
||||
@ -248,9 +309,11 @@ class GeneralizationThread( QThread ):
|
||||
for f in selection:
|
||||
featureId = f.id()
|
||||
featGeometry = QgsGeometry( f.geometry() )
|
||||
self.pointsBefore += geomVertexCount( featGeometry )
|
||||
|
||||
pointsBefore += geomVertexCount( featGeometry )
|
||||
newGeometry = featGeometry.simplify( self.tolerance )
|
||||
self.pointsAfter += geomVertexCount( newGeometry )
|
||||
pointsAfter += geomVertexCount( newGeometry )
|
||||
|
||||
self.inputLayer.changeGeometry( featureId, newGeometry )
|
||||
self.emit( SIGNAL( "featureProcessed()" ) )
|
||||
|
||||
@ -267,9 +330,11 @@ class GeneralizationThread( QThread ):
|
||||
while vProvider.nextFeature( f ):
|
||||
featureId = f.id()
|
||||
featGeometry = QgsGeometry( f.geometry() )
|
||||
self.pointsBefore += geomVertexCount( featGeometry )
|
||||
|
||||
pointsBefore += geomVertexCount( featGeometry )
|
||||
newGeometry = featGeometry.simplify( self.tolerance )
|
||||
self.pointsAfter += geomVertexCount( newGeometry )
|
||||
pointsAfter += geomVertexCount( newGeometry )
|
||||
|
||||
self.inputLayer.changeGeometry( featureId, newGeometry )
|
||||
self.emit( SIGNAL( "featureProcessed()" ) )
|
||||
|
||||
@ -288,9 +353,129 @@ class GeneralizationThread( QThread ):
|
||||
del shapeFileWriter
|
||||
|
||||
if not interrupted:
|
||||
self.emit( SIGNAL( "generalizationFinished( PyQt_PyObject )" ), ( self.pointsBefore, self.pointsAfter ) )
|
||||
self.emit( SIGNAL( "processingFinished( PyQt_PyObject )" ), ( pointsBefore, pointsAfter ) )
|
||||
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 ):
|
||||
self.mutex.lock()
|
||||
|
223
python/plugins/fTools/tools/doSpatialIndex.py
Normal file
223
python/plugins/fTools/tools/doSpatialIndex.py
Normal file
@ -0,0 +1,223 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
doSpatialIndex.py - build spatial index for vector layers or files
|
||||
--------------------------------------
|
||||
Date : 11-Nov-2011
|
||||
Copyright : (C) 2011 by Alexander Bruy
|
||||
Email : alexander dot bruy 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. *
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
|
||||
from PyQt4.QtCore import *
|
||||
from PyQt4.QtGui import *
|
||||
|
||||
from qgis.core import *
|
||||
from qgis.gui import *
|
||||
|
||||
import ftools_utils
|
||||
|
||||
from ui_frmSpatialIndex import Ui_Dialog
|
||||
|
||||
class Dialog( QDialog, Ui_Dialog ):
|
||||
def __init__( self, iface ):
|
||||
QDialog.__init__( self )
|
||||
self.setupUi( self )
|
||||
self.iface = iface
|
||||
|
||||
self.workThread = None
|
||||
|
||||
self.btnOk = self.buttonBox.button( QDialogButtonBox.Ok )
|
||||
self.btnClose = self.buttonBox.button( QDialogButtonBox.Close )
|
||||
|
||||
QObject.connect( self.chkExternalFiles, SIGNAL( "stateChanged( int )" ), self.toggleExternalFiles )
|
||||
QObject.connect( self.btnSelectFiles, SIGNAL( "clicked()" ), self.selectFiles )
|
||||
QObject.connect( self.lstLayers, SIGNAL( "itemSelectionChanged()" ), self.updateLayerList )
|
||||
QObject.connect( self.btnSelectAll, SIGNAL( "clicked()" ), self.selectAll )
|
||||
QObject.connect( self.btnSelectNone, SIGNAL( "clicked()" ), self.selectNone )
|
||||
QObject.connect( self.btnClearList, SIGNAL( "clicked()" ), self.clearList )
|
||||
|
||||
self.manageGui()
|
||||
|
||||
def manageGui( self ):
|
||||
self.btnSelectFiles.setEnabled( False )
|
||||
self.btnClearList.setEnabled( False )
|
||||
|
||||
self.fillLayersList()
|
||||
|
||||
def fillLayersList( self ):
|
||||
self.lstLayers.clear()
|
||||
layers = ftools_utils.getLayerNames( [ QGis.Line, QGis.Point, QGis.Polygon ] )
|
||||
for lay in layers:
|
||||
source = ftools_utils.getVectorLayerByName( lay ).source()
|
||||
item = QListWidgetItem( lay, self.lstLayers )
|
||||
item.setData( Qt.UserRole, source )
|
||||
item.setData( Qt.ToolTipRole, source )
|
||||
|
||||
def toggleExternalFiles( self ):
|
||||
if self.chkExternalFiles.isChecked():
|
||||
self.btnSelectFiles.setEnabled( True )
|
||||
self.btnClearList.setEnabled( True )
|
||||
self.btnSelectAll.setEnabled( False )
|
||||
self.btnSelectNone.setEnabled( False )
|
||||
|
||||
self.lstLayers.clear()
|
||||
self.lstLayers.setSelectionMode( QAbstractItemView.NoSelection )
|
||||
self.layers = []
|
||||
else:
|
||||
self.btnSelectFiles.setEnabled( False )
|
||||
self.btnClearList.setEnabled( False )
|
||||
self.btnSelectAll.setEnabled( True )
|
||||
self.btnSelectNone.setEnabled( True )
|
||||
|
||||
self.fillLayersList()
|
||||
self.lstLayers.setSelectionMode( QAbstractItemView.ExtendedSelection )
|
||||
self.updateLayerList()
|
||||
|
||||
def updateLayerList( self ):
|
||||
self.layers = []
|
||||
selection = self.lstLayers.selectedItems()
|
||||
for item in selection:
|
||||
self.layers.append( item.text() )
|
||||
|
||||
def selectFiles( self ):
|
||||
filters = QgsProviderRegistry.instance().fileVectorFilters()
|
||||
( files, self.encoding ) = ftools_utils.openDialog( self, filtering = filters, dialogMode = "MultipleFiles" )
|
||||
if files is None:
|
||||
return
|
||||
|
||||
self.layers.extend( [ unicode( f ) for f in files ] )
|
||||
self.lstLayers.addItems( files )
|
||||
|
||||
def selectAll( self ):
|
||||
self.lstLayers.selectAll()
|
||||
|
||||
def selectNone( self ):
|
||||
self.lstLayers.clearSelection()
|
||||
|
||||
def clearList( self ):
|
||||
self.layers = []
|
||||
self.lstLayers.clear()
|
||||
|
||||
def accept( self ):
|
||||
QApplication.setOverrideCursor( Qt.WaitCursor )
|
||||
self.btnOk.setEnabled( False )
|
||||
|
||||
self.workThread = SpatialIdxThread( self.layers, self.chkExternalFiles.isChecked() )
|
||||
self.progressBar.setRange( 0, len( self.layers ) )
|
||||
|
||||
QObject.connect( self.workThread, SIGNAL( "layerProcessed()" ), self.layerProcessed )
|
||||
QObject.connect( self.workThread, SIGNAL( "processFinished( PyQt_PyObject )" ), self.processFinished )
|
||||
QObject.connect( self.workThread, SIGNAL( "processInterrupted()" ), self.processInterrupted )
|
||||
|
||||
self.btnClose.setText( self.tr( "Cancel" ) )
|
||||
QObject.disconnect( self.buttonBox, SIGNAL( "rejected()" ), self.reject )
|
||||
QObject.connect( self.btnClose, SIGNAL( "clicked()" ), self.stopProcessing )
|
||||
|
||||
self.workThread.start()
|
||||
|
||||
def layerProcessed( self ):
|
||||
self.progressBar.setValue( self.progressBar.value() + 1 )
|
||||
|
||||
def processInterrupted( self ):
|
||||
self.restoreGui()
|
||||
|
||||
def processFinished( self, errors ):
|
||||
self.stopProcessing()
|
||||
self.restoreGui()
|
||||
|
||||
if not errors.isEmpty():
|
||||
msg = QString( "Processing of the following layers/files ended with error:<br><br>" ).append( errors.join( "<br>" ) )
|
||||
QErrorMessage( self ).showMessage( msg )
|
||||
|
||||
QMessageBox.information( self, self.tr( "Finished" ), self.tr( "Processing completed." ) )
|
||||
|
||||
def stopProcessing( self ):
|
||||
if self.workThread != None:
|
||||
self.workThread.stop()
|
||||
self.workThread = None
|
||||
|
||||
def restoreGui( self ):
|
||||
self.progressBar.setValue( 0 )
|
||||
QApplication.restoreOverrideCursor()
|
||||
QObject.connect( self.buttonBox, SIGNAL( "rejected()" ), self.reject )
|
||||
self.btnClose.setText( self.tr( "Close" ) )
|
||||
self.btnOk.setEnabled( True )
|
||||
|
||||
if self.chkExternalFiles.isChecked():
|
||||
self.clearList()
|
||||
|
||||
class SpatialIdxThread( QThread ):
|
||||
def __init__( self, layers, isFiles ):
|
||||
QThread.__init__( self, QThread.currentThread() )
|
||||
self.layers = layers
|
||||
self.isFiles = isFiles
|
||||
|
||||
self.mutex = QMutex()
|
||||
self.stopMe = 0
|
||||
|
||||
self.errors = QStringList()
|
||||
|
||||
def run( self ):
|
||||
self.mutex.lock()
|
||||
self.stopMe = 0
|
||||
self.mutex.unlock()
|
||||
|
||||
interrupted = False
|
||||
|
||||
if self.isFiles:
|
||||
for layer in self.layers:
|
||||
vl = QgsVectorLayer( layer, "tmp", "ogr" )
|
||||
provider = vl.dataProvider()
|
||||
if provider.capabilities() & QgsVectorDataProvider.CreateSpatialIndex:
|
||||
if not provider.createSpatialIndex():
|
||||
self.errors.append( layer )
|
||||
else:
|
||||
self.errors.append( layer )
|
||||
|
||||
self.emit( SIGNAL( "layerProcessed()" ) )
|
||||
|
||||
self.mutex.lock()
|
||||
s = self.stopMe
|
||||
self.mutex.unlock()
|
||||
if s == 1:
|
||||
interrupted = True
|
||||
break
|
||||
else:
|
||||
for layer in self.layers:
|
||||
vl = ftools_utils.getVectorLayerByName( layer )
|
||||
provider = vl.dataProvider()
|
||||
if provider.capabilities() & QgsVectorDataProvider.CreateSpatialIndex:
|
||||
if not provider.createSpatialIndex():
|
||||
self.errors.append( layer )
|
||||
else:
|
||||
self.errors.append( layer )
|
||||
|
||||
self.emit( SIGNAL( "layerProcessed()" ) )
|
||||
|
||||
self.mutex.lock()
|
||||
s = self.stopMe
|
||||
self.mutex.unlock()
|
||||
if s == 1:
|
||||
interrupted = True
|
||||
break
|
||||
|
||||
if not interrupted:
|
||||
self.emit( SIGNAL( "processFinished( PyQt_PyObject )" ), self.errors )
|
||||
else:
|
||||
self.emit( SIGNAL( "processInterrupted()" ) )
|
||||
|
||||
def stop( self ):
|
||||
self.mutex.lock()
|
||||
self.stopMe = 1
|
||||
self.mutex.unlock()
|
||||
|
||||
QThread.wait( self )
|
0
python/plugins/fTools/tools/doSpatialJoin.py
Executable file → Normal file
0
python/plugins/fTools/tools/doSpatialJoin.py
Executable file → Normal file
0
python/plugins/fTools/tools/doSubsetSelect.py
Executable file → Normal file
0
python/plugins/fTools/tools/doSubsetSelect.py
Executable file → Normal file
10
python/plugins/fTools/tools/doSumLines.py
Executable file → Normal file
10
python/plugins/fTools/tools/doSumLines.py
Executable file → Normal file
@ -44,14 +44,17 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
QObject.connect(self.toolOut, SIGNAL("clicked()"), self.outFile)
|
||||
self.setWindowTitle(self.tr("Sum line lengths"))
|
||||
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
|
||||
# populate layer list
|
||||
self.progressBar.setValue(0)
|
||||
mapCanvas = self.iface.mapCanvas()
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
layers = ftools_utils.getLayerNames([QGis.Line])
|
||||
self.inPoint.clear()
|
||||
self.inPoint.addItems(layers)
|
||||
layers = ftools_utils.getLayerNames([QGis.Polygon])
|
||||
self.inPolygon.clear()
|
||||
self.inPolygon.addItems(layers)
|
||||
|
||||
|
||||
def accept(self):
|
||||
self.buttonOk.setEnabled( False )
|
||||
if self.inPolygon.currentText() == "":
|
||||
@ -79,6 +82,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
|
||||
QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)
|
||||
self.populateLayers()
|
||||
self.progressBar.setValue(0)
|
||||
self.buttonOk.setEnabled( True )
|
||||
|
||||
|
9
python/plugins/fTools/tools/doVectorGrid.py
Executable file → Normal file
9
python/plugins/fTools/tools/doVectorGrid.py
Executable file → Normal file
@ -50,6 +50,10 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
self.xMax.setValidator(QDoubleValidator(self.xMax))
|
||||
self.yMin.setValidator(QDoubleValidator(self.yMin))
|
||||
self.yMax.setValidator(QDoubleValidator(self.yMax))
|
||||
self.populateLayers()
|
||||
|
||||
def populateLayers( self ):
|
||||
self.inShape.clear()
|
||||
layermap = QgsMapLayerRegistry.instance().mapLayers()
|
||||
for name, layer in layermap.iteritems():
|
||||
self.inShape.addItem( unicode( layer.name() ) )
|
||||
@ -64,12 +68,12 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
mLayer = ftools_utils.getMapLayerByName( unicode( mLayerName ) )
|
||||
boundBox = mLayer.extent()
|
||||
self.updateExtents( boundBox )
|
||||
|
||||
|
||||
def updateCanvas( self ):
|
||||
canvas = self.iface.mapCanvas()
|
||||
boundBox = canvas.extent()
|
||||
self.updateExtents( boundBox )
|
||||
|
||||
|
||||
def updateExtents( self, boundBox ):
|
||||
self.xMin.setText( unicode( boundBox.xMinimum() ) )
|
||||
self.yMin.setText( unicode( boundBox.yMinimum() ) )
|
||||
@ -100,6 +104,7 @@ class Dialog(QDialog, Ui_Dialog):
|
||||
addToTOC = QMessageBox.question(self, self.tr("Generate Vector Grid"), self.tr("Created output shapefile:\n%1\n\nWould you like to add the new layer to the TOC?").arg(unicode(self.shapefileName)), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
|
||||
if addToTOC == QMessageBox.Yes:
|
||||
ftools_utils.addShapeToCanvas( self.shapefileName )
|
||||
self.populateLayers()
|
||||
self.progressBar.setValue( 0 )
|
||||
self.buttonOk.setEnabled( True )
|
||||
|
||||
|
0
python/plugins/fTools/tools/doVectorSplit.py
Executable file → Normal file
0
python/plugins/fTools/tools/doVectorSplit.py
Executable file → Normal file
0
python/plugins/fTools/tools/doVisual.py
Executable file → Normal file
0
python/plugins/fTools/tools/doVisual.py
Executable file → Normal file
@ -2,9 +2,6 @@
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::WindowModal</enum>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
@ -35,7 +32,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="useSelectionCheck">
|
||||
<widget class="QCheckBox" name="chkUseSelection">
|
||||
<property name="text">
|
||||
<string>Use only selected features</string>
|
||||
</property>
|
||||
@ -44,14 +41,14 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<widget class="QLabel" name="lblTolerance">
|
||||
<property name="text">
|
||||
<string>Simplify tolerance</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="toleranceSpin">
|
||||
<widget class="QDoubleSpinBox" name="spnTolerance">
|
||||
<property name="decimals">
|
||||
<number>4</number>
|
||||
</property>
|
||||
@ -71,14 +68,14 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="writeShapefileCheck">
|
||||
<widget class="QCheckBox" name="chkWriteShapefile">
|
||||
<property name="text">
|
||||
<string>Save to new file</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="outputFileEdit">
|
||||
<widget class="QLineEdit" name="edOutputFile">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
@ -97,7 +94,7 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="addToCanvasCheck">
|
||||
<widget class="QCheckBox" name="chkAddToCanvas">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
|
127
python/plugins/fTools/tools/frmSpatialIndex.ui
Normal file
127
python/plugins/fTools/tools/frmSpatialIndex.ui
Normal file
@ -0,0 +1,127 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>351</width>
|
||||
<height>272</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Build spatial index</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="chkExternalFiles">
|
||||
<property name="text">
|
||||
<string>Select files from disk</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSelectFiles">
|
||||
<property name="text">
|
||||
<string>Select files...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="lstLayers">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSelectAll">
|
||||
<property name="text">
|
||||
<string>Select all</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSelectNone">
|
||||
<property name="text">
|
||||
<string>Select none</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnClearList">
|
||||
<property name="text">
|
||||
<string>Clear list</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QProgressBar" name="progressBar">
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
0
python/plugins/fTools/tools/ftools_utils.py
Executable file → Normal file
0
python/plugins/fTools/tools/ftools_utils.py
Executable file → Normal file
0
python/plugins/fTools/tools/voronoi.py
Executable file → Normal file
0
python/plugins/fTools/tools/voronoi.py
Executable file → Normal file
@ -276,6 +276,7 @@ QList<QgsMapLayer*> QgsSLDParser::mapLayerFromStyle( const QString& layerName, c
|
||||
{
|
||||
QgsRenderer* r = rendererFromUserStyle( userStyleElement, v );
|
||||
v->setRenderer( r );
|
||||
v->setUsingRendererV2( false );
|
||||
labelSettingsFromUserStyle( userStyleElement, v );
|
||||
#ifdef DIAGRAMSERVER
|
||||
overlaysFromUserStyle( userStyleElement, v );
|
||||
@ -399,6 +400,7 @@ QList<QgsMapLayer*> QgsSLDParser::mapLayerFromStyle( const QString& layerName, c
|
||||
return resultList;
|
||||
}
|
||||
theVectorLayer->setRenderer( theRenderer );
|
||||
theVectorLayer->setUsingRendererV2( false );
|
||||
QgsDebugMsg( "Returning the vectorlayer" );
|
||||
setOpacityForLayer( userLayerElement, theVectorLayer );
|
||||
resultList.push_back( theVectorLayer );
|
||||
|
Loading…
x
Reference in New Issue
Block a user