applying patch from ticket #1714: adds option to perform geoprocessing and basic statistics functions on selected features

git-svn-id: http://svn.osgeo.org/qgis/trunk@10849 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
cfarmer 2009-05-26 18:07:37 +00:00
parent d37aae28a6
commit f13f45e813
7 changed files with 1097 additions and 457 deletions

View File

@ -13,6 +13,8 @@ class GeoprocessingDialog( QDialog, Ui_Dialog ):
self.setupUi( self )
self.myFunction = function
QObject.connect( self.btnBrowse, SIGNAL( "clicked()" ), self.outFile )
QObject.connect( self.inShapeA, SIGNAL( "currentIndexChanged(QString)" ), self.checkA )
QObject.connect( self.inShapeB, SIGNAL( "currentIndexChanged(QString)" ), self.checkB )
if function == 4 or function == 1 or function == 2:
QObject.connect( self.inShapeA, SIGNAL( "currentIndexChanged(QString)" ), self.update )
self.manageGui()
@ -20,6 +22,24 @@ class GeoprocessingDialog( QDialog, Ui_Dialog ):
self.cancel_close = self.buttonBox_2.button( QDialogButtonBox.Close )
self.progressBar.setValue (0 )
def checkA( self ):
inputLayer = unicode( self.inShapeA.currentText() )
if inputLayer != "":
changedLayer = ftools_utils.getVectorLayerByName( inputLayer )
if changedLayer.selectedFeatureCount() != 0:
self.useSelectedA.setCheckState( Qt.Checked )
else:
self.useSelectedA.setCheckState( Qt.Unchecked )
def checkB( self ):
inputLayer = unicode( self.inShapeB.currentText() )
if inputLayer != "":
changedLayer = ftools_utils.getVectorLayerByName( inputLayer )
if changedLayer.selectedFeatureCount() != 0:
self.useSelectedB.setCheckState( Qt.Checked )
else:
self.useSelectedB.setCheckState( Qt.Unchecked )
def update( self ):
self.attrib.clear()
inputLayer = unicode( self.inShapeA.currentText() )
@ -42,18 +62,28 @@ class GeoprocessingDialog( QDialog, Ui_Dialog ):
QMessageBox.warning( self, "Geoprocessing", self.tr( "Please specify dissolve field" ) )
elif self.outShape.text() == "":
QMessageBox.warning( self, "Geoprocessing", self.tr( "Please specify output shapefile" ) )
else:
changedLayerA = ftools_utils.getVectorLayerByName( self.inShapeA.currentText() )
changedLayerB = ftools_utils.getVectorLayerByName( self.inShapeB.currentText() )
# check for selection in layer A
if self.useSelectedA.isChecked() and changedLayerA.selectedFeatureCount() == 0:
QMessageBox.warning( self, "Geoprocessing", self.tr( "No features selected, please uncheck 'Use selected' or make a selection" ) )
# check for selection in layer B
elif self.inShapeB.isVisible() and self.useSelectedB.isChecked() and changedLayerB.selectedFeatureCount() == 0:
QMessageBox.warning( self, "Geoprocessing", self.tr( "No features selected, please uncheck 'Use selected' or make a selection" ) )
else:
self.outShape.clear()
if self.attrib.isEnabled():
self.geoprocessing( self.inShapeA.currentText(), self.inShapeB.currentText(),
unicode( self.attrib.currentText() ), self.mergeOutput.checkState() )
unicode( self.attrib.currentText() ), self.mergeOutput.checkState(), self.useSelectedA.checkState(),
self.useSelectedB.checkState() )
else:
if self.param.isEnabled() and self.param.isVisible():
parameter = float( self.param.text() )
else:
parameter = None
self.geoprocessing( self.inShapeA.currentText(), self.inShapeB.currentText(),
parameter, self.mergeOutput.checkState() )
parameter, self.mergeOutput.checkState(), self.useSelectedA.checkState(), self.useSelectedB.checkState() )
def outFile( self ):
self.outShape.clear()
@ -66,11 +96,13 @@ class GeoprocessingDialog( QDialog, Ui_Dialog ):
if self.myFunction == 1: # Buffer
self.label_2.hide()
self.inShapeB.hide()
self.useSelectedB.hide()
self.label_4.hide()
self.setWindowTitle( self.tr( "Buffer(s)" ) )
elif self.myFunction == 2: # Convex hull
self.label_2.hide()
self.inShapeB.hide()
self.useSelectedB.hide()
self.rdoBuffer.setText( self.tr( "Create single minimum convex hull" ) )
self.rdoField.setText( self.tr( "Create convex hulls based on input field" ) )
self.label_4.hide()
@ -80,6 +112,7 @@ class GeoprocessingDialog( QDialog, Ui_Dialog ):
elif self.myFunction == 4: # Dissolve
self.label_2.hide()
self.inShapeB.hide()
self.useSelectedB.hide()
self.rdoBuffer.hide()
self.attrib.setEnabled( True )
self.param.hide()
@ -139,14 +172,14 @@ class GeoprocessingDialog( QDialog, Ui_Dialog ):
#7: Symetrical Difference
#8: Clip
def geoprocessing( self, myLayerA, myLayerB, myParam, myMerge ):
def geoprocessing( self, myLayerA, myLayerB, myParam, myMerge, mySelectionA, mySelectionB ):
check = QFile( self.shapefileName )
if check.exists():
if not QgsVectorFileWriter.deleteShapeFile( self.shapefileName ):
QMessageBox.warning( self, "Geoprocessing", self.tr( "Unable to delete existing shapefile." ) )
return
self.testThread = geoprocessingThread( self.iface.mainWindow(), self, self.myFunction, myLayerA,
myLayerB, myParam, myMerge, self.shapefileName, self.encoding )
myLayerB, myParam, myMerge, mySelectionA, mySelectionB, self.shapefileName, self.encoding )
QObject.connect( self.testThread, SIGNAL( "runFinished(PyQt_PyObject)" ), self.runFinishedFromThread )
QObject.connect( self.testThread, SIGNAL( "runStatus(PyQt_PyObject)" ), self.runStatusFromThread )
QObject.connect( self.testThread, SIGNAL( "runRange(PyQt_PyObject)" ), self.runRangeFromThread )
@ -189,7 +222,7 @@ class GeoprocessingDialog( QDialog, Ui_Dialog ):
class geoprocessingThread( QThread ):
def __init__( self, parentThread, parentObject, function, myLayerA, myLayerB,
myParam, myMerge, myName, myEncoding ):
myParam, myMerge, mySelectionA, mySelectionB, myName, myEncoding ):
QThread.__init__( self, parentThread )
self.parent = parentObject
self.running = False
@ -198,6 +231,8 @@ class geoprocessingThread( QThread ):
self.myLayerB = myLayerB
self.myParam = myParam
self.myMerge = myMerge
self.mySelectionA = mySelectionA
self.mySelectionB = mySelectionB
self.myName = myName
self.myEncoding = myEncoding
@ -244,14 +279,75 @@ class geoprocessingThread( QThread ):
inFeat = QgsFeature()
inGeom = QgsGeometry()
outGeom = QgsGeometry()
nFeat = vproviderA.featureCount()
nElement = 0
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0)
# there is selection in input layer
if self.mySelectionA:
nFeat = self.vlayerA.selectedFeatureCount()
selectionA = self.vlayerA.selectedFeatures()
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
# with dissolve
if self.myMerge:
first = True
for inFeat in selectionA:
atMap = inFeat.attributeMap()
if useField:
value = atMap[ self.myParam ].doDouble()[ 0 ]
else:
value = self.myParam
inGeom = QgsGeometry( inFeat.geometry() )
try:
outGeom = inGeom.buffer( float( value ), 5 )
if first:
tempGeom = QgsGeometry( outGeom )
first = False
else:
try:
tempGeom = tempGeom.combine( outGeom )
except:
GEOS_EXCEPT = False
continue
except:
GEOS_EXCEPT = False
continue
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
try:
outFeat.setGeometry( tempGeom )
writer.addFeature( outFeat )
except:
FEATURE_EXCEPT = False
# without dissolve
else:
for inFeat in selectionA:
atMap = inFeat.attributeMap()
if useField:
value = atMap[ self.myParam ].toDouble()[ 0 ]
else:
value = self.myParam
inGeom = QgsGeometry( inFeat.geometry() )
try:
outGeom = inGeom.buffer( float( value ), 5 )
try:
outFeat.setGeometry( outGeom )
outFeat.setAttributeMap( atMap )
writer.addFeature( outFeat )
except:
FEATURE_EXCEPT = False
continue
except:
GEOS_EXCEPT = False
continue
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
# there is no selection in input layer
else:
nFeat = vproviderA.featureCount()
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
# with dissolve
if self.myMerge:
first = True
vproviderA.rewind()
add = True
while vproviderA.nextFeature( inFeat ):
atMap = inFeat.attributeMap()
if useField:
@ -280,6 +376,7 @@ class geoprocessingThread( QThread ):
writer.addFeature( outFeat )
except:
FEATURE_EXCEPT = False
# without dissolve
else:
vproviderA.rewind()
while vproviderA.nextFeature( inFeat ):
@ -318,11 +415,69 @@ class geoprocessingThread( QThread ):
outFeat = QgsFeature()
inGeom = QgsGeometry()
outGeom = QgsGeometry()
nElement = 0
# there is selection in input layer
if self.mySelectionA:
nFeat = self.vlayerA.selectedFeatureCount()
selectionA = self.vlayerA.selectedFeatures()
if useField:
unique = ftools_utils.getUniqueValues( vproviderA, self.myParam )
nFeat = vproviderA.featureCount() * len( unique )
nElement = 0
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0)
nFeat = nFeat * len( unique )
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
for i in unique:
hull = []
first = True
outID = 0
for inFeat in selectionA:
atMap = inFeat.attributeMap()
idVar = atMap[ self.myParam ]
if idVar.toString().trimmed() == i.toString().trimmed():
if first:
outID = idVar
first = False
inGeom = QgsGeometry( inFeat.geometry() )
points = ftools_utils.extractPoints( inGeom )
hull.extend( points )
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
if len( hull ) >= 3:
tmpGeom = QgsGeometry( outGeom.fromMultiPoint( hull ) )
try:
outGeom = tmpGeom.convexHull()
outFeat.setGeometry( outGeom )
(area, perim) = self.simpleMeasure( outGeom )
outFeat.addAttribute( 0, QVariant( outID ) )
outFeat.addAttribute( 1, QVariant( area ) )
outFeat.addAttribute( 2, QVariant( perim ) )
writer.addFeature( outFeat )
except:
GEOS_EXCEPT = False
continue
else:
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
hull = []
for inFeat in selectionA:
inGeom = QgsGeometry( inFeat.geometry() )
points = ftools_utils.extractPoints( inGeom )
hull.extend( points )
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
tmpGeom = QgsGeometry( outGeom.fromMultiPoint( hull ) )
try:
outGeom = tmpGeom.convexHull()
outFeat.setGeometry( outGeom )
writer.addFeature( outFeat )
except:
GEOS_EXCEPT = False
# there is no selection in input layer
else:
nFeat = vproviderA.featureCount()
if useField:
unique = ftools_utils.getUniqueValues( vproviderA, self.myParam )
nFeat = nFeat * len( unique )
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
for i in unique:
hull = []
@ -356,12 +511,10 @@ class geoprocessingThread( QThread ):
GEOS_EXCEPT = False
continue
else:
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
hull = []
vproviderA.rewind()
nFeat = vproviderA.featureCount()
nElement = 0
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0)
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
while vproviderA.nextFeature( inFeat ):
inGeom = QgsGeometry( inFeat.geometry() )
points = ftools_utils.extractPoints( inGeom )
@ -389,13 +542,76 @@ class geoprocessingThread( QThread ):
inFeat = QgsFeature()
outFeat = QgsFeature()
vproviderA.rewind()
nFeat = vproviderA.featureCount()
nElement = 0
# there is selection in input layer
if self.mySelectionA:
nFeat = self.vlayerA.selectedFeatureCount()
selectionA = self.vlayerA.selectedFeatures()
if not useField:
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
first = True
for inFeat in selectionA:
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
if first:
attrs = inFeat.attributeMap()
tmpInGeom = QgsGeometry( inFeat.geometry() )
outFeat.setGeometry( tmpInGeom )
first = False
else:
tmpInGeom = QgsGeometry( inFeat.geometry() )
tmpOutGeom = QgsGeometry( outFeat.geometry() )
try:
tmpOutGeom = QgsGeometry( tmpOutGeom.combine( tmpInGeom ) )
outFeat.setGeometry( tmpOutGeom )
except:
GEOS_EXCEPT = False
continue
outFeat.setAttributeMap( attrs )
writer.addFeature( outFeat )
else:
unique = vproviderA.uniqueValues( int( self.myParam ) )
nFeat = nFeat * len( unique )
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
for item in unique:
first = True
add = False
vproviderA.select( allAttrsA )
vproviderA.rewind()
for inFeat in selectionA:
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
atMap = inFeat.attributeMap()
tempItem = atMap[ self.myParam ]
if tempItem.toString().trimmed() == item.toString().trimmed():
add = True
if first:
QgsGeometry( inFeat.geometry() )
tmpInGeom = QgsGeometry( inFeat.geometry() )
outFeat.setGeometry( tmpInGeom )
first = False
attrs = inFeat.attributeMap()
else:
tmpInGeom = QgsGeometry( inFeat.geometry() )
tmpOutGeom = QgsGeometry( outFeat.geometry() )
try:
tmpOutGeom = QgsGeometry( tmpOutGeom.combine( tmpInGeom ) )
outFeat.setGeometry( tmpOutGeom )
except:
GEOS_EXCEPT = False
add = False
if add:
outFeat.setAttributeMap( attrs )
writer.addFeature( outFeat )
# there is no selection in input layer
else:
nFeat = vproviderA.featureCount()
if not useField:
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0)
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
first = True
add = True
while vproviderA.nextFeature( inFeat ):
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
@ -470,11 +686,111 @@ class geoprocessingThread( QThread ):
inFeatB = QgsFeature()
outFeat = QgsFeature()
index = ftools_utils.createIndex( vproviderB )
nFeat = vproviderA.featureCount()
nElement = 0
# there is selection in input layer
if self.mySelectionA:
nFeat = self.vlayerA.selectedFeatureCount()
selectionA = self.vlayerA.selectedFeatures()
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0)
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
# we have selection in overlay layer
if self.mySelectionB:
selectionB = self.vlayerB.selectedFeaturesIds()
for inFeatA in selectionA:
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
add = True
geom = QgsGeometry( inFeatA.geometry() )
diff_geom = QgsGeometry( geom )
atMap = inFeatA.attributeMap()
intersects = index.intersects( geom.boundingBox() )
for id in intersects:
# is intersect feature in selection
if id in selectionB:
vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
tmpGeom = QgsGeometry( inFeatB.geometry() )
try:
if diff_geom.intersects( tmpGeom ):
diff_geom = QgsGeometry( diff_geom.difference( tmpGeom ) )
except:
GEOS_EXCEPT = False
add = False
break
if add:
try:
outFeat.setGeometry( diff_geom )
outFeat.setAttributeMap( atMap )
writer.addFeature( outFeat )
except:
FEATURE_EXCEPT = False
continue
# we have no selection in overlay layer
else:
for inFeatA in selectionA:
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
add = True
geom = QgsGeometry( inFeatA.geometry() )
diff_geom = QgsGeometry( geom )
atMap = inFeatA.attributeMap()
intersects = index.intersects( geom.boundingBox() )
for id in intersects:
vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
tmpGeom = QgsGeometry( inFeatB.geometry() )
try:
if diff_geom.intersects( tmpGeom ):
diff_geom = QgsGeometry( diff_geom.difference( tmpGeom ) )
except:
GEOS_EXCEPT = False
add = False
break
if add:
try:
outFeat.setGeometry( diff_geom )
outFeat.setAttributeMap( atMap )
writer.addFeature( outFeat )
except:
FEATURE_EXCEPT = False
continue
# there is no selection in input layer
else:
nFeat = vproviderA.featureCount()
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
vproviderA.rewind()
# we have selection in overlay layer
if self.mySelectionB:
selectionB = self.vlayerB.selectedFeaturesIds()
while vproviderA.nextFeature( inFeatA ):
nElement += 1
add = True
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
geom = QgsGeometry( inFeatA.geometry() )
diff_geom = QgsGeometry( geom )
atMap = inFeatA.attributeMap()
intersects = index.intersects( geom.boundingBox() )
for id in intersects:
# now check if id in selection
if id in selectionB:
vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
tmpGeom = QgsGeometry( inFeatB.geometry() )
try:
if diff_geom.intersects( tmpGeom ):
diff_geom = QgsGeometry( diff_geom.difference( tmpGeom ) )
except:
GEOS_EXCEPT = False
add = False
break
if add:
try:
outFeat.setGeometry( diff_geom )
outFeat.setAttributeMap( atMap )
writer.addFeature( outFeat )
except:
FEATURE_EXCEPT = False
continue
# we have no selection in overlay layer
else:
while vproviderA.nextFeature( inFeatA ):
nElement += 1
add = True
@ -522,11 +838,112 @@ class geoprocessingThread( QThread ):
inFeatB = QgsFeature()
outFeat = QgsFeature()
index = ftools_utils.createIndex( vproviderB )
nFeat = vproviderA.featureCount()
nElement = 0
# there is selection in input layer
if self.mySelectionA:
nFeat = self.vlayerA.selectedFeatureCount()
selectionA = self.vlayerA.selectedFeatures()
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0)
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
# we have selection in overlay layer
if self.mySelectionB:
selectionB = self.vlayerB.selectedFeaturesIds()
for inFeatA in selectionA:
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
geom = QgsGeometry( inFeatA.geometry() )
atMapA = inFeatA.attributeMap()
intersects = index.intersects( geom.boundingBox() )
for id in intersects:
if id in selectionB:
vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
tmpGeom = QgsGeometry( inFeatB.geometry() )
try:
if geom.intersects( tmpGeom ):
atMapB = inFeatB.attributeMap()
int_geom = QgsGeometry( geom.intersection( tmpGeom ) )
if int_geom.wkbType() == 7:
int_com = geom.combine( tmpGeom )
int_sym = geom.symDifference( tmpGeom )
int_geom = QgsGeometry( int_com.difference( int_sym ) )
try:
outFeat.setGeometry( int_geom )
outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
writer.addFeature( outFeat )
except:
FEATURE_EXCEPT = False
continue
except:
GEOS_EXCEPT = False
break
# we don't have selection in overlay layer
else:
for inFeatA in selectionA:
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
geom = QgsGeometry( inFeatA.geometry() )
atMapA = inFeatA.attributeMap()
intersects = index.intersects( geom.boundingBox() )
for id in intersects:
vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
tmpGeom = QgsGeometry( inFeatB.geometry() )
try:
if geom.intersects( tmpGeom ):
atMapB = inFeatB.attributeMap()
int_geom = QgsGeometry( geom.intersection( tmpGeom ) )
if int_geom.wkbType() == 7:
int_com = geom.combine( tmpGeom )
int_sym = geom.symDifference( tmpGeom )
int_geom = QgsGeometry( int_com.difference( int_sym ) )
try:
outFeat.setGeometry( int_geom )
outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
writer.addFeature( outFeat )
except:
EATURE_EXCEPT = False
continue
except:
GEOS_EXCEPT = False
break
# there is no selection in input layer
else:
nFeat = vproviderA.featureCount()
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0)
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
vproviderA.rewind()
# we have selection in overlay layer
if self.mySelectionB:
selectionB = self.vlayerB.selectedFeaturesIds()
while vproviderA.nextFeature( inFeatA ):
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
geom = QgsGeometry( inFeatA.geometry() )
atMapA = inFeatA.attributeMap()
intersects = index.intersects( geom.boundingBox() )
for id in intersects:
if id in selectionB:
vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
tmpGeom = QgsGeometry( inFeatB.geometry() )
try:
if geom.intersects( tmpGeom ):
atMapB = inFeatB.attributeMap()
int_geom = QgsGeometry( geom.intersection( tmpGeom ) )
if int_geom.wkbType() == 7:
int_com = geom.combine( tmpGeom )
int_sym = geom.symDifference( tmpGeom )
int_geom = QgsGeometry( int_com.difference( int_sym ) )
try:
outFeat.setGeometry( int_geom )
outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
writer.addFeature( outFeat )
except:
FEATURE_EXCEPT = False
continue
except:
GEOS_EXCEPT = False
break
# we have no selection in overlay layer
else:
while vproviderA.nextFeature( inFeatA ):
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
@ -773,11 +1190,110 @@ class geoprocessingThread( QThread ):
inFeatB = QgsFeature()
outFeat = QgsFeature()
index = ftools_utils.createIndex( vproviderB )
nFeat = vproviderA.featureCount()
nElement = 0
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
vproviderA.rewind()
nElement = 0
# there is selection in input layer
if self.mySelectionA:
nFeat = self.vlayerA.selectedFeatureCount()
selectionA = self.vlayerA.selectedFeatures()
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0)
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
# we have selection in overlay layer
if self.mySelectionB:
selectionB = self.vlayerB.selectedFeaturesIds()
for inFeatA in selectionA:
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
geom = QgsGeometry( inFeatA.geometry() )
atMap = inFeatA.attributeMap()
intersects = index.intersects( geom.boundingBox() )
for id in intersects:
if id in selectionB:
vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
tmpGeom = QgsGeometry( inFeatB.geometry() )
try:
if geom.intersects( tmpGeom ):
int_geom = QgsGeometry( geom.intersection( tmpGeom ) )
if int_geom.wkbType() == 7:
int_com = geom.combine( tmpGeom )
int_sym = geom.symDifference( tmpGeom )
int_geom = QgsGeometry( int_com.difference( int_sym ) )
try:
outFeat.setGeometry( int_geom )
outFeat.setAttributeMap( atMap )
writer.addFeature( outFeat )
except:
FEATURE_EXCEPT = False
continue
except:
GEOS_EXCEPT = False
break
# we have no selection in overlay layer
else:
for inFeatA in selectionA:
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
geom = QgsGeometry( inFeatA.geometry() )
atMap = inFeatA.attributeMap()
intersects = index.intersects( geom.boundingBox() )
for id in intersects:
vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
tmpGeom = QgsGeometry( inFeatB.geometry() )
try:
if geom.intersects( tmpGeom ):
int_geom = QgsGeometry( geom.intersection( tmpGeom ) )
if int_geom.wkbType() == 7:
int_com = geom.combine( tmpGeom )
int_sym = geom.symDifference( tmpGeom )
int_geom = QgsGeometry( int_com.difference( int_sym ) )
try:
outFeat.setGeometry( int_geom )
outFeat.setAttributeMap( atMap )
writer.addFeature( outFeat )
except:
FEATURE_EXCEPT = False
continue
except:
GEOS_EXCEPT = False
break
# there is no selection in input layer
else:
nFeat = vproviderA.featureCount()
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0)
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
# we have selection in overlay layer
if self.mySelectionB:
selectionB = self.vlayerB.selectedFeaturesIds()
while vproviderA.nextFeature( inFeatA ):
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
geom = QgsGeometry( inFeatA.geometry() )
atMap = inFeatA.attributeMap()
intersects = index.intersects( geom.boundingBox() )
for id in intersects:
if id in selectionB:
vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
tmpGeom = QgsGeometry( inFeatB.geometry() )
try:
if geom.intersects( tmpGeom ):
int_geom = QgsGeometry( geom.intersection( tmpGeom ) )
if int_geom.wkbType() == 7:
int_com = geom.combine( tmpGeom )
int_sym = geom.symDifference( tmpGeom )
int_geom = QgsGeometry( int_com.difference( int_sym ) )
try:
outFeat.setGeometry( int_geom )
outFeat.setAttributeMap( atMap )
writer.addFeature( outFeat )
except:
FEATURE_EXCEPT = False
continue
except:
GEOS_EXCEPT = False
break
# we have no selection in overlay layer
else:
while vproviderA.nextFeature( inFeatA ):
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )

