Skip to content
Permalink
Browse files

commit

  • Loading branch information
ddanielvaz committed Jul 14, 2013
1 parent 1db8347 commit f340ca01f7d692d66965704dcd56914c2173cf4b
Showing with 36 additions and 15 deletions.
  1. +34 −14 python/plugins/fTools/tools/doGeoprocessing.py
  2. +2 −1 python/plugins/fTools/tools/ftools_utils.py
@@ -463,16 +463,25 @@ def convex_hull(self, useField ):
GEOS_EXCEPT = True
FEATURE_EXCEPT = True
vproviderA = self.vlayerA.dataProvider()
#
outFeatFields = QgsFields()
if useField:
importedField = vproviderA.fields().at( self.myParam )
outFeatFields.append( importedField )
#
importedFieldName = importedField.name( )
else:
outIdField = QgsField( "hullGeneratedID", QVariant.String )
outFeatFields.append( outIdField )
# creating fields
idField = QgsField("outID", QVariant.String)
areaField = QgsField("area", QVariant.Double)
perimField = QgsField("perim", QVariant.Double)
# appending fields
outFeatFields = QgsFields()
outFeatFields.append(idField)
outFeatFields.append(areaField)
outFeatFields.append(perimField)
#
outFeatFields.extend( vproviderA.fields() )
#
writer = QgsVectorFileWriter( self.myName, self.myEncoding, outFeatFields,
QGis.WKBPolygon, vproviderA.crs() )
if writer.hasError():
@@ -497,15 +506,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 )
@@ -518,7 +526,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 )
@@ -539,6 +548,12 @@ 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( "hullGeneratedID", 'hullPolygonGenerated' )
outFeat.setAttribute( "area", area )
outFeat.setAttribute( "perim", perim )
writer.addFeature( outFeat )
except:
GEOS_EXCEPT = False
@@ -550,18 +565,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 )
@@ -574,7 +587,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 )
@@ -596,6 +610,12 @@ 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( "hullGeneratedID", 'hullPolygonGenerated' )
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 f340ca0

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