Skip to content
Permalink
Browse files
- 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
  • Loading branch information
g_j_m committed Sep 2, 2006
1 parent fa18469 commit 6a136c1791a87df0ae4b2c9801dcfa918ae48f65
@@ -64,7 +64,15 @@ void QgsGeorefPluginGui::on_pbnSelectRaster_clicked() {


void QgsGeorefPluginGui::on_pbnEnterWorldCoords_clicked() {


// Is there a filename
if (leSelectRaster->text().isEmpty())
{
QMessageBox::critical(this, tr("Error"),
tr("You need to specify a file to georeference first."));

return;
}
// do we think that this is a valid raster?
if (!QgsRasterLayer::isValidRasterFileName(leSelectRaster->text())) {
QMessageBox::critical(this, tr("Error"),
@@ -27,9 +27,9 @@ void QgsGeorefDataPoint::drawShape(QPainter & p)
p.drawRect(x + 2, y + 2, textBounds.width() + 4, textBounds.height() + 4);
p.drawText(textBounds, Qt::AlignLeft, msg);

//#ifdef QGISDEBUG
#ifdef QGISDEBUG
std::cout << "data point at :: " << x << "," << y << std::endl;
//#endif
#endif

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

//#ifdef QGISDEBUG
#ifdef QGISDEBUG
std::cout << "georefDataPoint::updatePosition: " << pt.x() << "," << pt.y() << std::endl;
//#endif

#endif
}
@@ -4,11 +4,8 @@

QgsGeorefWarpOptionsDialog::QgsGeorefWarpOptionsDialog(QWidget* parent)
: QgsGeorefWarpOptionsDialogBase()
// commented out during qt4 port - FIXME
//: QgsGeorefWarpOptionsDialogBase(parent, NULL, TRUE, 0)

{

setupUi(this);
}


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


void QgsGeorefWarpOptionsDialog::pbnOK_clicked() {
void QgsGeorefWarpOptionsDialog::on_pbnOK_clicked() {
QgsImageWarper::ResamplingMethod methods[] = {
QgsImageWarper::NearestNeighbour,
QgsImageWarper::Bilinear,
@@ -28,7 +28,7 @@ Q_OBJECT

public slots:

void pbnOK_clicked();
void on_pbnOK_clicked();

private:

@@ -12,10 +12,6 @@

#include "qgsimagewarper.h"


using namespace std;


void QgsImageWarper::warp(const QString& input, const QString& output,
double& xOffset, double& yOffset,
ResamplingMethod resampling, bool useZeroAsTrans) {
@@ -60,7 +56,7 @@ void QgsImageWarper::warp(const QString& input, const QString& output,
tParam.x0 = xOffset;
tParam.y0 = yOffset;
psWarpOptions->pTransformerArg = &tParam;

// create the output file
GDALDriver* driver = static_cast<GDALDriver*>(GDALGetDriverByName("GTiff"));
char **papszOptions = NULL;
@@ -82,15 +78,13 @@ void QgsImageWarper::warp(const QString& input, const QString& output,
hDstDS->GetRasterBand(i+1)->SetNoDataValue(0);
}
}

psWarpOptions->hDstDS = hDstDS;

// Initialize and execute the warp operation.
GDALWarpOperation oOperation;
oOperation.Initialize(psWarpOptions);
oOperation.ChunkAndWarpImage(0, 0, GDALGetRasterXSize(hDstDS),
GDALGetRasterYSize(hDstDS));

GDALDestroyWarpOptions(psWarpOptions);
delete hSrcDS;
delete hDstDS;
@@ -1,6 +1,7 @@
#include <cmath>

#include <QFileDialog>
#include <QFileInfo>
#include <QMessageBox>
#include <QTextStream>

@@ -132,13 +133,17 @@ QgsPointDialog::QgsPointDialog(QString layerPath, QgisIface* theQgisInterface,
if (pointFile.open(QIODevice::ReadOnly)) {
QTextStream points(&pointFile);
QString tmp;
// read the header
points>>tmp>>tmp>>tmp>>tmp;
// read the first line
double mapX, mapY, pixelX, pixelY;
points>>mapX>>mapY>>pixelX>>pixelY;
while (!points.atEnd()) {
double mapX, mapY, pixelX, pixelY;
points>>mapX>>mapY>>pixelX>>pixelY;
QgsPoint mapCoords(mapX, mapY);
QgsPoint pixelCoords(pixelX, pixelY);
addPoint(pixelCoords, mapCoords);
// read the next line
points>>mapX>>mapY>>pixelX>>pixelY;
}
}

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

// set adding points as default tool
addPoint();


// set the currently supported transforms
cmbTransformType->addItem(tr("Linear"));
cmbTransformType->addItem(tr("Helmert"));

enableModifiedRasterControls(false);

mCanvas->refresh();
}

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

// load raster to the main map canvas of QGIS
if (cmbTransformType->currentItem() == 0)
if (cmbTransformType->currentText() == tr("Linear"))
mIface->addRasterLayer(source);
else
mIface->addRasterLayer(leSelectModifiedRaster->text());

// This should cause a map refresh, but it doesn't...
mCanvas->refresh();

accept();
}
}
@@ -231,6 +245,28 @@ void QgsPointDialog::on_pbnSelectModifiedRaster_clicked()
leSelectWorldFile->setText(guessWorldFileName(filename));
}

void QgsPointDialog::on_cmbTransformType_currentIndexChanged(const QString& value)
{
if (value == tr("Helmert"))
{
enableModifiedRasterControls(true);
// Make up a modified raster field name based on the layer file name
QString filename(mLayer->source());
QFileInfo file(mLayer->source());
int pos = filename.size()-file.suffix().size()-1;
filename.insert(pos, tr("-modified", "Georeferencer:QgsPointDialog.cpp - used to modify a user given filename"));

leSelectModifiedRaster->setText(filename);
leSelectWorldFile->setText(guessWorldFileName(filename));
}
else
{
// Reset to the default filenames
leSelectModifiedRaster->setText("");
enableModifiedRasterControls(false);
leSelectWorldFile->setText(guessWorldFileName(mLayer->source()));
}
}

bool QgsPointDialog::generateWorldFile()
{
@@ -251,11 +287,11 @@ bool QgsPointDialog::generateWorldFile()
// (might throw std::domain_error)
try
{
if (cmbTransformType->currentItem() == 0)
if (cmbTransformType->currentText() == tr("Linear"))
{
QgsLeastSquares::linear(mapCoords, pixelCoords, origin, pixelSize);
}
else if (cmbTransformType->currentItem() == 1)
else if (cmbTransformType->currentText() == tr("Helmert"))
{
int res = QMessageBox::warning(this, tr("Warning"),
tr("<p>A Helmert transform requires modifications in "
@@ -266,16 +302,25 @@ bool QgsPointDialog::generateWorldFile()
QMessageBox::No, QMessageBox::Yes);
if (res == QMessageBox::No)
return false;

QgsLeastSquares::helmert(mapCoords, pixelCoords, origin, pixelSize, rotation);
}
else if (cmbTransformType->currentItem() == 2)
else if (cmbTransformType->currentText() == tr("Affine"))
{
QMessageBox::critical(this, tr("Not implemented!"),
tr("<p>An affine transform requires changing the "
"original raster file. This is not yet "
"supported.</p>"));
return false;
}
else
{
QMessageBox::critical(this, tr("Not implemented!"),
tr("<p>The ") +
cmbTransformType->currentText() +
tr(" transform is not yet supported.</p>"));
return false;
}
}
catch (std::domain_error& e)
{
@@ -287,6 +332,7 @@ bool QgsPointDialog::generateWorldFile()
double xOffset, yOffset;
if (rotation != 0)
{

QgsGeorefWarpOptionsDialog d(this);
d.exec();
bool useZeroForTrans;
@@ -296,7 +342,7 @@ bool QgsPointDialog::generateWorldFile()
warper.warp(mLayer->source(), leSelectModifiedRaster->text(),
xOffset, yOffset, resampling, useZeroForTrans);
}

// write the world file
QFile file(leSelectWorldFile->text());
if (!file.open(QIODevice::WriteOnly))
@@ -312,7 +358,6 @@ bool QgsPointDialog::generateWorldFile()
<<-pixelSize<<endl
<<(origin.x() - xOffset * pixelSize)<<endl
<<(origin.y() + yOffset * pixelSize)<<endl;

// write the data points in case we need them later
QFile pointFile(mLayer->source() + ".points");
if (pointFile.open(QIODevice::WriteOnly))
@@ -414,7 +459,7 @@ void QgsPointDialog::deleteDataPoint(QgsPoint& coords)

void QgsPointDialog::enableRelevantControls()
{
if (cmbTransformType->currentItem() == 0)
if (cmbTransformType->currentText() == tr("Linear"))
{
leSelectModifiedRaster->setEnabled(false);
pbnSelectModifiedRaster->setEnabled(false);
@@ -425,7 +470,7 @@ void QgsPointDialog::enableRelevantControls()
pbnSelectModifiedRaster->setEnabled(true);
}

if ((cmbTransformType->currentItem() == 0 &&
if ((cmbTransformType->currentText() == tr("Linear") &&
!leSelectWorldFile->text().isEmpty()) ||
(!leSelectWorldFile->text().isEmpty() &&
!leSelectModifiedRaster->text().isEmpty()))
@@ -453,3 +498,10 @@ QString QgsPointDialog::guessWorldFileName(const QString& raster)
}
return worldfile;
}

void QgsPointDialog::enableModifiedRasterControls(bool state)
{
lblSelectModifiedRaster->setEnabled(state);
pbnSelectModifiedRaster->setEnabled(state);
leSelectModifiedRaster->setEnabled(state);
}
@@ -14,12 +14,11 @@

#include <vector>

//#include <QCursor>
#include <QDialog>
#include <QString>

#include <qgsmapcanvas.h>

#include "qgsrasterlayer.h"
#include <qgsrasterlayer.h>

#include <ui_qgspointdialogbase.h>

@@ -47,6 +46,7 @@ public slots:
void on_pbnGenerateAndLoad_clicked();
void on_pbnSelectWorldFile_clicked();
void on_pbnSelectModifiedRaster_clicked();
void on_cmbTransformType_currentIndexChanged(const QString&);
void zoomIn();
void zoomOut();
void zoomToLayer();
@@ -59,6 +59,8 @@ public slots:

bool generateWorldFile();
QString guessWorldFileName(const QString& raster);

void enableModifiedRasterControls(bool state);

QActionGroup* mMapToolGroup;
QAction* mActionZoomIn;
@@ -260,7 +260,7 @@
</widget>
</item>
<item row="2" column="4" >
<widget class="QLabel" name="textLabel1_2" >
<widget class="QLabel" name="lblSelectModifiedRaster" >
<property name="text" >
<string>Modified raster:</string>
</property>
@@ -290,18 +290,7 @@
</spacer>
</item>
<item row="2" column="1" colspan="3" >
<widget class="QComboBox" name="cmbTransformType" >
<item>
<property name="text" >
<string>Linear</string>
</property>
</item>
<item>
<property name="text" >
<string>Helmert</string>
</property>
</item>
</widget>
<widget class="QComboBox" name="cmbTransformType" />
</item>
<item row="2" column="0" >
<widget class="QLabel" name="textLabel2" >

0 comments on commit 6a136c1

Please sign in to comment.