Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 271b590
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
12 changes: 6 additions & 6 deletions src/plugins/georeferencer/qgsleastsquares.cpp
@@ -1,8 +1,8 @@

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

#include <gsl/gsl_linalg.h>

#include <QObject>

Expand All @@ -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 "
Expand All @@ -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);
Expand All @@ -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);
}


Expand Down
2 changes: 1 addition & 1 deletion src/plugins/georeferencer/qgsleastsquares.h
Expand Up @@ -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,
Expand Down
40 changes: 16 additions & 24 deletions src/plugins/georeferencer/qgspointdialog.cpp
Expand Up @@ -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());
Expand Down Expand Up @@ -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));
}
Expand All @@ -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;
Expand All @@ -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"))
{
Expand All @@ -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"))
{
Expand All @@ -359,6 +350,8 @@ bool QgsPointDialog::generateWorldFile()
}

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

Expand All @@ -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))
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 271b590

Please sign in to comment.