View File

@ -38,31 +38,42 @@ class VisualDialog( QDialog, Ui_Dialog ):
if inputLayer != "":
changedLayer = ftools_utils.getVectorLayerByName( inputLayer )
changedField = changedLayer.dataProvider().fields()
# for Basic statistics (with or without selection)
if self.myFunction == 3:
if changedLayer.selectedFeatureCount() != 0:
self.useSelected.setCheckState( Qt.Checked )
else:
self.useSelected.setCheckState( Qt.Unchecked )
# add all fields in combobox because now we can work with text fields too
for i in changedField:
if self.myFunction == 3:
if changedField[i].type() == QVariant.Int or changedField[i].type() == QVariant.Double:
self.cmbField.addItem( unicode( changedField[i].name() ) )
else:
self.cmbField.addItem( unicode( changedField[i].name() ) )
self.cmbField.addItem( unicode( changedField[i].name() ) )
def accept( self ):
if self.inShape.currentText() == "":
QMessageBox.information( self, "Error!", self.tr( "Please specify input vector layer" ) )
elif self.cmbField.isVisible() and self.cmbField.currentText() == "":
QMessageBox.information( self, "Error!", self.tr( "Please specify input field" ) )
else:
self.visual( self.inShape.currentText(), self.cmbField.currentText() )
self.visual( self.inShape.currentText(), self.cmbField.currentText(), self.useSelected.checkState() )
def manageGui( self ):
if self.myFunction == 1: # Check geometry validity
self.setWindowTitle( self.tr( "Check geometry validity" ) )
self.cmbField.setVisible( False )
self.label.setVisible( False )
self.useSelected.setVisible( False )
self.label_2.setText( self.tr( "Geometry errors" ) )
self.label_4.setText( self.tr( "Total encountered errors" ) )
elif self.myFunction == 2: # List unique values
self.setWindowTitle( self.tr( "List unique values" ) )
self.label_2.setText( self.tr( "Unique values" ) )
self.label_4.setText(self.tr( "Total unique values" ) )
self.useSelected.setVisible( False )
elif self.myFunction == 3: # Basic statistics
self.setWindowTitle( self.tr( "Basics statistics" ) )
self.label_2.setText( self.tr( "Statistics output" ) )
@ -73,6 +84,7 @@ class VisualDialog( QDialog, Ui_Dialog ):
self.setWindowTitle( self.tr( "Nearest neighbour analysis" ) )
self.cmbField.setVisible( False )
self.label.setVisible( False )
self.useSelected.setVisible( False )
self.label_2.setText( self.tr( "Nearest neighbour statistics" ) )
self.label_4.setVisible( False )
self.lstCount.setVisible( False )
@ -91,11 +103,11 @@ class VisualDialog( QDialog, Ui_Dialog ):
#2: List unique values
#3: Basic statistics
#4: Nearest neighbour analysis
def visual( self, myLayer, myField ):
def visual( self, myLayer, myField, mySelection ):
vlayer = ftools_utils.getVectorLayerByName( myLayer )
self.lstUnique.clear()
self.lstCount.clear()
self.testThread = visualThread( self.iface.mainWindow(), self, self.myFunction, vlayer, myField )
self.testThread = visualThread( self.iface.mainWindow(), self, self.myFunction, vlayer, myField, mySelection )
QObject.connect( self.testThread, SIGNAL( "runFinished(PyQt_PyObject)" ), self.runFinishedFromThread )
QObject.connect( self.testThread, SIGNAL( "runStatus(PyQt_PyObject)" ), self.runStatusFromThread )
QObject.connect( self.testThread, SIGNAL( "runRange(PyQt_PyObject)" ), self.runRangeFromThread )
@ -122,13 +134,14 @@ class VisualDialog( QDialog, Ui_Dialog ):
self.progressBar.setRange( range_vals[ 0 ], range_vals[ 1 ] )
class visualThread( QThread ):
def __init__( self, parentThread, parentObject, function, vlayer, myField ):
def __init__( self, parentThread, parentObject, function, vlayer, myField, mySelection ):
QThread.__init__( self, parentThread )
self.parent = parentObject
self.running = False
self.myFunction = function
self.vlayer = vlayer
self.myField = myField
self.mySelection = mySelection
# self.total = 0
# self.currentCount = 0
@ -176,13 +189,94 @@ class visualThread( QThread ):
feat = QgsFeature()
sumVal = 0.0
meanVal = 0.0
stdVal = 0.0
cvVal = 0.0
nVal = 0.0
values = []
first = True
nFeat = vprovider.featureCount()
nElement = 0
# determine selected field type
if ftools_utils.getFieldType( vlayer, myField ) == 'String':
fillVal = 0
emptyVal = 0
if self.mySelection: # only selected features
selection = vlayer.selectedFeatures()
nFeat = vlayer.selectedFeatureCount()
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
for f in selection:
atMap = f.attributeMap()
lenVal = float( len( atMap[ index ].toString() ) )
if first:
minVal = lenVal
maxVal = lenVal
first = False
else:
if lenVal < minVal: minVal = lenVal
if lenVal > maxVal: maxVal = lenVal
if lenVal != 0.00:
fillVal += 1
else:
emptyVal += 1
values.append( lenVal )
sumVal = sumVal + lenVal
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
else: # there is no selection, process the whole layer
nFeat = vprovider.featureCount()
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
while vprovider.nextFeature( feat ):
atMap = feat.attributeMap()
lenVal = float( len( atMap[ index ].toString() ) )
if first:
minVal = lenVal
maxVal = lenVal
first = False
else:
if lenVal < minVal: minVal = lenVal
if lenVal > maxVal: maxVal = lenVal
if lenVal != 0.00:
fillVal += 1
else:
emptyVal += 1
values.append( lenVal )
sumVal = sumVal + lenVal
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
nVal= float( len( values ) )
if nVal > 0.00:
meanVal = sumVal / nVal
lstStats = []
lstStats.append( QCoreApplication.translate( "statResult", "Max. len. : " ) + unicode( maxVal ) )
lstStats.append( QCoreApplication.translate( "statResult", "Min. len. : " ) + unicode( minVal ) )
lstStats.append( QCoreApplication.translate( "statResult", "Mean. len : " ) + unicode( meanVal ) )
lstStats.append( QCoreApplication.translate( "statResult", "Filled : " ) + unicode( fillVal ) )
lstStats.append( QCoreApplication.translate( "statResult", "Empty : " ) + unicode( emptyVal ) )
lstStats.append( QCoreApplication.translate( "statResult", "N : " ) + unicode( nVal ) )
return ( lstStats, [] )
else: # numeric field
stdVal = 0
cvVal = 0
if self.mySelection: # only selected features
selection = vlayer.selectedFeatures()
nFeat = vlayer.selectedFeatureCount()
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
for f in selection:
atMap = f.attributeMap()
value = float( atMap[ index ].toDouble()[ 0 ] )
if first:
minVal = value
maxVal = value
first = False
else:
if value < minVal: minVal = value
if value > maxVal: maxVal = value
values.append( value )
sumVal = sumVal + value
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
else: # there is no selection, process the whole layer
nFeat = vprovider.featureCount()
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
while vprovider.nextFeature( feat ):
@ -196,17 +290,17 @@ class visualThread( QThread ):
if value < minVal: minVal = value
if value > maxVal: maxVal = value
values.append( value )
sumVal = float( sumVal + value )
sumVal = sumVal + value
nElement += 1
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nElement )
nVal= float( len( values ) )
if nVal > 0.00:
meanVal = float( sumVal ) / nVal
if not meanVal == 0.00:
meanVal = sumVal / nVal
if meanVal != 0.00:
for val in values:
stdVal += float( ( val - meanVal ) * ( val - meanVal ) )
stdVal = float( math.sqrt( stdVal / nVal ) )
cvVal = float( stdVal / meanVal )
stdVal += ( ( val - meanVal ) * ( val - meanVal ) )
stdVal = math.sqrt( stdVal / nVal )
cvVal = stdVal / meanVal
lstStats = []
lstStats.append( "Mean : " + unicode( meanVal ) )
lstStats.append( "StdDev : " + unicode( stdVal ) )

