Skip to content

Commit b35a456

Browse files
committed
fTools: fix add/export geometry columns
1 parent 96a8bd6 commit b35a456

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

python/plugins/fTools/tools/doGeometry.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ def perimMeasure( self, inGeom, measure ):
998998
value = value + measure.measureLine( k )
999999
return value
10001000

1001-
def doubleFieldIndex( self, name, desc, fieldList, f ):
1001+
def doubleFieldIndex( self, name, desc, fieldList ):
10021002
i = 0
10031003
for f in fieldList:
10041004
if name == f.name().toUpper():
@@ -1011,20 +1011,25 @@ def doubleFieldIndex( self, name, desc, fieldList, f ):
10111011
def checkMeasurementFields( self, vlayer, add ):
10121012
vprovider = vlayer.dataProvider()
10131013
geomType = vlayer.geometryType()
1014+
fieldList = vprovider.fields()
1015+
1016+
idx = len(fieldList)
10141017

10151018
if geomType == QGis.Polygon:
1016-
(index1, fieldList) = doubleFieldIndex( "AREA", self.tr( "Polygon area" ), fieldList )
1017-
(index2, fieldList) = doubleFieldIndex( "PERIMETER", self.tr( "Polygon perimeter" ), fieldList )
1019+
(index1, fieldList) = self.doubleFieldIndex( "AREA", self.tr( "Polygon area" ), fieldList )
1020+
(index2, fieldList) = self.doubleFieldIndex( "PERIMETER", self.tr( "Polygon perimeter" ), fieldList )
10181021
elif geomType == QGis.Line:
1019-
(index1, fieldList) = doubleFieldIndex( "LENGTH", self.tr( "Line length" ), fieldList )
1022+
(index1, fieldList) = self.doubleFieldIndex( "LENGTH", self.tr( "Line length" ), fieldList )
10201023
index2 = index1
10211024
else:
1022-
(index1, fieldList) = doubleFieldIndex( "XCOORD", self.tr( "Point x ordinate" ), fieldList )
1023-
(index2, fieldList) = doubleFieldIndex( "YCOORD", self.tr( "Point y ordinate" ), fieldList )
1025+
(index1, fieldList) = self.doubleFieldIndex( "XCOORD", self.tr( "Point x ordinate" ), fieldList )
1026+
(index2, fieldList) = self.doubleFieldIndex( "YCOORD", self.tr( "Point y ordinate" ), fieldList )
10241027

1025-
if add:
1028+
if add and idx<len(fieldList):
1029+
newFields = []
1030+
for i in range(idx,len(fieldList)):
1031+
newFields.append(fieldList[i])
10261032
vprovider.addAttributes( newFields )
1027-
vlayer.updateFieldMap()
10281033

10291034
return ( fieldList, index1, index2 )
10301035

0 commit comments

Comments
 (0)