@@ -59,30 +59,44 @@ def createInstance(self, config={}):
59
59
def createCustomParametersWidget (self , parent ):
60
60
return GdalAlgorithmDialog (self )
61
61
62
- def getConsoleCommands (self , parameters , context , feedback ):
62
+ def getConsoleCommands (self , parameters , context , feedback , executing = True ):
63
63
return None
64
64
65
- def getOgrCompatibleSource (self , parameter_name , parameters , context , feedback ):
65
+ def getOgrCompatibleSource (self , parameter_name , parameters , context , feedback , executing ):
66
66
"""
67
67
Interprets a parameter as an OGR compatible source and layer name
68
+ :param executing:
68
69
"""
69
70
input_layer = self .parameterAsVectorLayer (parameters , parameter_name , context )
70
71
ogr_data_path = None
71
72
ogr_layer_name = None
72
73
if input_layer is None :
73
- # parameter is not a vector layer - try to convert to a source compatible with OGR
74
- # and extract selection if required
75
- ogr_data_path = self .parameterAsCompatibleSourceLayerPath (parameters , parameter_name , context ,
76
- QgsVectorFileWriter .supportedFormatExtensions (),
77
- feedback = feedback )
78
- ogr_layer_name = GdalUtils .ogrLayerName (ogr_data_path )
74
+ if executing :
75
+ # parameter is not a vector layer - try to convert to a source compatible with OGR
76
+ # and extract selection if required
77
+ ogr_data_path = self .parameterAsCompatibleSourceLayerPath (parameters , parameter_name , context ,
78
+ QgsVectorFileWriter .supportedFormatExtensions (),
79
+ feedback = feedback )
80
+ ogr_layer_name = GdalUtils .ogrLayerName (ogr_data_path )
81
+ else :
82
+ #not executing - don't waste time converting incompatible sources, just return dummy strings
83
+ #for the command preview (since the source isn't compatible with OGR, it has no meaning anyway and can't
84
+ #be run directly in the command line)
85
+ ogr_data_path = 'path_to_data_file'
86
+ ogr_layer_name = 'layer_name'
79
87
elif input_layer .dataProvider ().name () == 'ogr' :
80
- # parameter is a vector layer, with OGR data provider
81
- # so extract selection if required
82
- ogr_data_path = self .parameterAsCompatibleSourceLayerPath (parameters , parameter_name , context ,
83
- QgsVectorFileWriter .supportedFormatExtensions (),
84
- feedback = feedback )
85
- ogr_layer_name = GdalUtils .ogrLayerName (input_layer .dataProvider ().dataSourceUri ())
88
+ if executing :
89
+ # parameter is a vector layer, with OGR data provider
90
+ # so extract selection if required
91
+ ogr_data_path = self .parameterAsCompatibleSourceLayerPath (parameters , parameter_name , context ,
92
+ QgsVectorFileWriter .supportedFormatExtensions (),
93
+ feedback = feedback )
94
+ ogr_layer_name = GdalUtils .ogrLayerName (input_layer .dataProvider ().dataSourceUri ())
95
+ else :
96
+ #not executing - don't worry about 'selected features only' handling. It has no meaning
97
+ #for the command line preview since it has no meaning outside of a QGIS session!
98
+ ogr_data_path = GdalUtils .ogrConnectionString (input_layer .dataProvider ().dataSourceUri (), context )[1 :- 1 ]
99
+ ogr_layer_name = GdalUtils .ogrLayerName (input_layer .dataProvider ().dataSourceUri ())
86
100
else :
87
101
# vector layer, but not OGR - get OGR compatible path
88
102
# TODO - handle "selected features only" mode!!
@@ -94,7 +108,7 @@ def setOutputValue(self, name, value):
94
108
self .output_values [name ] = value
95
109
96
110
def processAlgorithm (self , parameters , context , feedback ):
97
- commands = self .getConsoleCommands (parameters , context , feedback )
111
+ commands = self .getConsoleCommands (parameters , context , feedback , executing = True )
98
112
GdalUtils .runGdal (commands , feedback )
99
113
100
114
# auto generate outputs
0 commit comments