View File

@ -2,8 +2,8 @@
# Form implementation generated from reading ui file 'frmGeoprocessing.ui'
#
# Created: Thu Nov 13 23:17:35 2008
# by: PyQt4 UI code generator 4.3.3
# Created: Tue May 26 19:00:00 2009
# by: PyQt4 UI code generator 4.4.4
#
# WARNING! All changes made in this file will be lost!
@ -12,69 +12,54 @@ from PyQt4 import QtCore, QtGui
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(QtCore.QSize(QtCore.QRect(0,0,422,405).size()).expandedTo(Dialog.minimumSizeHint()))
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Preferred)
Dialog.resize(422, 405)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(Dialog.sizePolicy().hasHeightForWidth())
Dialog.setSizePolicy(sizePolicy)
self.gridlayout = QtGui.QGridLayout(Dialog)
self.gridlayout.setObjectName("gridlayout")
self.gridLayout = QtGui.QGridLayout(Dialog)
self.gridLayout.setObjectName("gridLayout")
self.vboxlayout = QtGui.QVBoxLayout()
self.vboxlayout.setObjectName("vboxlayout")
self.label_1 = QtGui.QLabel(Dialog)
self.label_1.setObjectName("label_1")
self.vboxlayout.addWidget(self.label_1)
self.inShapeA = QtGui.QComboBox(Dialog)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Fixed)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.inShapeA.sizePolicy().hasHeightForWidth())
self.inShapeA.setSizePolicy(sizePolicy)
self.inShapeA.setObjectName("inShapeA")
self.vboxlayout.addWidget(self.inShapeA)
self.gridlayout.addLayout(self.vboxlayout,0,0,1,2)
self.gridLayout.addLayout(self.vboxlayout, 0, 0, 1, 2)
self.vboxlayout1 = QtGui.QVBoxLayout()
self.vboxlayout1.setObjectName("vboxlayout1")
self.label_2 = QtGui.QLabel(Dialog)
self.label_2.setObjectName("label_2")
self.vboxlayout1.addWidget(self.label_2)
self.inShapeB = QtGui.QComboBox(Dialog)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Fixed)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.inShapeB.sizePolicy().hasHeightForWidth())
self.inShapeB.setSizePolicy(sizePolicy)
self.inShapeB.setObjectName("inShapeB")
self.vboxlayout1.addWidget(self.inShapeB)
self.gridlayout.addLayout(self.vboxlayout1,1,0,1,2)
self.gridLayout.addLayout(self.vboxlayout1, 3, 0, 1, 2)
self.hboxlayout = QtGui.QHBoxLayout()
self.hboxlayout.setObjectName("hboxlayout")
self.hboxlayout1 = QtGui.QHBoxLayout()
self.hboxlayout1.setObjectName("hboxlayout1")
self.rdoBuffer = QtGui.QRadioButton(Dialog)
self.rdoBuffer.setChecked(True)
self.rdoBuffer.setObjectName("rdoBuffer")
self.hboxlayout1.addWidget(self.rdoBuffer)
self.hboxlayout.addLayout(self.hboxlayout1)
self.param = QtGui.QLineEdit(Dialog)
self.param.setEnabled(True)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Fixed)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.param.sizePolicy().hasHeightForWidth())
@ -83,90 +68,85 @@ class Ui_Dialog(object):
self.param.setCursorPosition(0)
self.param.setObjectName("param")
self.hboxlayout.addWidget(self.param)
self.gridlayout.addLayout(self.hboxlayout,2,0,1,2)
self.gridLayout.addLayout(self.hboxlayout, 5, 0, 1, 2)
self.vboxlayout2 = QtGui.QVBoxLayout()
self.vboxlayout2.setObjectName("vboxlayout2")
self.hboxlayout2 = QtGui.QHBoxLayout()
self.hboxlayout2.setObjectName("hboxlayout2")
self.rdoField = QtGui.QRadioButton(Dialog)
self.rdoField.setObjectName("rdoField")
self.hboxlayout2.addWidget(self.rdoField)
self.label_4 = QtGui.QLabel(Dialog)
self.label_4.setObjectName("label_4")
self.hboxlayout2.addWidget(self.label_4)
spacerItem = QtGui.QSpacerItem(40,20,QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Minimum)
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.hboxlayout2.addItem(spacerItem)
self.vboxlayout2.addLayout(self.hboxlayout2)
self.attrib = QtGui.QComboBox(Dialog)
self.attrib.setEnabled(False)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Fixed)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.attrib.sizePolicy().hasHeightForWidth())
self.attrib.setSizePolicy(sizePolicy)
self.attrib.setObjectName("attrib")
self.vboxlayout2.addWidget(self.attrib)
self.gridlayout.addLayout(self.vboxlayout2,3,0,1,2)
self.gridLayout.addLayout(self.vboxlayout2, 6, 0, 1, 2)
self.hboxlayout3 = QtGui.QHBoxLayout()
self.hboxlayout3.setSpacing(6)
self.hboxlayout3.setMargin(0)
self.hboxlayout3.setObjectName("hboxlayout3")
self.mergeOutput = QtGui.QCheckBox(Dialog)
self.mergeOutput.setEnabled(True)
self.mergeOutput.setObjectName("mergeOutput")
self.hboxlayout3.addWidget(self.mergeOutput)
self.gridlayout.addLayout(self.hboxlayout3,4,0,1,1)
spacerItem1 = QtGui.QSpacerItem(20,40,QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Expanding)
self.gridlayout.addItem(spacerItem1,5,0,1,1)
self.gridLayout.addLayout(self.hboxlayout3, 7, 0, 1, 1)
spacerItem1 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.gridLayout.addItem(spacerItem1, 8, 0, 1, 1)
self.vboxlayout3 = QtGui.QVBoxLayout()
self.vboxlayout3.setObjectName("vboxlayout3")
self.label_5 = QtGui.QLabel(Dialog)
self.label_5.setObjectName("label_5")
self.vboxlayout3.addWidget(self.label_5)
self.hboxlayout4 = QtGui.QHBoxLayout()
self.hboxlayout4.setObjectName("hboxlayout4")
self.outShape = QtGui.QLineEdit(Dialog)
self.outShape.setReadOnly(True)
self.outShape.setObjectName("outShape")
self.hboxlayout4.addWidget(self.outShape)
self.btnBrowse = QtGui.QPushButton(Dialog)
self.btnBrowse.setObjectName("btnBrowse")
self.hboxlayout4.addWidget(self.btnBrowse)
self.vboxlayout3.addLayout(self.hboxlayout4)
self.gridlayout.addLayout(self.vboxlayout3,6,0,1,2)
self.gridLayout.addLayout(self.vboxlayout3, 9, 0, 1, 2)
self.progressBar = QtGui.QProgressBar(Dialog)
self.progressBar.setProperty("value",QtCore.QVariant(0))
self.progressBar.setProperty("value", QtCore.QVariant(0))
self.progressBar.setAlignment(QtCore.Qt.AlignCenter)
self.progressBar.setOrientation(QtCore.Qt.Horizontal)
self.progressBar.setObjectName("progressBar")
self.gridlayout.addWidget(self.progressBar,7,0,1,1)
self.gridLayout.addWidget(self.progressBar, 10, 0, 1, 1)
self.buttonBox_2 = QtGui.QDialogButtonBox(Dialog)
self.buttonBox_2.setStandardButtons(QtGui.QDialogButtonBox.Close|QtGui.QDialogButtonBox.Ok)
self.buttonBox_2.setObjectName("buttonBox_2")
self.gridlayout.addWidget(self.buttonBox_2,7,1,1,1)
self.gridLayout.addWidget(self.buttonBox_2, 10, 1, 1, 1)
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.useSelectedA = QtGui.QCheckBox(Dialog)
self.useSelectedA.setObjectName("useSelectedA")
self.verticalLayout.addWidget(self.useSelectedA)
self.gridLayout.addLayout(self.verticalLayout, 2, 0, 1, 1)
self.verticalLayout_2 = QtGui.QVBoxLayout()
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.useSelectedB = QtGui.QCheckBox(Dialog)
self.useSelectedB.setObjectName("useSelectedB")
self.verticalLayout_2.addWidget(self.useSelectedB)
self.gridLayout.addLayout(self.verticalLayout_2, 4, 0, 1, 1)
self.retranslateUi(Dialog)
QtCore.QObject.connect(self.rdoField,QtCore.SIGNAL("toggled(bool)"),self.attrib.setEnabled)
QtCore.QObject.connect(self.rdoBuffer,QtCore.SIGNAL("toggled(bool)"),self.param.setEnabled)
QtCore.QObject.connect(self.buttonBox_2,QtCore.SIGNAL("rejected()"),Dialog.reject)
QtCore.QObject.connect(self.buttonBox_2,QtCore.SIGNAL("accepted()"),Dialog.accept)
QtCore.QObject.connect(self.rdoField, QtCore.SIGNAL("toggled(bool)"), self.attrib.setEnabled)
QtCore.QObject.connect(self.rdoBuffer, QtCore.SIGNAL("toggled(bool)"), self.param.setEnabled)
QtCore.QObject.connect(self.buttonBox_2, QtCore.SIGNAL("rejected()"), Dialog.reject)
QtCore.QObject.connect(self.buttonBox_2, QtCore.SIGNAL("accepted()"), Dialog.accept)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
@ -179,4 +159,6 @@ class Ui_Dialog(object):
self.mergeOutput.setText(QtGui.QApplication.translate("Dialog", "Dissolve buffer results", None, QtGui.QApplication.UnicodeUTF8))
self.label_5.setText(QtGui.QApplication.translate("Dialog", "Output shapefile", None, QtGui.QApplication.UnicodeUTF8))
self.btnBrowse.setText(QtGui.QApplication.translate("Dialog", "Browse", None, QtGui.QApplication.UnicodeUTF8))
self.useSelectedA.setText(QtGui.QApplication.translate("Dialog", "Use only selected features", None, QtGui.QApplication.UnicodeUTF8))
self.useSelectedB.setText(QtGui.QApplication.translate("Dialog", "Use only selected features", None, QtGui.QApplication.UnicodeUTF8))

