31
31
from widgetPluginBase import GdalToolsBasePluginWidget as BasePluginWidget
32
32
import GdalTools_utils as Utils
33
33
34
-
35
34
class GdalToolsDialog (QWidget , Ui_Widget , BasePluginWidget ):
36
35
37
36
def __init__ (self , iface ):
@@ -46,12 +45,18 @@ def __init__(self, iface):
46
45
self .extentSelector .setCanvas (self .canvas )
47
46
self .outputFormat = Utils .fillRasterOutputFormat ()
48
47
48
+ # set the default QDoubleSpinBoxes
49
+ self .xRes .setValue (12.5 )
50
+ self .yRes .setValue (12.5 )
51
+
49
52
self .setParamsStatus ([
50
53
(self .inSelector , SIGNAL ("filenameChanged()" )),
51
54
(self .outSelector , SIGNAL ("filenameChanged()" )),
52
55
(self .noDataSpin , SIGNAL ("valueChanged(int)" ), self .noDataCheck , 1700 ),
53
56
(self .maskSelector , SIGNAL ("filenameChanged()" ), self .maskModeRadio , 1600 ),
54
- (self .alphaBandCheck , SIGNAL ("stateChanged( int )" )),
57
+ (self .alphaBandCheck , SIGNAL ("stateChanged(int)" )),
58
+ (self .cropToCutlineCheck , SIGNAL ("stateChanged(int)" )),
59
+ ([self .xRes , self .yRes ], SIGNAL ("valueChanged(double)" ), self .setResolutionRadio ),
55
60
(self .extentSelector , [SIGNAL ("selectionStarted()" ), SIGNAL ("newExtentDefined()" )], self .extentModeRadio ),
56
61
(self .modeStackedWidget , SIGNAL ("currentIndexChanged(int)" ))
57
62
])
@@ -63,9 +68,11 @@ def __init__(self, iface):
63
68
self .connect (self .extentSelector , SIGNAL ("selectionStarted()" ), self .checkRun )
64
69
65
70
self .connect (self .extentModeRadio , SIGNAL ("toggled(bool)" ), self .switchClippingMode )
71
+ self .connect (self .keepResolutionRadio , SIGNAL ("toggled(bool)" ), self .switchResolutionMode )
66
72
67
73
def show_ (self ):
68
74
self .switchClippingMode ()
75
+ self .switchResolutionMode ()
69
76
BasePluginWidget .show_ (self )
70
77
71
78
def onClosing (self ):
@@ -82,6 +89,12 @@ def switchClippingMode(self):
82
89
self .modeStackedWidget .setCurrentIndex (index )
83
90
self .checkRun ()
84
91
92
+ def switchResolutionMode (self ):
93
+ if self .keepResolutionRadio .isChecked ():
94
+ self .resolutionWidget .hide ()
95
+ else :
96
+ self .resolutionWidget .show ()
97
+
85
98
def checkRun (self ):
86
99
if self .extentModeRadio .isChecked ():
87
100
enabler = self .extentSelector .isCoordsValid ()
@@ -135,47 +148,60 @@ def getArguments(self):
135
148
136
149
def getArgsModeExtent (self ):
137
150
self .base .setPluginCommand ("gdal_translate" )
151
+ inputFn = self .getInputFileName ()
138
152
arguments = []
139
153
if self .noDataCheck .isChecked ():
140
154
arguments .append ("-a_nodata" )
141
155
arguments .append (unicode (self .noDataSpin .value ()))
142
156
if self .extentModeRadio .isChecked () and self .extentSelector .isCoordsValid ():
143
157
rect = self .extentSelector .getExtent ()
144
- if rect is not None :
158
+ if rect is not None and not inputFn == '' :
145
159
arguments .append ("-projwin" )
146
160
arguments .append (unicode (rect .xMinimum ()))
147
161
arguments .append (unicode (rect .yMaximum ()))
148
162
arguments .append (unicode (rect .xMaximum ()))
149
163
arguments .append (unicode (rect .yMinimum ()))
150
- if not self .getOutputFileName () == '' :
164
+ outputFn = self .getOutputFileName ()
165
+ if not outputFn == '' :
151
166
arguments .append ("-of" )
152
167
arguments .append (self .outputFormat )
153
- arguments .append (self . getInputFileName () )
154
- arguments .append (self . getOutputFileName () )
168
+ arguments .append (inputFn )
169
+ arguments .append (outputFn )
155
170
return arguments
156
171
157
172
def getArgsModeMask (self ):
158
173
self .base .setPluginCommand ("gdalwarp" )
174
+ inputFn = self .getInputFileName ()
159
175
arguments = []
160
176
if self .noDataCheck .isChecked ():
161
177
arguments .append ("-dstnodata" )
162
178
arguments .append (unicode (self .noDataSpin .value ()))
163
179
if self .maskModeRadio .isChecked ():
164
180
mask = self .maskSelector .filename ()
165
- if not mask == '' :
181
+ if not mask == '' and not inputFn == '' :
166
182
arguments .append ("-q" )
167
183
arguments .append ("-cutline" )
168
184
arguments .append (mask )
169
185
if Utils .GdalConfig .versionNum () >= 1800 :
170
- arguments .append ("-crop_to_cutline" )
186
+ if self .cropToCutlineCheck .isChecked ():
187
+ arguments .append ("-crop_to_cutline" )
171
188
if self .alphaBandCheck .isChecked ():
172
189
arguments .append ("-dstalpha" )
173
-
190
+ if self .keepResolutionRadio .isChecked ():
191
+ resolution = Utils .getRasterResolution (inputFn )
192
+ if resolution is not None :
193
+ arguments .append ("-tr" )
194
+ arguments .append (resolution [0 ])
195
+ arguments .append (resolution [1 ])
196
+ else :
197
+ arguments .append ("-tr" )
198
+ arguments .append (unicode (self .xRes .value ()))
199
+ arguments .append (unicode (self .yRes .value ()))
174
200
outputFn = self .getOutputFileName ()
175
201
if not outputFn == '' :
176
202
arguments .append ("-of" )
177
203
arguments .append (self .outputFormat )
178
- arguments .append (self . getInputFileName () )
204
+ arguments .append (inputFn )
179
205
arguments .append (outputFn )
180
206
return arguments
181
207
0 commit comments