Skip to content

Commit

Permalink
fTools: fix add/export geometry columns
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Feb 5, 2013
1 parent 96a8bd6 commit b35a456
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions python/plugins/fTools/tools/doGeometry.py
Expand Up @@ -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():
Expand All @@ -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 )

Expand Down

0 comments on commit b35a456

Please sign in to comment.