View File

@ -40,7 +40,7 @@
</item>
</layout>
</item>
<item row="1" column="0" colspan="2" >
<item row="3" column="0" colspan="2" >
<layout class="QVBoxLayout" >
<item>
<widget class="QLabel" name="label_2" >
@ -61,7 +61,7 @@
</item>
</layout>
</item>
<item row="2" column="0" colspan="2" >
<item row="5" column="0" colspan="2" >
<layout class="QHBoxLayout" >
<item>
<layout class="QHBoxLayout" >
@ -101,7 +101,7 @@
</item>
</layout>
</item>
<item row="3" column="0" colspan="2" >
<item row="6" column="0" colspan="2" >
<layout class="QVBoxLayout" >
<item>
<layout class="QHBoxLayout" >
@ -149,7 +149,7 @@
</item>
</layout>
</item>
<item row="4" column="0" >
<item row="7" column="0" >
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
@ -169,7 +169,7 @@
</item>
</layout>
</item>
<item row="5" column="0" >
<item row="8" column="0" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
@ -182,7 +182,7 @@
</property>
</spacer>
</item>
<item row="6" column="0" colspan="2" >
<item row="9" column="0" colspan="2" >
<layout class="QVBoxLayout" >
<item>
<widget class="QLabel" name="label_5" >
@ -211,7 +211,7 @@
</item>
</layout>
</item>
<item row="7" column="0" >
<item row="10" column="0" >
<widget class="QProgressBar" name="progressBar" >
<property name="value" >
<number>0</number>
@ -224,13 +224,35 @@
</property>
</widget>
</item>
<item row="7" column="1" >
<item row="10" column="1" >
<widget class="QDialogButtonBox" name="buttonBox_2" >
<property name="standardButtons" >
<set>QDialogButtonBox::Close|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="2" column="0" >
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<widget class="QCheckBox" name="useSelectedA" >
<property name="text" >
<string>Use only selected features</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0" >
<layout class="QVBoxLayout" name="verticalLayout_2" >
<item>
<widget class="QCheckBox" name="useSelectedB" >
<property name="text" >
<string>Use only selected features</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>

