Skip to content
Permalink
Browse files
fTools: fix add/export geometry columns
  • Loading branch information
jef-n committed Feb 5, 2013
1 parent 96a8bd6 commit b35a45625f55ca94dd1826f3b152fedbb21019ac
Showing with 13 additions and 8 deletions.
  1. +13 −8 python/plugins/fTools/tools/doGeometry.py
@@ -998,7 +998,7 @@ def perimMeasure( self, inGeom, measure ):
value = value + measure.measureLine( k )
return value

def doubleFieldIndex( self, name, desc, fieldList, f ):
def doubleFieldIndex( self, name, desc, fieldList ):
i = 0
for f in fieldList:
if name == f.name().toUpper():
@@ -1011,20 +1011,25 @@ def doubleFieldIndex( self, name, desc, fieldList, f ):
def checkMeasurementFields( self, vlayer, add ):
vprovider = vlayer.dataProvider()
geomType = vlayer.geometryType()
fieldList = vprovider.fields()

idx = len(fieldList)

if geomType == QGis.Polygon:
(index1, fieldList) = doubleFieldIndex( "AREA", self.tr( "Polygon area" ), fieldList )
(index2, fieldList) = doubleFieldIndex( "PERIMETER", self.tr( "Polygon perimeter" ), fieldList )
(index1, fieldList) = self.doubleFieldIndex( "AREA", self.tr( "Polygon area" ), fieldList )
(index2, fieldList) = self.doubleFieldIndex( "PERIMETER", self.tr( "Polygon perimeter" ), fieldList )
elif geomType == QGis.Line:
(index1, fieldList) = doubleFieldIndex( "LENGTH", self.tr( "Line length" ), fieldList )
(index1, fieldList) = self.doubleFieldIndex( "LENGTH", self.tr( "Line length" ), fieldList )
index2 = index1
else:
(index1, fieldList) = doubleFieldIndex( "XCOORD", self.tr( "Point x ordinate" ), fieldList )
(index2, fieldList) = doubleFieldIndex( "YCOORD", self.tr( "Point y ordinate" ), fieldList )
(index1, fieldList) = self.doubleFieldIndex( "XCOORD", self.tr( "Point x ordinate" ), fieldList )
(index2, fieldList) = self.doubleFieldIndex( "YCOORD", self.tr( "Point y ordinate" ), fieldList )

if add:
if add and idx<len(fieldList):
newFields = []
for i in range(idx,len(fieldList)):
newFields.append(fieldList[i])
vprovider.addAttributes( newFields )
vlayer.updateFieldMap()

return ( fieldList, index1, index2 )

0 comments on commit b35a456

Please sign in to comment.