Skip to content
Permalink
Browse files
[sextante]Replaced provider.crs() by layer.crs(). Fixed memory layer …
…usage
  • Loading branch information
volaya committed Feb 24, 2013
1 parent ce8d79c commit 3e6c803f9dfcc81779ce00d75b037079d6d3f20b
Showing with 41 additions and 43 deletions.
  1. +1 −1 python/plugins/sextante/algs/AddTableField.py
  2. +1 −1 python/plugins/sextante/algs/AutoincrementalField.py
  3. +1 −1 python/plugins/sextante/algs/EquivalentNumField.py
  4. +1 −1 python/plugins/sextante/algs/Explode.py
  5. +1 −1 python/plugins/sextante/algs/FieldPyculator.py
  6. +1 −1 python/plugins/sextante/algs/FieldsCalculator.py
  7. +1 −1 python/plugins/sextante/algs/JoinAttributes.py
  8. +1 −1 python/plugins/sextante/algs/SaveSelectedFeatures.py
  9. +1 −1 python/plugins/sextante/algs/ftools/Centroids.py
  10. +1 −1 python/plugins/sextante/algs/ftools/Delaunay.py
  11. +1 −1 python/plugins/sextante/algs/ftools/ExportGeometryInfo.py
  12. +1 −1 python/plugins/sextante/algs/ftools/ExtractNodes.py
  13. +1 −1 python/plugins/sextante/algs/ftools/FixedDistanceBuffer.py
  14. +1 −1 python/plugins/sextante/algs/ftools/LinesToPolygons.py
  15. +1 −1 python/plugins/sextante/algs/ftools/MeanCoords.py
  16. +1 −1 python/plugins/sextante/algs/ftools/MultipartToSingleparts.py
  17. +1 −1 python/plugins/sextante/algs/ftools/SimplifyGeometries.py
  18. +1 −1 python/plugins/sextante/algs/ftools/SinglePartsToMultiparts.py
  19. +1 −4 python/plugins/sextante/algs/ftools/Union.py
  20. +1 −1 python/plugins/sextante/algs/mmqgisx/MMQGISXAlgorithms.py
  21. +1 −1 python/plugins/sextante/core/GeoAlgorithm.py
  22. +3 −3 python/plugins/sextante/core/LayerExporter.py
  23. +6 −5 python/plugins/sextante/core/SextanteVectorWriter.py
  24. +1 −1 python/plugins/sextante/gui/AlgorithmExecutor.py
  25. +1 −1 python/plugins/sextante/gui/UnthreadedAlgorithmExecutor.py
  26. +5 −5 python/plugins/sextante/script/scripts/Number_of_unique_values_in_classes.py
  27. +1 −1 python/plugins/sextante/script/scripts/Save_selected_features.py
  28. +3 −3 python/plugins/sextante/script/scripts/Split_vector_layer_by_attribute.py