View File

@ -2,8 +2,8 @@
# Form implementation generated from reading ui file 'frmVisual.ui'
#
# Created: Tue Apr 21 15:10:47 2009
# by: PyQt4 UI code generator 4.4.3
# Created: Tue May 26 18:55:54 2009
# by: PyQt4 UI code generator 4.4.4
#
# WARNING! All changes made in this file will be lost!
@ -13,7 +13,7 @@ class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.setWindowModality(QtCore.Qt.NonModal)
Dialog.resize(374, 485)
Dialog.resize(404, 485)
Dialog.setSizeGripEnabled(True)
self.gridLayout = QtGui.QGridLayout(Dialog)
self.gridLayout.setObjectName("gridLayout")
@ -34,7 +34,7 @@ class Ui_Dialog(object):
self.cmbField = QtGui.QComboBox(Dialog)
self.cmbField.setObjectName("cmbField")
self.vboxlayout1.addWidget(self.cmbField)
self.gridLayout.addLayout(self.vboxlayout1, 1, 0, 1, 2)
self.gridLayout.addLayout(self.vboxlayout1, 4, 0, 1, 2)
self.vboxlayout2 = QtGui.QVBoxLayout()
self.vboxlayout2.setObjectName("vboxlayout2")
self.label_2 = QtGui.QLabel(Dialog)
@ -49,7 +49,7 @@ class Ui_Dialog(object):
self.lstUnique.setSelectionRectVisible(True)
self.lstUnique.setObjectName("lstUnique")
self.vboxlayout2.addWidget(self.lstUnique)
self.gridLayout.addLayout(self.vboxlayout2, 2, 0, 1, 2)
self.gridLayout.addLayout(self.vboxlayout2, 5, 0, 1, 2)
self.hboxlayout = QtGui.QHBoxLayout()
self.hboxlayout.setObjectName("hboxlayout")
self.label_4 = QtGui.QLabel(Dialog)
@ -59,17 +59,23 @@ class Ui_Dialog(object):
self.lstCount.setReadOnly(True)
self.lstCount.setObjectName("lstCount")
self.hboxlayout.addWidget(self.lstCount)
self.gridLayout.addLayout(self.hboxlayout, 3, 0, 1, 2)
self.gridLayout.addLayout(self.hboxlayout, 6, 0, 1, 2)
self.progressBar = QtGui.QProgressBar(Dialog)
self.progressBar.setProperty("value", QtCore.QVariant(24))
self.progressBar.setAlignment(QtCore.Qt.AlignCenter)
self.progressBar.setObjectName("progressBar")
self.gridLayout.addWidget(self.progressBar, 4, 0, 1, 1)
self.gridLayout.addWidget(self.progressBar, 7, 0, 1, 1)
self.buttonBox_2 = QtGui.QDialogButtonBox(Dialog)
self.buttonBox_2.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox_2.setStandardButtons(QtGui.QDialogButtonBox.Close|QtGui.QDialogButtonBox.Ok)
self.buttonBox_2.setObjectName("buttonBox_2")
self.gridLayout.addWidget(self.buttonBox_2, 4, 1, 1, 1)
self.gridLayout.addWidget(self.buttonBox_2, 7, 1, 1, 1)
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.useSelected = QtGui.QCheckBox(Dialog)
self.useSelected.setObjectName("useSelected")
self.verticalLayout.addWidget(self.useSelected)
self.gridLayout.addLayout(self.verticalLayout, 3, 0, 1, 1)
self.retranslateUi(Dialog)
QtCore.QObject.connect(self.buttonBox_2, QtCore.SIGNAL("accepted()"), Dialog.accept)
@ -83,4 +89,5 @@ class Ui_Dialog(object):
self.label_2.setText(QtGui.QApplication.translate("Dialog", "Unique values list", None, QtGui.QApplication.UnicodeUTF8))
self.lstUnique.setSortingEnabled(True)
self.label_4.setText(QtGui.QApplication.translate("Dialog", "Unique value count", None, QtGui.QApplication.UnicodeUTF8))
self.useSelected.setText(QtGui.QApplication.translate("Dialog", "Use only selected features", None, QtGui.QApplication.UnicodeUTF8))

