Skip to content
Permalink
Browse files
Merge branch 'master' of github.com:qgis/Quantum-GIS
  • Loading branch information
timlinux committed Nov 12, 2011
2 parents cf7b989 + d3fe194 commit 6274cd112f1cca6ae09b89ba35df946f48cab482
0 python/plugins/fTools/__init__.py 100755 → 100644
Empty file.
32 python/plugins/fTools/fTools.py 100755 → 100644
@@ -43,7 +43,7 @@
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 @@ def updateThemeIcons(self, theme):
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 @@ def updateThemeIcons(self, theme):
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 @@ def initGui(self):
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 @@ def initGui(self):
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 @@ def initGui(self):
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 @@ def docentroids(self):
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 @@ def dospatJoin(self):

def doMergeShapes(self):
d = doMergeShapes.Dialog(self.iface)
d.show()
d.exec_()

def doSpatIndex(self):
d = doSpatialIndex.Dialog(self.iface)
d.show()
d.exec_()
Empty file.
@@ -161,7 +161,9 @@ def manageGui(self):
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 @@ def manageGui(self):
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 @@ def runFinishedFromThread( self, success ):
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." ) )

@@ -182,6 +182,9 @@ def manageGui( self ):
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 @@ def manageGui( self ):
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 @@ def runFinishedFromThread( self, results ):
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 @@ def union( self ):
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 @@ def union( self ):
# 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 )
@@ -46,10 +46,13 @@ def __init__(self, iface):
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 @@ def accept(self):
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 )

@@ -45,12 +45,15 @@ def __init__(self, iface, function):
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 @@ def accept(self):
if addToTOC == QMessageBox.Yes:
vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr")
QgsMapLayerRegistry.instance().addMapLayer(vlayer)
self.populateLayers()
self.progressBar.setValue(0)
self.buttonOk.setEnabled( True )

Empty file.
Empty file.
@@ -44,14 +44,18 @@ def __init__(self, iface):
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 @@ def accept(self):
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 @@ def compute(self, inPoly, inPts, inField, outPath, progressBar):
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()
@@ -46,9 +46,14 @@ def __init__(self, iface):
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 @@ def accept(self):
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 @@ def randomize(self, inLayer, outPath, minimum, design, value):
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)
Empty file.
@@ -50,7 +50,11 @@ def __init__(self, iface):
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 @@ def accept(self):
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 @@ def outFile(self):
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 @@ def simpleRandom(self, n, bound, xmin, xmax, ymin, ymax):
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()
Empty file.

0 comments on commit 6274cd1

Please sign in to comment.