@@ -64,7 +64,7 @@ def processAlgorithm(self, progress):
vprovider = vlayer.dataProvider()
fields = vprovider.fields()
fields.append(QgsField(fieldname, self.TYPES[fieldtype]))
writer = output.getVectorWriter(fields, vprovider.geometryType(), vprovider.crs() )
writer = output.getVectorWriter(fields, vprovider.geometryType(), vlayer.crs() )
outFeat = QgsFeature()
inGeom = QgsGeometry()
nElement = 0
@@ -46,7 +46,7 @@ def processAlgorithm(self, progress):
vprovider = vlayer.dataProvider()
fields = vprovider.fields()
fields[len(fields)] = QgsField("AUTO", QVariant.Int)
writer = output.getVectorWriter(fields, vprovider.geometryType(), vprovider.crs() )
writer = output.getVectorWriter(fields, vprovider.geometryType(), vlayer.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
@@ -50,7 +50,7 @@ def processAlgorithm(self, progress):
fieldindex = vlayer.fieldNameIndex(fieldname)
fields = vprovider.fields()
fields.append(QgsField("NUM_FIELD", QVariant.Int))
writer = output.getVectorWriter(fields, vprovider.geometryType(), vprovider.crs() )
writer = output.getVectorWriter(fields, vprovider.geometryType(), vlayer.crs() )
outFeat = QgsFeature()
inGeom = QgsGeometry()
nElement = 0
@@ -46,7 +46,7 @@ def processAlgorithm(self, progress):
output = self.getOutputFromName(self.OUTPUT)
vprovider = vlayer.dataProvider()
fields = vprovider.fields()
writer = output.getVectorWriter(fields, QGis.WKBLineString, vprovider.crs() )
writer = output.getVectorWriter(fields, QGis.WKBLineString, vlayer.crs() )
outFeat = QgsFeature()
inGeom = QgsGeometry()
nElement = 0
@@ -69,7 +69,7 @@ def processAlgorithm(self, progress):
vprovider = layer.dataProvider()
fields = vprovider.fields()
fields.append(QgsField(fieldname, QVariant.Double))
writer = output.getVectorWriter(fields, vprovider.geometryType(), vprovider.crs() )
writer = output.getVectorWriter(fields, vprovider.geometryType(), layer.crs() )
outFeat = QgsFeature()
new_ns = {}

@@ -61,7 +61,7 @@ def processAlgorithm(self, progress):
vprovider = vlayer.dataProvider()
fields = vprovider.fields()
fields.append(QgsField(fieldname, QVariant.Double))
writer = output.getVectorWriter(fields, vprovider.geometryType(), vprovider.crs())
writer = output.getVectorWriter(fields, vprovider.geometryType(), vlayer.crs())
outFeat = QgsFeature()
inGeom = QgsGeometry()
nFeat = vprovider.featureCount()
@@ -72,7 +72,7 @@ def processAlgorithm(self, progress):
outFields.extend(provider.fields())
outFields.extend(provider2.fields())

writer = output.getVectorWriter(outFields, provider.geometryType(), provider.crs())
writer = output.getVectorWriter(outFields, provider.geometryType(), layer.crs())

inFeat = QgsFeature()
inFeat2 = QgsFeature()
@@ -85,7 +85,7 @@ def processAlgorithm(self, progress):
#To do so, we call the getVectorWriter method in the Output object.
#That will give as a SextanteVectorWriter, that we can later use to add features.
provider = vectorLayer.dataProvider()
writer = output.getVectorWriter( provider.fields(), provider.geometryType(), provider.crs() )
writer = output.getVectorWriter( provider.fields(), provider.geometryType(), vectorLayer.crs() )

#Now we take the selected features and add them to the output layer
features = QGisLayers.features(vectorLayer)
@@ -56,7 +56,7 @@ def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT_LAYER))

writer = self.getOutputFromName(self.OUTPUT_LAYER).getVectorWriter(layer.pendingFields(),
QGis.WKBPoint, layer.dataProvider().crs())
QGis.WKBPoint, layer.crs())

#layer.select(layer.pendingAllAttributesList())

@@ -63,7 +63,7 @@ def processAlgorithm(self, progress):
]

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields,
QGis.WKBPolygon, layer.dataProvider().crs())
QGis.WKBPolygon, layer.crs())

pts = []
ptDict = {}
@@ -78,7 +78,7 @@ def processAlgorithm(self, progress):
fields.append(QgsField(QString("ycoords"), QVariant.Double))

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fields,
provider.geometryType(), provider.crs())
provider.geometryType(), layer.crs())

ellips = None
crs = None
@@ -56,7 +56,7 @@ def processAlgorithm(self, progress):
provider = layer.dataProvider()

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
QGis.WKBPoint, provider.crs())
QGis.WKBPoint, layer.crs())

outFeat = QgsFeature()
inGeom = QgsGeometry()
@@ -70,7 +70,7 @@ def processAlgorithm(self, progress):

provider = layer.dataProvider()
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
QGis.WKBPolygon, provider.crs())
QGis.WKBPolygon, layer.crs())

buff.buffering(progress, writer, distance, None, False,
layer, dissolve, segments)
@@ -52,7 +52,7 @@ def processAlgorithm(self, progress):
provider = layer.dataProvider()

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
QGis.WKBPolygon, provider.crs())
QGis.WKBPolygon, layer.crs())

outFeat = QgsFeature()

@@ -78,7 +78,7 @@ def processAlgorithm(self, progress):
]

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fieldList,
QGis.WKBPoint, provider.crs())
QGis.WKBPoint, layer.crs())

current = 0
total = 100.0 / float(provider.featureCount() * len(uniqueValues))
@@ -60,7 +60,7 @@ def processAlgorithm(self, progress):
geomType = self.multiToSingleGeom(provider.geometryType())

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
geomType, provider.crs())
geomType, layer.crs())

