Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] fixed attribute types in memory layers
fixes #12894
  • Loading branch information
volaya committed Jun 23, 2015
1 parent 0bbc11b commit 38a247f
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions python/plugins/processing/tools/vector.py
Expand Up @@ -52,6 +52,11 @@
bool: QVariant.Bool
}

TYPE_MAP_MEMORY_LAYER = {
QVariant.String: "string",
QVariant.Double: "double",
QVariant.Int: "integer"
}

def features(layer):
"""This returns an iterator over features in a vector layer,
Expand Down Expand Up @@ -369,12 +374,6 @@ def checkMinDistance(point, index, distance, points):
return True


def _fieldName(f):
if isinstance(f, basestring):
return f
return f.name()


def _toQgsField(f):
if isinstance(f, QgsField):
return f
Expand Down Expand Up @@ -402,10 +401,13 @@ def __init__(self, fileName, encoding, fields, geometryType,
uri = GEOM_TYPE_MAP[geometryType] + "?uuid=" + str(uuid.uuid4())
if crs.isValid():
uri += '&crs=' + crs.authid()

fieldsdesc = ['field=' + _fieldName(f) for f in fields]
fieldsdesc = []
for f in fields:
qgsfield = _toQgsField(f)
fieldsdesc.append('field=%s:%s' %(qgsfield.name(),
TYPE_MAP_MEMORY_LAYER.get(qgsfield.type(), "string")))
if fieldsdesc:
uri += '&' + '&'.join(fieldsdesc)
uri += '&' + '&'.join(fieldsdesc)

self.memLayer = QgsVectorLayer(uri, self.fileName, 'memory')
self.writer = self.memLayer.dataProvider()
Expand Down

0 comments on commit 38a247f

Please sign in to comment.