Skip to content
Permalink
Browse files

Merge pull request #731 from ddanielvaz/bugfix-6063

Preserve attributes in Convex Hull (fix #6063)
  • Loading branch information
alexbruy committed Sep 12, 2013
2 parents 885c8b4 + 8a50ddb commit 033440fcfe9e9c46a0fa75de7c76561e1864f282
Showing with 30 additions and 16 deletions.
  1. +28 −15 python/plugins/fTools/tools/doGeoprocessing.py
  2. +2 −1 python/plugins/fTools/tools/ftools_utils.py
@@ -467,13 +467,17 @@ def convex_hull(self, useField ):
GEOS_EXCEPT = True
FEATURE_EXCEPT = True
vproviderA = self.vlayerA.dataProvider()
# creating fields
idField = QgsField("outID", QVariant.String)
#
outFeatFields = QgsFields()
if useField:
importedField = vproviderA.fields().at( self.myParam )
importedFieldName = importedField.name( )
#
outFeatFields.extend( vproviderA.fields() )
# creating area and perimeter fields
areaField = QgsField("area", QVariant.Double)
perimField = QgsField("perim", QVariant.Double)
# appending fields
outFeatFields = QgsFields()
outFeatFields.append(idField)
outFeatFields.append(areaField)
outFeatFields.append(perimField)
#
@@ -501,15 +505,14 @@ def convex_hull(self, useField ):
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
for i in unique:
hull = []
first = True
outID = 0
hull = []
for inFeat in selectionA:
atMap = inFeat.attributes()
idVar = atMap[ self.myParam ]
if idVar == i:
if first:
outID = idVar
firstFeature = QgsFeature( inFeat )
first = False
inGeom = QgsGeometry( inFeat.geometry() )
points = ftools_utils.extractPoints( inGeom )
@@ -522,7 +525,8 @@ def convex_hull(self, useField ):
outGeom = tmpGeom.convexHull()
outFeat.setGeometry( outGeom )
(area, perim) = self.simpleMeasure( outGeom )
outFeat.setAttribute( "outID", outID )
for f in firstFeature.fields():
outFeat.setAttribute( f.name( ), firstFeature.attribute( f.name( ) ) )
outFeat.setAttribute( "area", area )
outFeat.setAttribute( "perim", perim )
writer.addFeature( outFeat )
@@ -543,6 +547,11 @@ def convex_hull(self, useField ):
try:
outGeom = tmpGeom.convexHull()
outFeat.setGeometry( outGeom )
(area, perim) = self.simpleMeasure( outGeom )
for f in inFeat.fields():
outFeat.setAttribute( f.name( ), inFeat.attribute( f.name( ) ) )
outFeat.setAttribute( "area", area )
outFeat.setAttribute( "perim", perim )
writer.addFeature( outFeat )
except:
GEOS_EXCEPT = False
@@ -554,18 +563,16 @@ def convex_hull(self, useField ):
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

hull = []
fitA = vproviderA.getFeatures()
while fitA.nextFeature( inFeat ):
atMap = inFeat.attributes()
idVar = atMap[ self.myParam ]
idVar = inFeat.attribute( importedFieldName )
if idVar == i:
if first:
outID = idVar
firstFeature = QgsFeature( inFeat )
first = False
inGeom = QgsGeometry( inFeat.geometry() )
points = ftools_utils.extractPoints( inGeom )
@@ -578,7 +585,8 @@ def convex_hull(self, useField ):
outGeom = tmpGeom.convexHull()
outFeat.setGeometry( outGeom )
(area, perim) = self.simpleMeasure( outGeom )
outFeat.setAttribute( "outID", outID )
for f in firstFeature.fields():
outFeat.setAttribute( f.name( ), firstFeature.attribute( f.name( ) ) )
outFeat.setAttribute( "area", area )
outFeat.setAttribute( "perim", perim )
writer.addFeature( outFeat )
@@ -600,6 +608,11 @@ def convex_hull(self, useField ):
try:
outGeom = tmpGeom.convexHull()
outFeat.setGeometry( outGeom )
(area, perim) = self.simpleMeasure( outGeom )
for f in inFeat.fields():
outFeat.setAttribute( f.name( ), inFeat.attribute( f.name( ) ) )
outFeat.setAttribute( "area", area )
outFeat.setAttribute( "perim", perim )
writer.addFeature( outFeat )
except:
GEOS_EXCEPT = False
@@ -132,7 +132,7 @@ def extractPoints( geom ):
temp_geom = geom.asMultiPoint()
else:
temp_geom.append(geom.asPoint())
if geom.type() == 1: # it's a line
elif geom.type() == 1: # it's a line
if geom.isMultipart():
multi_geom = geom.asMultiPolyline() #multi_geog is a multiline
for i in multi_geom: #i is a line
@@ -149,6 +149,7 @@ def extractPoints( geom ):
multi_geom = geom.asPolygon() #multi_geom is a polygon
for i in multi_geom: #i is a line
temp_geom.extend( i )
# FIXME - if there is none of know geoms (point, line, polygon) show an warning message
return temp_geom

# Check if two input field maps are unique, and resolve name issues if they aren't

0 comments on commit 033440f

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