outFeat = QgsFeature()
inGeom = QgsGeometry()
@@ -65,7 +65,7 @@ def processAlgorithm(self, progress):
provider = layer.dataProvider()

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
layer.wkbType(), provider.crs())
layer.wkbType(), layer.crs())

current = 0
selection = QGisLayers.features(layer)
@@ -65,7 +65,7 @@ def processAlgorithm(self, progress):
geomType = self.singleToMultiGeom(provider.geometryType())

writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
geomType, provider.crs())
geomType, layer.crs())

inFeat = QgsFeature()
outFeat = QgsFeature()
@@ -54,10 +54,7 @@ def processAlgorithm(self, progress):

fields = utils.combineVectorFields(vlayerA, vlayerB )
names = [field.name() for field in fields]
SextanteLog.addToLog(SextanteLog.LOG_INFO, str(names))
#longNames = ftools_utils.checkFieldNameLength( fields )
#if not longNames.isEmpty():
#raise GeoAlgorithmExecutionException("Following field names are longer than 10 characters:\n" + longNames.join('\n') )
SextanteLog.addToLog(SextanteLog.LOG_INFO, str(names))
writer = self.getOutputFromName(Union.OUTPUT).getVectorWriter(fields, vproviderA.geometryType(), vproviderA.crs() )
inFeatA = QgsFeature()
inFeatB = QgsFeature()
@@ -803,7 +803,7 @@ def processAlgorithm(self, progress):
for feature in features:
source = feature.geometry().boundingBox().center()
distance = QgsDistanceArea()
distance.setSourceCrs(layersource.dataProvider().crs().srsid())
distance.setSourceCrs(layersource.crs().srsid())
distance.setEllipsoidalMode(True)

closest = hubs[0]
@@ -198,7 +198,7 @@ def convertUnsupportedFormats(self, progress):
if layer is None: # for the case of memory layer, if the getCompatible method has been called
continue
provider = layer.dataProvider()
writer = out.getVectorWriter( provider.fields(), provider.geometryType(), provider.crs())
writer = out.getVectorWriter( provider.fields(), provider.geometryType(), layer.crs())
features = QGisLayers.features(layer)
for feature in features:
writer.addFeature(feature)
@@ -52,7 +52,7 @@ def exportVectorLayer(layer):
provider = layer.dataProvider()
useSelection = SextanteConfig.getSetting(SextanteConfig.USE_SELECTED)
if useSelection and layer.selectedFeatureCount() != 0:
writer = QgsVectorFileWriter(output, systemEncoding, layer.pendingFields(), provider.geometryType(), provider.crs())
writer = QgsVectorFileWriter(output, systemEncoding, layer.pendingFields(), provider.geometryType(), layer.crs())
selection = layer.selectedFeatures()
for feat in selection:
writer.addFeature(feat)
@@ -65,7 +65,7 @@ def exportVectorLayer(layer):
except UnicodeEncodeError:
isASCII=False
if (not unicode(layer.source()).endswith("shp") or not isASCII):
writer = QgsVectorFileWriter( output, systemEncoding, layer.pendingFields(), provider.geometryType(), provider.crs() )
writer = QgsVectorFileWriter( output, systemEncoding, layer.pendingFields(), provider.geometryType(), layer.crs() )
for feat in layer.getFeatures():
writer.addFeature(feat)
del writer
@@ -108,7 +108,7 @@ def exportTable( table):
isASCII=False
isDbf = unicode(table.source()).endswith("dbf") or unicode(table.source()).endswith("shp")
if (not isDbf or not isASCII):
writer = QgsVectorFileWriter( output, systemEncoding, provider.fields(), QGis.WKBNoGeometry, provider.crs() )
writer = QgsVectorFileWriter( output, systemEncoding, provider.fields(), QGis.WKBNoGeometry, layer.crs() )
for feat in table.getFeatures():
writer.addFeature(feat)
del writer
@@ -54,12 +54,13 @@ def __init__(self, fileName, encoding, fields, geometryType, crs, options=None):

