Skip to content

Commit f340ca0

Browse files
committed
commit
1 parent 1db8347 commit f340ca0

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

python/plugins/fTools/tools/doGeoprocessing.py

+34-14
Original file line numberDiff line numberDiff line change
@@ -463,16 +463,25 @@ def convex_hull(self, useField ):
463463
GEOS_EXCEPT = True
464464
FEATURE_EXCEPT = True
465465
vproviderA = self.vlayerA.dataProvider()
466+
#
467+
outFeatFields = QgsFields()
468+
if useField:
469+
importedField = vproviderA.fields().at( self.myParam )
470+
outFeatFields.append( importedField )
471+
#
472+
importedFieldName = importedField.name( )
473+
else:
474+
outIdField = QgsField( "hullGeneratedID", QVariant.String )
475+
outFeatFields.append( outIdField )
466476
# creating fields
467-
idField = QgsField("outID", QVariant.String)
468477
areaField = QgsField("area", QVariant.Double)
469478
perimField = QgsField("perim", QVariant.Double)
470479
# appending fields
471-
outFeatFields = QgsFields()
472-
outFeatFields.append(idField)
473480
outFeatFields.append(areaField)
474481
outFeatFields.append(perimField)
475482
#
483+
outFeatFields.extend( vproviderA.fields() )
484+
#
476485
writer = QgsVectorFileWriter( self.myName, self.myEncoding, outFeatFields,
477486
QGis.WKBPolygon, vproviderA.crs() )
478487
if writer.hasError():
@@ -497,15 +506,14 @@ def convex_hull(self, useField ):
497506
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
498507
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
499508
for i in unique:
500-
hull = []
501509
first = True
502-
outID = 0
510+
hull = []
503511
for inFeat in selectionA:
504512
atMap = inFeat.attributes()
505513
idVar = atMap[ self.myParam ]
506514
if idVar == i:
507515
if first:
508-
outID = idVar
516+
firstFeature = QgsFeature( inFeat )
509517
first = False
510518
inGeom = QgsGeometry( inFeat.geometry() )
511519
points = ftools_utils.extractPoints( inGeom )
@@ -518,7 +526,8 @@ def convex_hull(self, useField ):
518526
outGeom = tmpGeom.convexHull()
519527
outFeat.setGeometry( outGeom )
520528
(area, perim) = self.simpleMeasure( outGeom )
521-
outFeat.setAttribute( "outID", outID )
529+
for f in firstFeature.fields():
530+
outFeat.setAttribute( f.name( ), firstFeature.attribute( f.name( ) ) )
522531
outFeat.setAttribute( "area", area )
523532
outFeat.setAttribute( "perim", perim )
524533
writer.addFeature( outFeat )
@@ -539,6 +548,12 @@ def convex_hull(self, useField ):
539548
try:
540549
outGeom = tmpGeom.convexHull()
541550
outFeat.setGeometry( outGeom )
551+
(area, perim) = self.simpleMeasure( outGeom )
552+
for f in inFeat.fields():
553+
outFeat.setAttribute( f.name( ), inFeat.attribute( f.name( ) ) )
554+
outFeat.setAttribute( "hullGeneratedID", 'hullPolygonGenerated' )
555+
outFeat.setAttribute( "area", area )
556+
outFeat.setAttribute( "perim", perim )
542557
writer.addFeature( outFeat )
543558
except:
544559
GEOS_EXCEPT = False
@@ -550,18 +565,16 @@ def convex_hull(self, useField ):
550565
nFeat = nFeat * len( unique )
551566
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 0 )
552567
self.emit( SIGNAL( "runRange(PyQt_PyObject)" ), ( 0, nFeat ) )
568+
553569
for i in unique:
554-
hull = []
555570
first = True
556-
outID = 0
557-
571+
hull = []
558572
fitA = vproviderA.getFeatures()
559573
while fitA.nextFeature( inFeat ):
560-
atMap = inFeat.attributes()
561-
idVar = atMap[ self.myParam ]
574+
idVar = inFeat.attribute( importedFieldName )
562575
if idVar == i:
563576
if first:
564-
outID = idVar
577+
firstFeature = QgsFeature( inFeat )
565578
first = False
566579
inGeom = QgsGeometry( inFeat.geometry() )
567580
points = ftools_utils.extractPoints( inGeom )
@@ -574,7 +587,8 @@ def convex_hull(self, useField ):
574587
outGeom = tmpGeom.convexHull()
575588
outFeat.setGeometry( outGeom )
576589
(area, perim) = self.simpleMeasure( outGeom )
577-
outFeat.setAttribute( "outID", outID )
590+
for f in firstFeature.fields():
591+
outFeat.setAttribute( f.name( ), firstFeature.attribute( f.name( ) ) )
578592
outFeat.setAttribute( "area", area )
579593
outFeat.setAttribute( "perim", perim )
580594
writer.addFeature( outFeat )
@@ -596,6 +610,12 @@ def convex_hull(self, useField ):
596610
try:
597611
outGeom = tmpGeom.convexHull()
598612
outFeat.setGeometry( outGeom )
613+
(area, perim) = self.simpleMeasure( outGeom )
614+
for f in inFeat.fields():
615+
outFeat.setAttribute( f.name( ), inFeat.attribute( f.name( ) ) )
616+
outFeat.setAttribute( "hullGeneratedID", 'hullPolygonGenerated' )
617+
outFeat.setAttribute( "area", area )
618+
outFeat.setAttribute( "perim", perim )
599619
writer.addFeature( outFeat )
600620
except:
601621
GEOS_EXCEPT = False

python/plugins/fTools/tools/ftools_utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def extractPoints( geom ):
132132
temp_geom = geom.asMultiPoint()
133133
else:
134134
temp_geom.append(geom.asPoint())
135-
if geom.type() == 1: # it's a line
135+
elif geom.type() == 1: # it's a line
136136
if geom.isMultipart():
137137
multi_geom = geom.asMultiPolyline() #multi_geog is a multiline
138138
for i in multi_geom: #i is a line
@@ -149,6 +149,7 @@ def extractPoints( geom ):
149149
multi_geom = geom.asPolygon() #multi_geom is a polygon
150150
for i in multi_geom: #i is a line
151151
temp_geom.extend( i )
152+
# FIXME - if there is none of know geoms (point, line, polygon) show an warning message
152153
return temp_geom
153154

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

0 commit comments

Comments
 (0)