Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Added support for non-file-based output channels
Changed GUI elements accordingly Only Ftools's Convex hull algorithm has been changed to support this. All other native algorithms have to be adapted git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@343 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
- Loading branch information
volayaf
committed
Aug 10, 2012
1 parent
1433a12
commit 24406ab
Showing
8 changed files
with
124 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -34,3 +34,6 @@ def getIcon(self): | ||
|
||
def _loadAlgorithms(self): | ||
self.algs = self.alglist | ||
|
||
def supportsNonFileBasedOutput(self): | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,55 @@ | ||
from sextante.outputs.Output import Output | ||
from qgis.core import * | ||
from PyQt4.QtCore import * | ||
|
||
class OutputVector(Output): | ||
|
||
MEMORY_LAYER_PREFIX = "memory:" | ||
|
||
def getFileFilter(self,alg): | ||
exts = alg.provider.getSupportedOutputVectorLayerExtensions() | ||
for i in range(len(exts)): | ||
exts[i] = exts[i].upper() + " files(*." + exts[i].lower() + ")" | ||
return ";;".join(exts) | ||
|
||
def getDefaultFileExtension(self, alg): | ||
return alg.provider.getSupportedOutputVectorLayerExtensions()[0] | ||
return alg.provider.getSupportedOutputVectorLayerExtensions()[0] | ||
|
||
def getVectorWriter(self, fields, geomType, crs, options=None): | ||
'''Returns a suitable writer to which features can be added as a result of the algorithm. | ||
Use this to transparently handle output values instead of creating your own method. | ||
Parameters: | ||
-field: an array with the fields of the attributes table | ||
-geomType: A suitable geometry type, as it would be passed to a QgsVectorFileWriter constructor | ||
-crs: the crs of the layer to create. | ||
Executing this method might modify the object, adding additional information to it, so the writer | ||
can be later accessed and processed within QGIS. | ||
It should be called just once, since a new call might result in previous data being replaced, | ||
thus rendering a previously obtained writer useless''' | ||
|
||
if self.value.startswith(self.MEMORY_LAYER_PREFIX): | ||
types = { QGis.WKBPoint : "Point", QGis.WKBLineString : "Point", QGis.WKBPolygon : "Polygon", | ||
QGis.WKBMultiPoint : "MultiPoint", QGis.WKBMultiLineString : "MultiLineString", QGis.WKBMultiPolygon : "MultiPolygon",} | ||
v = QgsVectorLayer(types[geomType], self.description, "memory") | ||
pr = v.dataProvider() | ||
pr.addAttributes(fields) | ||
self.memoryLayer = v #keep a reference to the writer | ||
return v | ||
else: #outputChannel is a file path | ||
#TODO: Add support for encodings | ||
formats = QgsVectorFileWriter.supportedFiltersAndFormats() | ||
OGRCodes = {} | ||
for key,value in formats.items(): | ||
extension = str(key) | ||
extension = extension[extension.find('*.') + 2:] | ||
extension = extension[:extension.find(" ")] | ||
OGRCodes[extension] = value | ||
fieldsDict = {} | ||
i = 0 | ||
for field in fields: | ||
fieldsDict[i] = field | ||
i += 1 | ||
settings = QSettings() | ||
systemEncoding = settings.value( "/UI/encoding", "System" ).toString() | ||
extension = self.value[self.value.find(".")+1:] | ||
return QgsVectorFileWriter(self.value, systemEncoding, fieldsDict, geomType, crs, OGRCodes[extension] ) |