@@ -73,19 +73,33 @@ QgsAlignRasterDialog::QgsAlignRasterDialog( QWidget *parent )
73
73
connect ( mBtnRemove , SIGNAL ( clicked ( bool ) ), this , SLOT ( removeLayer () ) );
74
74
connect ( mBtnEdit , SIGNAL ( clicked ( bool ) ), this , SLOT ( editLayer () ) );
75
75
76
- connect ( mCboReferenceLayer , SIGNAL ( currentIndexChanged ( int ) ), this , SLOT ( updateConfigFromReferenceLayer () ) );
76
+ connect ( mCboReferenceLayer , SIGNAL ( currentIndexChanged ( int ) ), this , SLOT ( referenceLayerChanged () ) );
77
77
connect ( mCrsSelector , SIGNAL ( crsChanged ( QgsCoordinateReferenceSystem ) ), this , SLOT ( destinationCrsChanged () ) );
78
+ connect ( mSpinCellSizeX , SIGNAL ( valueChanged ( double ) ), this , SLOT ( updateParametersFromReferenceLayer () ) );
79
+ connect ( mSpinCellSizeY , SIGNAL ( valueChanged ( double ) ), this , SLOT ( updateParametersFromReferenceLayer () ) );
80
+ connect ( mSpinGridOffsetX , SIGNAL ( valueChanged ( double ) ), this , SLOT ( updateParametersFromReferenceLayer () ) );
81
+ connect ( mSpinGridOffsetY , SIGNAL ( valueChanged ( double ) ), this , SLOT ( updateParametersFromReferenceLayer () ) );
82
+
83
+ connect ( mChkCustomCRS , SIGNAL ( clicked ( bool ) ), this , SLOT ( updateCustomCRS () ) );
84
+ connect ( mChkCustomCellSize , SIGNAL ( clicked ( bool ) ), this , SLOT ( updateCustomCellSize () ) );
85
+ connect ( mChkCustomGridOffset , SIGNAL ( clicked ( bool ) ), this , SLOT ( updateCustomGridOffset () ) );
78
86
79
87
mClipExtentGroupBox ->setChecked ( false );
80
88
mClipExtentGroupBox ->setCollapsed ( true );
81
89
mClipExtentGroupBox ->setTitleBase ( tr ( " Clip to Extent" ) );
90
+ QgsMapCanvas* mc = QgisApp::instance ()->mapCanvas ();
91
+ mClipExtentGroupBox ->setCurrentExtent ( mc->extent (), mc->mapSettings ().destinationCrs () );
82
92
connect ( mClipExtentGroupBox , SIGNAL ( extentChanged ( QgsRectangle ) ), this , SLOT ( clipExtentChanged () ) );
83
93
84
94
// TODO: auto-detect reference layer
85
95
86
96
connect ( buttonBox, SIGNAL ( accepted () ), this , SLOT ( runAlign () ) );
87
97
88
98
populateLayersView ();
99
+
100
+ updateCustomCRS ();
101
+ updateCustomCellSize ();
102
+ updateCustomGridOffset ();
89
103
}
90
104
91
105
QgsAlignRasterDialog::~QgsAlignRasterDialog ()
@@ -130,6 +144,67 @@ void QgsAlignRasterDialog::updateAlignedRasterInfo()
130
144
mEditOutputSize ->setText ( msg );
131
145
}
132
146
147
+ void QgsAlignRasterDialog::updateParametersFromReferenceLayer ()
148
+ {
149
+ QString customCRSWkt;
150
+ QSizeF customCellSize;
151
+ QPointF customGridOffset ( -1 , -1 );
152
+
153
+ int index = mCboReferenceLayer ->currentIndex ();
154
+ if ( index < 0 )
155
+ return ;
156
+
157
+ QgsAlignRaster::RasterInfo refInfo ( mAlign ->rasters ().at ( index ).inputFilename );
158
+ if ( !refInfo.isValid () )
159
+ return ;
160
+
161
+ // get custom values from the GUI (if any)
162
+ if ( mChkCustomCRS ->isChecked () )
163
+ {
164
+ QgsCoordinateReferenceSystem refCRS ( QString::fromAscii ( refInfo.crs () ) );
165
+ if ( refCRS != mCrsSelector ->crs () )
166
+ customCRSWkt = mCrsSelector ->crs ().toWkt ();
167
+ }
168
+
169
+ if ( mChkCustomCellSize ->isChecked () )
170
+ {
171
+ customCellSize = QSizeF ( mSpinCellSizeX ->value (), mSpinCellSizeY ->value () );
172
+ }
173
+
174
+ if ( mChkCustomGridOffset ->isChecked () )
175
+ {
176
+ customGridOffset = QPointF ( mSpinGridOffsetX ->value (), mSpinGridOffsetY ->value () );
177
+ }
178
+
179
+ // calculate the parameters which are not customized already
180
+ bool res = mAlign ->setParametersFromRaster ( refInfo, customCRSWkt, customCellSize, customGridOffset );
181
+
182
+ // refresh values that may have changed
183
+ if ( res )
184
+ {
185
+ QgsCoordinateReferenceSystem destCRS ( mAlign ->destinationCRS () );
186
+ mClipExtentGroupBox ->setOutputCrs ( destCRS );
187
+ if ( !mChkCustomCRS ->isChecked () )
188
+ {
189
+ mCrsSelector ->setCrs ( destCRS );
190
+ }
191
+ }
192
+ if ( !mChkCustomCellSize ->isChecked () )
193
+ {
194
+ QSizeF cellSize = mAlign ->cellSize ();
195
+ mSpinCellSizeX ->setValue ( cellSize.width () );
196
+ mSpinCellSizeY ->setValue ( cellSize.height () );
197
+ }
198
+ if ( !mChkCustomGridOffset ->isChecked () )
199
+ {
200
+ QPointF gridOffset = mAlign ->gridOffset ();
201
+ mSpinGridOffsetX ->setValue ( gridOffset.x () );
202
+ mSpinGridOffsetY ->setValue ( gridOffset.y () );
203
+ }
204
+
205
+ updateAlignedRasterInfo ();
206
+ }
207
+
133
208
134
209
void QgsAlignRasterDialog::addLayer ()
135
210
{
@@ -185,7 +260,7 @@ void QgsAlignRasterDialog::editLayer()
185
260
populateLayersView ();
186
261
}
187
262
188
- void QgsAlignRasterDialog::updateConfigFromReferenceLayer ()
263
+ void QgsAlignRasterDialog::referenceLayerChanged ()
189
264
{
190
265
int index = mCboReferenceLayer ->currentIndex ();
191
266
if ( index < 0 )
@@ -195,25 +270,11 @@ void QgsAlignRasterDialog::updateConfigFromReferenceLayer()
195
270
if ( !refInfo.isValid () )
196
271
return ;
197
272
198
- mAlign ->setParametersFromRaster ( refInfo );
199
-
200
- QgsCoordinateReferenceSystem destCRS ( mAlign ->destinationCRS () );
201
- mCrsSelector ->setCrs ( destCRS );
202
-
203
- QSizeF cellSize = mAlign ->cellSize ();
204
- mSpinCellSizeX ->setValue ( cellSize.width () );
205
- mSpinCellSizeY ->setValue ( cellSize.height () );
273
+ QgsCoordinateReferenceSystem layerCRS ( QString::fromAscii ( refInfo.crs () ) );
274
+ mCrsSelector ->setLayerCrs ( layerCRS );
275
+ mClipExtentGroupBox ->setOriginalExtent ( refInfo.extent (), layerCRS );
206
276
207
- QPointF gridOffset = mAlign ->gridOffset ();
208
- mSpinGridOffsetX ->setValue ( gridOffset.x () );
209
- mSpinGridOffsetY ->setValue ( gridOffset.y () );
210
-
211
- QgsMapCanvas* mc = QgisApp::instance ()->mapCanvas ();
212
- mClipExtentGroupBox ->setCurrentExtent ( mc->extent (), mc->mapSettings ().destinationCrs () );
213
- mClipExtentGroupBox ->setOriginalExtent ( refInfo.extent (), QgsCoordinateReferenceSystem ( QString::fromAscii ( refInfo.crs () ) ) );
214
- mClipExtentGroupBox ->setOutputCrs ( destCRS );
215
-
216
- updateAlignedRasterInfo ();
277
+ updateParametersFromReferenceLayer ();
217
278
}
218
279
219
280
@@ -230,23 +291,7 @@ void QgsAlignRasterDialog::destinationCrsChanged()
230
291
if ( !refInfo.isValid () )
231
292
return ;
232
293
233
- if ( !mAlign ->setParametersFromRaster ( refInfo, mCrsSelector ->crs ().toWkt () ) )
234
- {
235
- QMessageBox::warning ( this , tr ( " Align Rasters" ), tr ( " Cannot reproject reference layer to the chosen destination CRS.\n\n Please select a different CRS" ) );
236
- return ;
237
- }
238
-
239
- QSizeF cellSize = mAlign ->cellSize ();
240
- mSpinCellSizeX ->setValue ( cellSize.width () );
241
- mSpinCellSizeY ->setValue ( cellSize.height () );
242
-
243
- QPointF gridOffset = mAlign ->gridOffset ();
244
- mSpinGridOffsetX ->setValue ( gridOffset.x () );
245
- mSpinGridOffsetY ->setValue ( gridOffset.y () );
246
-
247
- mClipExtentGroupBox ->setOutputCrs ( mCrsSelector ->crs () );
248
-
249
- updateAlignedRasterInfo ();
294
+ updateParametersFromReferenceLayer ();
250
295
}
251
296
252
297
void QgsAlignRasterDialog::clipExtentChanged ()
@@ -256,6 +301,26 @@ void QgsAlignRasterDialog::clipExtentChanged()
256
301
updateAlignedRasterInfo ();
257
302
}
258
303
304
+ void QgsAlignRasterDialog::updateCustomCRS ()
305
+ {
306
+ mCrsSelector ->setEnabled ( mChkCustomCRS ->isChecked () );
307
+ updateParametersFromReferenceLayer ();
308
+ }
309
+
310
+ void QgsAlignRasterDialog::updateCustomCellSize ()
311
+ {
312
+ mSpinCellSizeX ->setEnabled ( mChkCustomCellSize ->isChecked () );
313
+ mSpinCellSizeY ->setEnabled ( mChkCustomCellSize ->isChecked () );
314
+ updateParametersFromReferenceLayer ();
315
+ }
316
+
317
+ void QgsAlignRasterDialog::updateCustomGridOffset ()
318
+ {
319
+ mSpinGridOffsetX ->setEnabled ( mChkCustomGridOffset ->isChecked () );
320
+ mSpinGridOffsetY ->setEnabled ( mChkCustomGridOffset ->isChecked () );
321
+ updateParametersFromReferenceLayer ();
322
+ }
323
+
259
324
260
325
void QgsAlignRasterDialog::runAlign ()
261
326
{
0 commit comments