mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
[processing] fix VectorWriter class (fix #11875)
This commit is contained in:
parent
e31027c840
commit
69fe922a54
@ -35,6 +35,24 @@ from qgis.core import *
|
||||
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 createUniqueFieldName(fieldName, fieldList):
|
||||
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 @@ class VectorWriter:
|
||||
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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user