uri = self.TYPE_MAP[geometryType]
if crs.isValid():
uri += "?crs=" + crs.authid()
uri += "?crs=" + crs.authid() + "&"
fieldsdesc = ["field=" + str(f.name()) for f in fields]
#+ ":" + str(f.typeName())
fieldsstring = "&".join(fieldsdesc)
uri += fieldsstring
self.memLayer = QgsVectorLayer(uri, self.fileName, "memory")
self.writer = self.memLayer.dataProvider()
# FIXME: addAttributes was deprecated and removed
self.writer.addAttributes(fields.values())
self.memLayer.updateFieldMap()
self.writer = self.memLayer.dataProvider()
else:
formats = QgsVectorFileWriter.supportedFiltersAndFormats()
OGRCodes = {}
@@ -81,7 +81,7 @@ def setConsoleInfo(self, info):
while provider.nextFeature(feat):
output = SextanteUtils.getTempFilename("shp")
self.filelist.append(output)
writer = QgsVectorFileWriter(output, systemEncoding,provider.fields(), provider.geometryType(), provider.crs() )
writer = QgsVectorFileWriter(output, systemEncoding,provider.fields(), provider.geometryType(), layer.crs() )
writer.addFeature(feat)
del writer
else:
@@ -64,7 +64,7 @@ def runalgIterating(alg,paramToIter,progress):
while provider.nextFeature(feat):
output = SextanteUtils.getTempFilename("shp")
filelist.append(output)
writer = QgsVectorFileWriter(output, systemEncoding,provider.fields(), provider.geometryType(), provider.crs() )
writer = QgsVectorFileWriter(output, systemEncoding,provider.fields(), provider.geometryType(), layer.crs() )
writer.addFeature(feat)
del writer

@@ -39,11 +39,11 @@

# "input" contains the location of the selected layer.
# We get the actual object, so we can get its bounds
layer = getobject(input)
layer = sextante.getobject(input)
provider = layer.dataProvider()
fields = provider.fields()
fields.append(QgsField("UNIQ_COUNT", QVariant.Int))
writer = SextanteVectorWriter(output, None, fields, provider.geometryType(), provider.crs() )
writer = SextanteVectorWriter(output, None, fields, provider.geometryType(), layer.crs() )

# Fields are defined by their names, but QGIS needs the index for the attributes map
class_field_index = layer.fieldNameIndex(class_field)
@@ -57,8 +57,8 @@

#Iterate over input layer to count unique values in each class

feats = getfeatures(layer)
nFeat = len(feates)
feats = sextante.getfeatures(layer)
nFeat = len(feats)
for inFeat in feats:
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
@@ -71,7 +71,7 @@
classes[clazz].append(value)

# Create output vector layer with additional attribute
feats = getfeatures(layer)
feats = sextante.getfeatures(layer)
nElement = 0
for inFeat in feats:
progress.setPercentage(int((100 * nElement)/nFeat))
@@ -54,7 +54,7 @@
#First we create the output layer.
#To do so, we create a SextanteVectorWriter, that we can later use to add features.
provider = vectorLayer.dataProvider()
writer = SextanteVectorWriter(output, None, provider.fields(), provider.geometryType(), provider.crs() )
writer = SextanteVectorWriter(output, None, provider.fields(), provider.geometryType(), layer.crs() )

#Now we take the selected features and add them to the output layer
selection = vectorLayer.selectedFeatures()
@@ -38,7 +38,7 @@

# "input" contains the location of the selected layer.
# We get the actual object,
layer = getobject(input)
layer = sextante.getobject(input)
provider = layer.dataProvider()
allAttrs = provider.attributeIndexes()
provider.select( allAttrs )
@@ -54,7 +54,7 @@
nElement = 0
writers = {}

feats = getfeatures(layer)
feats = sextante.getfeatures(layer)
nFeat = len(feats)
for inFeat in feats:
progress.setPercentage(int((100 * nElement)/nFeat))
@@ -63,7 +63,7 @@
clazz = atMap[class_field_index].toString()
if clazz not in writers:
outputFile = output + "_" + str(len(writers)) + ".shp"
writers[clazz] = SextanteVectorWriter(outputFile, None, fields, provider.geometryType(), provider.crs() )
writers[clazz] = SextanteVectorWriter(outputFile, None, fields, provider.geometryType(), layer.crs() )
inGeom = inFeat.geometry()
outFeat.setGeometry(inGeom)
outFeat.setAttributes(atMap)

0 comments on commit 3e6c803

Please sign in to comment.