View File

@ -1,126 +1,138 @@
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog" >
<property name="windowModality" >
<widget class="QDialog" name="Dialog">
<property name="windowModality">
<enum>Qt::NonModal</enum>
</property>
<property name="geometry" >
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>374</width>
<width>404</width>
<height>485</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string>List Unique Values</string>
</property>
<property name="sizeGripEnabled" >
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout" >
<item row="0" column="0" colspan="2" >
<layout class="QVBoxLayout" >
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<layout class="QVBoxLayout">
<item>
<widget class="QLabel" name="label_3" >
<property name="text" >
<widget class="QLabel" name="label_3">
<property name="text">
<string>Input Vector Layer</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="inShape" />
<widget class="QComboBox" name="inShape"/>
</item>
</layout>
</item>
<item row="1" column="0" colspan="2" >
<layout class="QVBoxLayout" >
<item row="4" column="0" colspan="2">
<layout class="QVBoxLayout">
<item>
<widget class="QLabel" name="label" >
<property name="text" >
<widget class="QLabel" name="label">
<property name="text">
<string>Target field</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cmbField" />
<widget class="QComboBox" name="cmbField"/>
</item>
</layout>
</item>
<item row="2" column="0" colspan="2" >
<layout class="QVBoxLayout" >
<item row="5" column="0" colspan="2">
<layout class="QVBoxLayout">
<item>
<widget class="QLabel" name="label_2" >
<property name="text" >
<widget class="QLabel" name="label_2">
<property name="text">
<string>Unique values list</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="lstUnique" >
<property name="editTriggers" >
<widget class="QListWidget" name="lstUnique">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="showDropIndicator" stdset="0" >
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="alternatingRowColors" >
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode" >
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="selectionBehavior" >
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="selectionRectVisible" >
<property name="selectionRectVisible">
<bool>true</bool>
</property>
<property name="sortingEnabled" >
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0" colspan="2" >
<layout class="QHBoxLayout" >
<item row="6" column="0" colspan="2">
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="label_4" >
<property name="text" >
<widget class="QLabel" name="label_4">
<property name="text">
<string>Unique value count</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lstCount" >
<property name="readOnly" >
<widget class="QLineEdit" name="lstCount">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0" >
<widget class="QProgressBar" name="progressBar" >
<property name="value" >
<item row="7" column="0">
<widget class="QProgressBar" name="progressBar">
<property name="value">
<number>24</number>
</property>
<property name="alignment" >
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="4" column="1" >
<widget class="QDialogButtonBox" name="buttonBox_2" >
<property name="orientation" >
<item row="7" column="1">
<widget class="QDialogButtonBox" name="buttonBox_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<property name="standardButtons">
<set>QDialogButtonBox::Close|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="3" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="useSelected">
<property name="text">
<string>Use only selected features</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
@ -131,11 +143,11 @@
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>133</x>
<y>276</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>215</x>
<y>290</y>
</hint>
@ -147,11 +159,11 @@
<receiver>Dialog</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel" >
<hint type="sourcelabel">
<x>59</x>
<y>276</y>
</hint>
<hint type="destinationlabel" >
<hint type="destinationlabel">
<x>132</x>
<y>239</y>
</hint>

View File

@ -19,6 +19,7 @@
# addShapeToCanvas( QString *file path )
# getUniqueValues( QgsVectorDataProvider, int *field id )
# saveDialog( QWidget *parent )
# getFieldType( QgsVectorLayer, QgsField.name() )
#
# -------------------------------------------------
@ -260,3 +261,9 @@ def saveDialog( parent ):
settings.setValue("/UI/lastShapefileDir", QVariant( QFileInfo( unicode( files.first() ) ).absolutePath() ) )
return ( unicode( files.first() ), unicode( fileDialog.encoding() ) )
# Return field type from it's name
def getFieldType(vlayer, fieldName):
fields = vlayer.dataProvider().fields()
for name, field in fields.iteritems():
if field.name() == fieldName:
return field.typeName()