Skip to content
Permalink
Browse files

[processing] more cleanups (follow up 06c4b07)

  • Loading branch information
alexbruy committed Aug 5, 2016
1 parent 45c8a09 commit acdde31b3dc4c8ba9ddd1ee60e4ae4579ba1922d
@@ -96,10 +96,11 @@ def processAlgorithm(self, progress):
# directly
settings = QSettings()
systemEncoding = settings.value('/UI/encoding', 'System')
provider = vectorLayer.dataProvider()
writer = QgsVectorFileWriter(output, systemEncoding,
provider.fields(),
provider.wkbType(), provider.crs())
writer = QgsVectorFileWriter(output,
systemEncoding,
vectorLayer.fields(),
vectorLayer.wkbType(),
vectorLayer.crs())

# Now we take the features from input layer and add them to the
# output. Method features() returns an iterator, considering the
@@ -9,10 +9,9 @@
from processing.tools.vector import VectorWriter

layer = processing.getObject(input)
provider = layer.dataProvider()
fields = provider.fields()
fields = layer.fields()
fields.append(QgsField('UNIQ_COUNT', QVariant.Int))
writer = VectorWriter(N_unique_values, None, fields, provider.wkbType(),
writer = VectorWriter(N_unique_values, None, fields, layer.wkbType(),
layer.crs())

class_field_index = layer.fieldNameIndex(class_field)
@@ -273,10 +273,9 @@ def convertUnsupportedFormats(self, progress):
# For the case of memory layer, if the
# getCompatible method has been called
continue
provider = layer.dataProvider()
writer = out.getVectorWriter(
provider.fields(),
provider.wkbType(), layer.crs()
layer.fields(),
layer.wkbType(), layer.crs()
)
features = vector.features(layer)
for feature in features:
@@ -312,8 +311,7 @@ def convertUnsupportedFormats(self, progress):
elif isinstance(out, OutputTable):
if out.compatible is not None:
layer = dataobjects.getObjectFromUri(out.compatible)
provider = layer.dataProvider()
writer = out.getTableWriter(provider.fields())
writer = out.getTableWriter(layer.fields())
features = vector.features(layer)
for feature in features:
writer.addRecord(feature)
@@ -64,13 +64,12 @@ def runalgIterating(alg, paramToIter, progress):
feat = QgsFeature()
filelist = []
outputs = {}
provider = layer.dataProvider()
features = vector.features(layer)
for feat in features:
output = getTempFilename('shp')
filelist.append(output)
writer = QgsVectorFileWriter(output, systemEncoding,
provider.fields(), provider.wkbType(), layer.crs())
layer.fields(), layer.wkbType(), layer.crs())
writer.addFeature(feat)
del writer

@@ -471,7 +471,7 @@ def getFields(self, layer, datatype):
QVariant.UInt, QVariant.ULongLong]

fieldNames = set()
for field in layer.pendingFields():
for field in layer.fields():
if not fieldTypes or field.type() in fieldTypes:
fieldNames.add(unicode(field.name()))
return sorted(list(fieldNames), cmp=locale.strcoll)
@@ -294,8 +294,8 @@ def exportVectorLayer(layer, supported=None):
useSelection = ProcessingConfig.getSetting(ProcessingConfig.USE_SELECTED)
if useSelection and layer.selectedFeatureCount() != 0:
writer = QgsVectorFileWriter(output, systemEncoding,
layer.pendingFields(),
provider.wkbType(), layer.crs())
layer.fields(),
layer.wkbType(), layer.crs())
selection = layer.selectedFeatures()
for feat in selection:
writer.addFeature(feat)
@@ -310,7 +310,7 @@ def exportVectorLayer(layer, supported=None):
if not os.path.splitext(layer.source())[1].lower() in supported or not isASCII:
writer = QgsVectorFileWriter(
output, systemEncoding,
layer.pendingFields(), provider.wkbType(),
layer.fields(), layer.wkbType(),
layer.crs()
)
for feat in layer.getFeatures():
@@ -354,7 +354,6 @@ def exportTable(table):
settings = QSettings()
systemEncoding = settings.value('/UI/encoding', 'System')
output = getTempFilename()
provider = table.dataProvider()
isASCII = True
try:
unicode(table.source()).decode('ascii')
@@ -364,7 +363,7 @@ def exportTable(table):
or unicode(table.source()).endswith('shp')
if not isDbf or not isASCII:
writer = QgsVectorFileWriter(output, systemEncoding,
provider.fields(), QgsWkbTypes.NullGeometry,
layer.fields(), QgsWkbTypes.NullGeometry,
QgsCoordinateReferenceSystem('4326'))
for feat in table.getFeatures():
writer.addFeature(feat)
@@ -316,10 +316,10 @@ def combineVectorFields(layerA, layerB):
"""Create single field map from two input field maps.
"""
fields = []
fieldsA = layerA.pendingFields()
fieldsA = layerA.fields()
fields.extend(fieldsA)
namesA = [unicode(f.name()).lower() for f in fieldsA]
fieldsB = layerB.pendingFields()
fieldsB = layerB.fields()
for field in fieldsB:
name = unicode(field.name()).lower()
if name in namesA:
@@ -366,7 +366,7 @@ def duplicateInMemory(layer, newName='', addToRegistry=False):
memProvider = memLayer.dataProvider()

provider = layer.dataProvider()
fields = provider.fields().toList()
fields = layer.fields().toList()
memProvider.addAttributes(fields)
memLayer.updateFields()

0 comments on commit acdde31

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