Skip to content

Commit

Permalink
[processing] fix VectorWriter class (fix #11875)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Dec 18, 2014
1 parent e31027c commit 69fe922
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions python/plugins/processing/tools/vector.py
Expand Up @@ -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
Expand Down Expand Up @@ -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.'''
Expand All @@ -143,6 +162,7 @@ def testForUniqueness( fieldList1, fieldList2 ):
changed = True
return fieldList2


def spatialindex(layer):
"""Creates a spatial index for the passed vector layer.
"""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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]
Expand Down

0 comments on commit 69fe922

Please sign in to comment.