Skip to content

Commit 271b590

Browse files
author
mhugent
committedApr 14, 2007
initialize xOffset and yOffset to 0
git-svn-id: http://svn.osgeo.org/qgis/branches/Release-0_8_0@6886 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 253cae3 commit 271b590

File tree

3 files changed

+23
-31
lines changed

3 files changed

+23
-31
lines changed
 

‎src/plugins/georeferencer/qgsleastsquares.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
12
#include <cmath>
23
#include <stdexcept>
3-
#include "qgslogger.h"
4-
#include <gsl/gsl_linalg.h>
54

5+
#include <gsl/gsl_linalg.h>
66

77
#include <QObject>
88

@@ -11,7 +11,7 @@
1111

1212
void QgsLeastSquares::linear(std::vector<QgsPoint> mapCoords,
1313
std::vector<QgsPoint> pixelCoords,
14-
QgsPoint& origin, double& pixelSize) {
14+
QgsPoint& origin, double& pixelXSize, double& pixelYSize) {
1515
int n = mapCoords.size();
1616
if (n < 2) {
1717
throw std::domain_error(QObject::tr("Fit to a linear transform requires at "
@@ -21,8 +21,6 @@ void QgsLeastSquares::linear(std::vector<QgsPoint> mapCoords,
2121
double sumPx(0), sumPy(0), sumPx2(0), sumPy2(0), sumPxMx(0), sumPyMy(0),
2222
sumMx(0), sumMy(0);
2323
for (int i = 0; i < n; ++i) {
24-
QgsDebugMsg("Processing point Pixel(" + QString::number(pixelCoords[i].x()) + ":" + QString::number(pixelCoords[i].y()) +
25-
")\n Map(" + QString::number(mapCoords[i].x()) + ":" + QString::number(mapCoords[i].y()) + ")\n");
2624
sumPx += pixelCoords[i].x();
2725
sumPy += pixelCoords[i].y();
2826
sumPx2 += std::pow(pixelCoords[i].x(), 2);
@@ -43,7 +41,9 @@ void QgsLeastSquares::linear(std::vector<QgsPoint> mapCoords,
4341

4442
origin.setX(aX);
4543
origin.setY(aY);
46-
pixelSize = (std::abs(bX) + std::abs(bY)) / 2;
44+
45+
pixelXSize = std::abs(bX);
46+
pixelYSize = std::abs(bY);
4747
}
4848

4949

‎src/plugins/georeferencer/qgsleastsquares.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class QgsLeastSquares {
1212
public:
1313
static void linear(std::vector<QgsPoint> mapCoords,
1414
std::vector<QgsPoint> pixelCoords,
15-
QgsPoint& origin, double& pixelSize);
15+
QgsPoint& origin, double& pixelXSize, double& pixelYSize);
1616

1717
static void helmert(std::vector<QgsPoint> mapCoords,
1818
std::vector<QgsPoint> pixelCoords,

‎src/plugins/georeferencer/qgspointdialog.cpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,6 @@ QgsPointDialog::QgsPointDialog(QString layerPath, QgisIface* theQgisInterface,
136136
QgsMapLayerRegistry* registry = QgsMapLayerRegistry::instance();
137137
registry->addMapLayer(layer, FALSE);
138138

139-
140-
// Set source SRS same as dest SRS, so that we don't do any transformation.
141-
// Dest SRS is set by project defaults
142-
// The CoordinateTransform should now be shortcircuited.
143-
layer->coordinateTransform()->setSourceSRS(layer->coordinateTransform()->destSRS());
144-
145139
// add layer to map canvas
146140
std::deque<QString> layers;
147141
layers.push_back(layer->getLayerID());
@@ -280,9 +274,7 @@ void QgsPointDialog::on_cmbTransformType_currentIndexChanged(const QString& valu
280274
QFileInfo file(mLayer->source());
281275
int pos = filename.size()-file.suffix().size()-1;
282276
filename.insert(pos, tr("-modified", "Georeferencer:QgsPointDialog.cpp - used to modify a user given filename"));
283-
pos = filename.size()-file.suffix().size();
284-
filename.replace(pos, filename.size(), "tif");
285-
277+
286278
leSelectModifiedRaster->setText(filename);
287279
leSelectWorldFile->setText(guessWorldFileName(filename));
288280
}
@@ -298,10 +290,9 @@ void QgsPointDialog::on_cmbTransformType_currentIndexChanged(const QString& valu
298290
bool QgsPointDialog::generateWorldFile()
299291
{
300292
QgsPoint origin(0, 0);
301-
double pixelSize = 1;
293+
double pixelXSize = 1;
294+
double pixelYSize = 1;
302295
double rotation = 0;
303-
double xOffset = 0.0;
304-
double yOffset = 0.0;
305296

306297
// create arrays with points from mPoints
307298
std::vector<QgsPoint> pixelCoords, mapCoords;
@@ -318,7 +309,7 @@ bool QgsPointDialog::generateWorldFile()
318309
{
319310
if (cmbTransformType->currentText() == tr("Linear"))
320311
{
321-
QgsLeastSquares::linear(mapCoords, pixelCoords, origin, pixelSize);
312+
QgsLeastSquares::linear(mapCoords, pixelCoords, origin, pixelXSize, pixelYSize);
322313
}
323314
else if (cmbTransformType->currentText() == tr("Helmert"))
324315
{
@@ -327,13 +318,13 @@ bool QgsPointDialog::generateWorldFile()
327318
"the raster layer.</p><p>The modifed raster will be "
328319
"saved in a new file and a world file will be "
329320
"generated for this new file instead.</p><p>Are you "
330-
"sure that this is what you want?</p>") +
331-
"<p><i>" + tr("Currently all modified files will be written in TIFF format.") +
332-
"</i><p>", QMessageBox::No, QMessageBox::Yes);
321+
"sure that this is what you want?</p>"),
322+
QMessageBox::No, QMessageBox::Yes);
333323
if (res == QMessageBox::No)
334324
return false;
335325

336-
QgsLeastSquares::helmert(mapCoords, pixelCoords, origin, pixelSize, rotation);
326+
QgsLeastSquares::helmert(mapCoords, pixelCoords, origin, pixelXSize, rotation);
327+
pixelXSize = pixelYSize;
337328
}
338329
else if (cmbTransformType->currentText() == tr("Affine"))
339330
{
@@ -359,6 +350,8 @@ bool QgsPointDialog::generateWorldFile()
359350
}
360351

361352
// warp the raster if needed
353+
double xOffset = 0;
354+
double yOffset = 0;
362355
if (rotation != 0)
363356
{
364357

@@ -381,12 +374,12 @@ bool QgsPointDialog::generateWorldFile()
381374
return false;
382375
}
383376
QTextStream stream(&file);
384-
stream<<pixelSize<<endl
377+
stream<<pixelXSize<<endl
385378
<<0<<endl
386379
<<0<<endl
387-
<<-pixelSize<<endl
388-
<<QString::number(origin.x() - xOffset * pixelSize, 'f')<<endl
389-
<<QString::number(origin.y() + yOffset * pixelSize, 'f')<<endl;
380+
<<-pixelYSize<<endl
381+
<<(origin.x() - xOffset * pixelXSize)<<endl
382+
<<(origin.y() + yOffset * pixelYSize)<<endl;
390383
// write the data points in case we need them later
391384
QFile pointFile(mLayer->source() + ".points");
392385
if (pointFile.open(QIODevice::WriteOnly))
@@ -396,8 +389,7 @@ bool QgsPointDialog::generateWorldFile()
396389
for (unsigned int i = 0; i < mapCoords.size(); ++i)
397390
{
398391
points<<(QString("%1\t%2\t%3\t%4").
399-
arg(QString::number(mapCoords[i].x(), 'f')).
400-
arg(QString::number(mapCoords[i].y(), 'f')).
392+
arg(mapCoords[i].x()).arg(mapCoords[i].y()).
401393
arg(pixelCoords[i].x()).arg(pixelCoords[i].y()))<<endl;
402394
}
403395
}
@@ -469,8 +461,8 @@ void QgsPointDialog::deleteDataPoint(QgsPoint& coords)
469461
#endif
470462
if ((x*x + y*y) < maxDistSqr)
471463
{
472-
delete *it;
473464
mPoints.erase(it);
465+
delete *it;
474466
mCanvas->refresh();
475467
break;
476468
}

0 commit comments

Comments
 (0)
Please sign in to comment.