Skip to content
Permalink
Browse files

[processing] fix VectorWriter class (fix #11875)

  • Loading branch information
alexbruy committed Dec 18, 2014
1 parent e31027c commit 69fe922a5403d84e28857959903e473afa7f19e5
Showing with 25 additions and 17 deletions.
  1. +25 −17 python/plugins/processing/tools/vector.py
@@ -35,6 +35,24 @@
from processing.core.ProcessingConfig import ProcessingConfig


GEOM_TYPE_MAP = {
QGis.WKBPoint: 'Point',
QGis.WKBLineString: 'LineString',
QGis.WKBPolygon: 'Polygon',
QGis.WKBMultiPoint: 'MultiPoint',
QGis.WKBMultiLineString: 'MultiLineString',
QGis.WKBMultiPolygon: 'MultiPolygon',
}


TYPE_MAP = {
str : QVariant.String,
float: QVariant.Double,
int: QVariant.Int,
bool: QVariant.Bool
}


def features(layer):
"""This returns an iterator over features in a vector layer,
considering the selection that might exist in the layer, and the
@@ -128,6 +146,7 @@ def values(layer, *attributes):
ret[attr] = values
return ret


def testForUniqueness( fieldList1, fieldList2 ):
'''Returns a modified version of fieldList2, removing naming
collisions with fieldList1.'''
@@ -143,6 +162,7 @@ def testForUniqueness( fieldList1, fieldList2 ):
changed = True
return fieldList2


def spatialindex(layer):
"""Creates a spatial index for the passed vector layer.
"""
@@ -176,6 +196,7 @@ def found(name):
if not found(newname):
return newname


def findOrCreateField(layer, fieldList, fieldName, fieldLen=24, fieldPrec=15):
idx = layer.fieldNameIndex(fieldName)
if idx == -1:
@@ -328,6 +349,7 @@ def duplicateInMemory(layer, newName='', addToRegistry=False):

return memLayer


def checkMinDistance(point, index, distance, points):
"""Check if distance from given point to all other points is greater
than given value.
@@ -346,37 +368,23 @@ def checkMinDistance(point, index, distance, points):

return True

GEOM_TYPE_MAP = {
QGis.WKBPoint: 'Point',
QGis.WKBLineString: 'LineString',
QGis.WKBPolygon: 'Polygon',
QGis.WKBMultiPoint: 'MultiPoint',
QGis.WKBMultiLineString: 'MultiLineString',
QGis.WKBMultiPolygon: 'MultiPolygon',
}

TYPE_MAP = {
str : QVariant.String,
float: QVariant.Double,
int: QVariant.Int,
bool: QVariant.Bool
}

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


def _toQgsField(f):
if isinstance(f, QgsField):
return f
return QgsField(f[0], TYPE_MAP.get(f[1], QVariant.String))


class VectorWriter:

MEMORY_LAYER_PREFIX = 'memory:'


def __init__(self, fileName, encoding, fields, geometryType,
crs, options=None):
self.fileName = fileName
@@ -391,7 +399,7 @@ def __init__(self, fileName, encoding, fields, geometryType,
if self.fileName.startswith(self.MEMORY_LAYER_PREFIX):
self.isMemory = True

uri = self.GEOM_TYPE_MAP[geometryType]
uri = GEOM_TYPE_MAP[geometryType]
if crs.isValid():
uri += '?crs=' + crs.authid() + '&'
fieldsdesc = ['field=' + _fieldName(f) for f in fields]

0 comments on commit 69fe922

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