mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -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
|
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):
|
def features(layer):
|
||||||
"""This returns an iterator over features in a vector layer,
|
"""This returns an iterator over features in a vector layer,
|
||||||
considering the selection that might exist in the layer, and the
|
considering the selection that might exist in the layer, and the
|
||||||
@ -128,6 +146,7 @@ def values(layer, *attributes):
|
|||||||
ret[attr] = values
|
ret[attr] = values
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def testForUniqueness( fieldList1, fieldList2 ):
|
def testForUniqueness( fieldList1, fieldList2 ):
|
||||||
'''Returns a modified version of fieldList2, removing naming
|
'''Returns a modified version of fieldList2, removing naming
|
||||||
collisions with fieldList1.'''
|
collisions with fieldList1.'''
|
||||||
@ -143,6 +162,7 @@ def testForUniqueness( fieldList1, fieldList2 ):
|
|||||||
changed = True
|
changed = True
|
||||||
return fieldList2
|
return fieldList2
|
||||||
|
|
||||||
|
|
||||||
def spatialindex(layer):
|
def spatialindex(layer):
|
||||||
"""Creates a spatial index for the passed vector layer.
|
"""Creates a spatial index for the passed vector layer.
|
||||||
"""
|
"""
|
||||||
@ -176,6 +196,7 @@ def createUniqueFieldName(fieldName, fieldList):
|
|||||||
if not found(newname):
|
if not found(newname):
|
||||||
return newname
|
return newname
|
||||||
|
|
||||||
|
|
||||||
def findOrCreateField(layer, fieldList, fieldName, fieldLen=24, fieldPrec=15):
|
def findOrCreateField(layer, fieldList, fieldName, fieldLen=24, fieldPrec=15):
|
||||||
idx = layer.fieldNameIndex(fieldName)
|
idx = layer.fieldNameIndex(fieldName)
|
||||||
if idx == -1:
|
if idx == -1:
|
||||||
@ -328,6 +349,7 @@ def duplicateInMemory(layer, newName='', addToRegistry=False):
|
|||||||
|
|
||||||
return memLayer
|
return memLayer
|
||||||
|
|
||||||
|
|
||||||
def checkMinDistance(point, index, distance, points):
|
def checkMinDistance(point, index, distance, points):
|
||||||
"""Check if distance from given point to all other points is greater
|
"""Check if distance from given point to all other points is greater
|
||||||
than given value.
|
than given value.
|
||||||
@ -346,37 +368,23 @@ def checkMinDistance(point, index, distance, points):
|
|||||||
|
|
||||||
return True
|
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):
|
def _fieldName(f):
|
||||||
if isinstance(f, basestring):
|
if isinstance(f, basestring):
|
||||||
return f
|
return f
|
||||||
return f.name()
|
return f.name()
|
||||||
|
|
||||||
|
|
||||||
def _toQgsField(f):
|
def _toQgsField(f):
|
||||||
if isinstance(f, QgsField):
|
if isinstance(f, QgsField):
|
||||||
return f
|
return f
|
||||||
return QgsField(f[0], TYPE_MAP.get(f[1], QVariant.String))
|
return QgsField(f[0], TYPE_MAP.get(f[1], QVariant.String))
|
||||||
|
|
||||||
|
|
||||||
class VectorWriter:
|
class VectorWriter:
|
||||||
|
|
||||||
MEMORY_LAYER_PREFIX = 'memory:'
|
MEMORY_LAYER_PREFIX = 'memory:'
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, fileName, encoding, fields, geometryType,
|
def __init__(self, fileName, encoding, fields, geometryType,
|
||||||
crs, options=None):
|
crs, options=None):
|
||||||
self.fileName = fileName
|
self.fileName = fileName
|
||||||
@ -391,7 +399,7 @@ class VectorWriter:
|
|||||||
if self.fileName.startswith(self.MEMORY_LAYER_PREFIX):
|
if self.fileName.startswith(self.MEMORY_LAYER_PREFIX):
|
||||||
self.isMemory = True
|
self.isMemory = True
|
||||||
|
|
||||||
uri = self.GEOM_TYPE_MAP[geometryType]
|
uri = GEOM_TYPE_MAP[geometryType]
|
||||||
if crs.isValid():
|
if crs.isValid():
|
||||||
uri += '?crs=' + crs.authid() + '&'
|
uri += '?crs=' + crs.authid() + '&'
|
||||||
fieldsdesc = ['field=' + _fieldName(f) for f in fields]
|
fieldsdesc = ['field=' + _fieldName(f) for f in fields]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user