Skip to content

Commit 6a136c1

Browse files
author
g_j_m
committed
- fix ticket #165 (crash in Helmert transform in georeferencer)
- fix a bug when reading in a past saved list of points (there was always a 0,0 point) - tidy up misc code in georeferencer - do some qt3 to qt4 things to get the georeferencer working correctly again - tidy up the use of the modified raster text widget so that it's only editable when it's required - put some debugging output back into #ifdef's git-svn-id: http://svn.osgeo.org/qgis/trunk@5753 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent fa18469 commit 6a136c1

File tree

8 files changed

+87
-46
lines changed

8 files changed

+87
-46
lines changed

src/plugins/georeferencer/plugingui.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,15 @@ void QgsGeorefPluginGui::on_pbnSelectRaster_clicked() {
6464

6565

6666
void QgsGeorefPluginGui::on_pbnEnterWorldCoords_clicked() {
67-
67+
68+
// Is there a filename
69+
if (leSelectRaster->text().isEmpty())
70+
{
71+
QMessageBox::critical(this, tr("Error"),
72+
tr("You need to specify a file to georeference first."));
73+
74+
return;
75+
}
6876
// do we think that this is a valid raster?
6977
if (!QgsRasterLayer::isValidRasterFileName(leSelectRaster->text())) {
7078
QMessageBox::critical(this, tr("Error"),

src/plugins/georeferencer/qgsgeorefdatapoint.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ void QgsGeorefDataPoint::drawShape(QPainter & p)
2727
p.drawRect(x + 2, y + 2, textBounds.width() + 4, textBounds.height() + 4);
2828
p.drawText(textBounds, Qt::AlignLeft, msg);
2929

30-
//#ifdef QGISDEBUG
30+
#ifdef QGISDEBUG
3131
std::cout << "data point at :: " << x << "," << y << std::endl;
32-
//#endif
32+
#endif
3333

3434
setSize(textBounds.width() + 6, textBounds.height() + 6);
3535
}
@@ -40,8 +40,7 @@ void QgsGeorefDataPoint::updatePosition()
4040
move(pt.x() - 2, pt.y() - 2);
4141
show();
4242

43-
//#ifdef QGISDEBUG
43+
#ifdef QGISDEBUG
4444
std::cout << "georefDataPoint::updatePosition: " << pt.x() << "," << pt.y() << std::endl;
45-
//#endif
46-
45+
#endif
4746
}

src/plugins/georeferencer/qgsgeorefwarpoptionsdialog.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
QgsGeorefWarpOptionsDialog::QgsGeorefWarpOptionsDialog(QWidget* parent)
66
: QgsGeorefWarpOptionsDialogBase()
7-
// commented out during qt4 port - FIXME
8-
//: QgsGeorefWarpOptionsDialogBase(parent, NULL, TRUE, 0)
9-
107
{
11-
8+
setupUi(this);
129
}
1310

1411

@@ -20,7 +17,7 @@ getWarpOptions(QgsImageWarper::ResamplingMethod& resampling,
2017
}
2118

2219

23-
void QgsGeorefWarpOptionsDialog::pbnOK_clicked() {
20+
void QgsGeorefWarpOptionsDialog::on_pbnOK_clicked() {
2421
QgsImageWarper::ResamplingMethod methods[] = {
2522
QgsImageWarper::NearestNeighbour,
2623
QgsImageWarper::Bilinear,

src/plugins/georeferencer/qgsgeorefwarpoptionsdialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Q_OBJECT
2828

2929
public slots:
3030

31-
void pbnOK_clicked();
31+
void on_pbnOK_clicked();
3232

3333
private:
3434

src/plugins/georeferencer/qgsimagewarper.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212

1313
#include "qgsimagewarper.h"
1414

15-
16-
using namespace std;
17-
18-
1915
void QgsImageWarper::warp(const QString& input, const QString& output,
2016
double& xOffset, double& yOffset,
2117
ResamplingMethod resampling, bool useZeroAsTrans) {
@@ -60,7 +56,7 @@ void QgsImageWarper::warp(const QString& input, const QString& output,
6056
tParam.x0 = xOffset;
6157
tParam.y0 = yOffset;
6258
psWarpOptions->pTransformerArg = &tParam;
63-
59+
6460
// create the output file
6561
GDALDriver* driver = static_cast<GDALDriver*>(GDALGetDriverByName("GTiff"));
6662
char **papszOptions = NULL;
@@ -82,15 +78,13 @@ void QgsImageWarper::warp(const QString& input, const QString& output,
8278
hDstDS->GetRasterBand(i+1)->SetNoDataValue(0);
8379
}
8480
}
85-
8681
psWarpOptions->hDstDS = hDstDS;
8782

8883
// Initialize and execute the warp operation.
8984
GDALWarpOperation oOperation;
9085
oOperation.Initialize(psWarpOptions);
9186
oOperation.ChunkAndWarpImage(0, 0, GDALGetRasterXSize(hDstDS),
9287
GDALGetRasterYSize(hDstDS));
93-
9488
GDALDestroyWarpOptions(psWarpOptions);
9589
delete hSrcDS;
9690
delete hDstDS;

src/plugins/georeferencer/qgspointdialog.cpp

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <cmath>
22

33
#include <QFileDialog>
4+
#include <QFileInfo>
45
#include <QMessageBox>
56
#include <QTextStream>
67

@@ -132,13 +133,17 @@ QgsPointDialog::QgsPointDialog(QString layerPath, QgisIface* theQgisInterface,
132133
if (pointFile.open(QIODevice::ReadOnly)) {
133134
QTextStream points(&pointFile);
134135
QString tmp;
136+
// read the header
135137
points>>tmp>>tmp>>tmp>>tmp;
138+
// read the first line
139+
double mapX, mapY, pixelX, pixelY;
140+
points>>mapX>>mapY>>pixelX>>pixelY;
136141
while (!points.atEnd()) {
137-
double mapX, mapY, pixelX, pixelY;
138-
points>>mapX>>mapY>>pixelX>>pixelY;
139142
QgsPoint mapCoords(mapX, mapY);
140143
QgsPoint pixelCoords(pixelX, pixelY);
141144
addPoint(pixelCoords, mapCoords);
145+
// read the next line
146+
points>>mapX>>mapY>>pixelX>>pixelY;
142147
}
143148
}
144149

@@ -149,7 +154,13 @@ QgsPointDialog::QgsPointDialog(QString layerPath, QgisIface* theQgisInterface,
149154

150155
// set adding points as default tool
151156
addPoint();
152-
157+
158+
// set the currently supported transforms
159+
cmbTransformType->addItem(tr("Linear"));
160+
cmbTransformType->addItem(tr("Helmert"));
161+
162+
enableModifiedRasterControls(false);
163+
153164
mCanvas->refresh();
154165
}
155166

@@ -203,11 +214,14 @@ void QgsPointDialog::on_pbnGenerateAndLoad_clicked()
203214
mLayer = 0;
204215

205216
// load raster to the main map canvas of QGIS
206-
if (cmbTransformType->currentItem() == 0)
217+
if (cmbTransformType->currentText() == tr("Linear"))
207218
mIface->addRasterLayer(source);
208219
else
209220
mIface->addRasterLayer(leSelectModifiedRaster->text());
210221

222+
// This should cause a map refresh, but it doesn't...
223+
mCanvas->refresh();
224+
211225
accept();
212226
}
213227
}
@@ -231,6 +245,28 @@ void QgsPointDialog::on_pbnSelectModifiedRaster_clicked()
231245
leSelectWorldFile->setText(guessWorldFileName(filename));
232246
}
233247

248+
void QgsPointDialog::on_cmbTransformType_currentIndexChanged(const QString& value)
249+
{
250+
if (value == tr("Helmert"))
251+
{
252+
enableModifiedRasterControls(true);
253+
// Make up a modified raster field name based on the layer file name
254+
QString filename(mLayer->source());
255+
QFileInfo file(mLayer->source());
256+
int pos = filename.size()-file.suffix().size()-1;
257+
filename.insert(pos, tr("-modified", "Georeferencer:QgsPointDialog.cpp - used to modify a user given filename"));
258+
259+
leSelectModifiedRaster->setText(filename);
260+
leSelectWorldFile->setText(guessWorldFileName(filename));
261+
}
262+
else
263+
{
264+
// Reset to the default filenames
265+
leSelectModifiedRaster->setText("");
266+
enableModifiedRasterControls(false);
267+
leSelectWorldFile->setText(guessWorldFileName(mLayer->source()));
268+
}
269+
}
234270

235271
bool QgsPointDialog::generateWorldFile()
236272
{
@@ -251,11 +287,11 @@ bool QgsPointDialog::generateWorldFile()
251287
// (might throw std::domain_error)
252288
try
253289
{
254-
if (cmbTransformType->currentItem() == 0)
290+
if (cmbTransformType->currentText() == tr("Linear"))
255291
{
256292
QgsLeastSquares::linear(mapCoords, pixelCoords, origin, pixelSize);
257293
}
258-
else if (cmbTransformType->currentItem() == 1)
294+
else if (cmbTransformType->currentText() == tr("Helmert"))
259295
{
260296
int res = QMessageBox::warning(this, tr("Warning"),
261297
tr("<p>A Helmert transform requires modifications in "
@@ -266,16 +302,25 @@ bool QgsPointDialog::generateWorldFile()
266302
QMessageBox::No, QMessageBox::Yes);
267303
if (res == QMessageBox::No)
268304
return false;
305+
269306
QgsLeastSquares::helmert(mapCoords, pixelCoords, origin, pixelSize, rotation);
270307
}
271-
else if (cmbTransformType->currentItem() == 2)
308+
else if (cmbTransformType->currentText() == tr("Affine"))
272309
{
273310
QMessageBox::critical(this, tr("Not implemented!"),
274311
tr("<p>An affine transform requires changing the "
275312
"original raster file. This is not yet "
276313
"supported.</p>"));
277314
return false;
278315
}
316+
else
317+
{
318+
QMessageBox::critical(this, tr("Not implemented!"),
319+
tr("<p>The ") +
320+
cmbTransformType->currentText() +
321+
tr(" transform is not yet supported.</p>"));
322+
return false;
323+
}
279324
}
280325
catch (std::domain_error& e)
281326
{
@@ -287,6 +332,7 @@ bool QgsPointDialog::generateWorldFile()
287332
double xOffset, yOffset;
288333
if (rotation != 0)
289334
{
335+
290336
QgsGeorefWarpOptionsDialog d(this);
291337
d.exec();
292338
bool useZeroForTrans;
@@ -296,7 +342,7 @@ bool QgsPointDialog::generateWorldFile()
296342
warper.warp(mLayer->source(), leSelectModifiedRaster->text(),
297343
xOffset, yOffset, resampling, useZeroForTrans);
298344
}
299-
345+
300346
// write the world file
301347
QFile file(leSelectWorldFile->text());
302348
if (!file.open(QIODevice::WriteOnly))
@@ -312,7 +358,6 @@ bool QgsPointDialog::generateWorldFile()
312358
<<-pixelSize<<endl
313359
<<(origin.x() - xOffset * pixelSize)<<endl
314360
<<(origin.y() + yOffset * pixelSize)<<endl;
315-
316361
// write the data points in case we need them later
317362
QFile pointFile(mLayer->source() + ".points");
318363
if (pointFile.open(QIODevice::WriteOnly))
@@ -414,7 +459,7 @@ void QgsPointDialog::deleteDataPoint(QgsPoint& coords)
414459

415460
void QgsPointDialog::enableRelevantControls()
416461
{
417-
if (cmbTransformType->currentItem() == 0)
462+
if (cmbTransformType->currentText() == tr("Linear"))
418463
{
419464
leSelectModifiedRaster->setEnabled(false);
420465
pbnSelectModifiedRaster->setEnabled(false);
@@ -425,7 +470,7 @@ void QgsPointDialog::enableRelevantControls()
425470
pbnSelectModifiedRaster->setEnabled(true);
426471
}
427472

428-
if ((cmbTransformType->currentItem() == 0 &&
473+
if ((cmbTransformType->currentText() == tr("Linear") &&
429474
!leSelectWorldFile->text().isEmpty()) ||
430475
(!leSelectWorldFile->text().isEmpty() &&
431476
!leSelectModifiedRaster->text().isEmpty()))
@@ -453,3 +498,10 @@ QString QgsPointDialog::guessWorldFileName(const QString& raster)
453498
}
454499
return worldfile;
455500
}
501+
502+
void QgsPointDialog::enableModifiedRasterControls(bool state)
503+
{
504+
lblSelectModifiedRaster->setEnabled(state);
505+
pbnSelectModifiedRaster->setEnabled(state);
506+
leSelectModifiedRaster->setEnabled(state);
507+
}

src/plugins/georeferencer/qgspointdialog.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414

1515
#include <vector>
1616

17-
//#include <QCursor>
1817
#include <QDialog>
18+
#include <QString>
1919

2020
#include <qgsmapcanvas.h>
21-
22-
#include "qgsrasterlayer.h"
21+
#include <qgsrasterlayer.h>
2322

2423
#include <ui_qgspointdialogbase.h>
2524

@@ -47,6 +46,7 @@ public slots:
4746
void on_pbnGenerateAndLoad_clicked();
4847
void on_pbnSelectWorldFile_clicked();
4948
void on_pbnSelectModifiedRaster_clicked();
49+
void on_cmbTransformType_currentIndexChanged(const QString&);
5050
void zoomIn();
5151
void zoomOut();
5252
void zoomToLayer();
@@ -59,6 +59,8 @@ public slots:
5959

6060
bool generateWorldFile();
6161
QString guessWorldFileName(const QString& raster);
62+
63+
void enableModifiedRasterControls(bool state);
6264

6365
QActionGroup* mMapToolGroup;
6466
QAction* mActionZoomIn;

src/plugins/georeferencer/qgspointdialogbase.ui

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@
260260
</widget>
261261
</item>
262262
<item row="2" column="4" >
263-
<widget class="QLabel" name="textLabel1_2" >
263+
<widget class="QLabel" name="lblSelectModifiedRaster" >
264264
<property name="text" >
265265
<string>Modified raster:</string>
266266
</property>
@@ -290,18 +290,7 @@
290290
</spacer>
291291
</item>
292292
<item row="2" column="1" colspan="3" >
293-
<widget class="QComboBox" name="cmbTransformType" >
294-
<item>
295-
<property name="text" >
296-
<string>Linear</string>
297-
</property>
298-
</item>
299-
<item>
300-
<property name="text" >
301-
<string>Helmert</string>
302-
</property>
303-
</item>
304-
</widget>
293+
<widget class="QComboBox" name="cmbTransformType" />
305294
</item>
306295
<item row="2" column="0" >
307296
<widget class="QLabel" name="textLabel2" >

0 commit comments

Comments
 (0)