1
- from sextante .outputs .Output import Output
2
- from qgis .core import *
3
1
from PyQt4 .QtCore import *
4
- from sextante .core .GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
5
2
6
- class OutputVector (Output ):
3
+ from sextante .outputs .Output import Output
4
+ from sextante .core .SextanteVectorWriter import SextanteVectorWriter
7
5
8
- MEMORY_LAYER_PREFIX = "memory:"
6
+ class OutputVector ( Output ):
9
7
10
8
def getFileFilter (self ,alg ):
11
9
exts = alg .provider .getSupportedOutputVectorLayerExtensions ()
@@ -17,50 +15,26 @@ def getDefaultFileExtension(self, alg):
17
15
return alg .provider .getSupportedOutputVectorLayerExtensions ()[0 ]
18
16
19
17
def getVectorWriter (self , fields , geomType , crs , options = None ):
20
- '''Returns a suitable writer to which features can be added as a result of the algorithm.
21
- Use this to transparently handle output values instead of creating your own method.
22
- Parameters:
23
- -field: an array with the fields of the attributes table or dict of int-QgsField
24
- -geomType: A suitable geometry type, as it would be passed to a QgsVectorFileWriter constructor
25
- -crs: the crs of the layer to create.
26
- Executing this method might modify the object, adding additional information to it, so the writer
27
- can be later accessed and processed within QGIS.
28
- It should be called just once, since a new call might result in previous data being replaced,
29
- thus rendering a previously obtained writer useless'''
18
+ '''Returns a suitable writer to which features can be added as a
19
+ result of the algorithm. Use this to transparently handle output
20
+ values instead of creating your own method.
21
+
22
+ Executing this method might modify the object, adding additional
23
+ information to it, so the writer can be later accessed and processed
24
+ within QGIS. It should be called just once, since a new call might
25
+ result in previous data being replaced, thus rendering a previously
26
+ obtained writer useless
27
+
28
+ @param fields a dict of int-QgsField
29
+ @param geomType a suitable geometry type, as it would be passed
30
+ to a QgsVectorFileWriter constructor
31
+ @param crs the crs of the layer to create
32
+
33
+ @return writer instance of the vectoe writer class
34
+ '''
30
35
31
- if self .value .startswith (self .MEMORY_LAYER_PREFIX ):
32
- if isinstance (fields , dict ):
33
- fields = fields .values ()
34
- types = { QGis .WKBPoint : "Point" , QGis .WKBLineString : "Point" , QGis .WKBPolygon : "Polygon" ,
35
- QGis .WKBMultiPoint : "MultiPoint" , QGis .WKBMultiLineString : "MultiLineString" , QGis .WKBMultiPolygon : "MultiPolygon" ,}
36
- v = QgsVectorLayer (types [geomType ], self .description , "memory" )
37
- pr = v .dataProvider ()
38
- pr .addAttributes (fields )
39
- v .startEditing ()
40
- self .memoryLayer = v #keep a reference to the writer
41
- return v
42
- else : #outputChannel is a file path
43
- #TODO: Add support for encodings
44
- check = QFile (self .value )
45
- if check .exists ():
46
- if not QgsVectorFileWriter .deleteShapeFile (self .value ):
47
- raise GeoAlgorithmExecutionException ("Could not delete existing output file" )
48
- formats = QgsVectorFileWriter .supportedFiltersAndFormats ()
49
- OGRCodes = {}
50
- for key ,value in formats .items ():
51
- extension = str (key )
52
- extension = extension [extension .find ('*.' ) + 2 :]
53
- extension = extension [:extension .find (" " )]
54
- OGRCodes [extension ] = value
55
- if isinstance (fields , dict ):
56
- fieldsDict = fields
57
- else :
58
- fieldsDict = {}
59
- i = 0
60
- for field in fields :
61
- fieldsDict [i ] = field
62
- i += 1
63
- settings = QSettings ()
64
- systemEncoding = settings .value ( "/UI/encoding" , "System" ).toString ()
65
- extension = self .value [self .value .find ("." )+ 1 :]
66
- return QgsVectorFileWriter (self .value , systemEncoding , fieldsDict , geomType , crs , OGRCodes [extension ] )
36
+ settings = QSettings ()
37
+ encoding = settings .value ( "/UI/encoding" , "System" ).toString ()
38
+ w = SextanteVectorWriter (self .value , encoding , fields , geomType , crs , options )
39
+ self .memoryLayer = w .memLayer
40
+ return w
0 commit comments