Skip to content
Permalink
Browse files
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
  • Loading branch information
mhugent committed Apr 14, 2007
1 parent 253cae3 commit 271b5905b4c2f8fe6f95ca60e6f5b7c9b852cb2d
Showing with 23 additions and 31 deletions.
  1. +6 −6 src/plugins/georeferencer/qgsleastsquares.cpp
  2. +1 −1 src/plugins/georeferencer/qgsleastsquares.h
  3. +16 −24 src/plugins/georeferencer/qgspointdialog.cpp
@@ -1,8 +1,8 @@

#include <cmath>
#include <stdexcept>
#include "qgslogger.h"
#include <gsl/gsl_linalg.h>

#include <gsl/gsl_linalg.h>

#include <QObject>

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

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

origin.setX(aX);
origin.setY(aY);
pixelSize = (std::abs(bX) + std::abs(bY)) / 2;

pixelXSize = std::abs(bX);
pixelYSize = std::abs(bY);
}


@@ -12,7 +12,7 @@ class QgsLeastSquares {
public:
static void linear(std::vector<QgsPoint> mapCoords,
std::vector<QgsPoint> pixelCoords,
QgsPoint& origin, double& pixelSize);
QgsPoint& origin, double& pixelXSize, double& pixelYSize);

static void helmert(std::vector<QgsPoint> mapCoords,
std::vector<QgsPoint> pixelCoords,
@@ -136,12 +136,6 @@ QgsPointDialog::QgsPointDialog(QString layerPath, QgisIface* theQgisInterface,
QgsMapLayerRegistry* registry = QgsMapLayerRegistry::instance();
registry->addMapLayer(layer, FALSE);


// Set source SRS same as dest SRS, so that we don't do any transformation.
// Dest SRS is set by project defaults
// The CoordinateTransform should now be shortcircuited.
layer->coordinateTransform()->setSourceSRS(layer->coordinateTransform()->destSRS());

// add layer to map canvas
std::deque<QString> layers;
layers.push_back(layer->getLayerID());
@@ -280,9 +274,7 @@ void QgsPointDialog::on_cmbTransformType_currentIndexChanged(const QString& valu
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"));
pos = filename.size()-file.suffix().size();
filename.replace(pos, filename.size(), "tif");


leSelectModifiedRaster->setText(filename);
leSelectWorldFile->setText(guessWorldFileName(filename));
}
@@ -298,10 +290,9 @@ void QgsPointDialog::on_cmbTransformType_currentIndexChanged(const QString& valu
bool QgsPointDialog::generateWorldFile()
{
QgsPoint origin(0, 0);
double pixelSize = 1;
double pixelXSize = 1;
double pixelYSize = 1;
double rotation = 0;
double xOffset = 0.0;
double yOffset = 0.0;

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

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

// warp the raster if needed
double xOffset = 0;
double yOffset = 0;
if (rotation != 0)
{

@@ -381,12 +374,12 @@ bool QgsPointDialog::generateWorldFile()
return false;
}
QTextStream stream(&file);
stream<<pixelSize<<endl
stream<<pixelXSize<<endl
<<0<<endl
<<0<<endl
<<-pixelSize<<endl
<<QString::number(origin.x() - xOffset * pixelSize, 'f')<<endl
<<QString::number(origin.y() + yOffset * pixelSize, 'f')<<endl;
<<-pixelYSize<<endl
<<(origin.x() - xOffset * pixelXSize)<<endl
<<(origin.y() + yOffset * pixelYSize)<<endl;
// write the data points in case we need them later
QFile pointFile(mLayer->source() + ".points");
if (pointFile.open(QIODevice::WriteOnly))
@@ -396,8 +389,7 @@ bool QgsPointDialog::generateWorldFile()
for (unsigned int i = 0; i < mapCoords.size(); ++i)
{
points<<(QString("%1\t%2\t%3\t%4").
arg(QString::number(mapCoords[i].x(), 'f')).
arg(QString::number(mapCoords[i].y(), 'f')).
arg(mapCoords[i].x()).arg(mapCoords[i].y()).
arg(pixelCoords[i].x()).arg(pixelCoords[i].y()))<<endl;
}
}
@@ -469,8 +461,8 @@ void QgsPointDialog::deleteDataPoint(QgsPoint& coords)
#endif
if ((x*x + y*y) < maxDistSqr)
{
delete *it;
mPoints.erase(it);
delete *it;
mCanvas->refresh();
break;
}

0 comments on commit 271b590

Please sign in to comment.