diff --git a/src/offlinemap.cpp b/src/offlinemap.cpp index 4c44898c..d8238d15 100644 --- a/src/offlinemap.cpp +++ b/src/offlinemap.cpp @@ -244,34 +244,31 @@ bool OfflineMap::createProjection(const QString &datum, return true; } -bool OfflineMap::computeTransformation(const QList &points) +bool OfflineMap::simpleTransformation(const QList &points) { - Q_ASSERT(points.size() >= 2); - - // translate + scale - if (points.size() == 2) { - if (points.at(0).xy.x() == points.at(1).xy.x() - || points.at(0).xy.y() == points.at(1).xy.y()) { - _errorString = "Invalid reference points tuple"; - return false; - } - - QPointF p0(_projection->ll2xy(points.at(0).ll)); - QPointF p1(_projection->ll2xy(points.at(1).ll)); - - qreal dX, dY, lat0, lon0; - dX = (p0.x() - p1.x()) / (points.at(0).xy.x() - points.at(1).xy.x()); - dY = (p1.y() - p0.y()) / (points.at(1).xy.y() - points.at(0).xy.y()); - lat0 = p0.y() - points.at(0).xy.y() * dY; - lon0 = p1.x() - points.at(1).xy.x() * dX; - - _transform = QTransform(1.0/dX, 0, 0, 1.0/dY, -lon0/dX, -lat0/dY); - _inverted = _transform.inverted(); - - return true; + if (points.at(0).xy.x() == points.at(1).xy.x() + || points.at(0).xy.y() == points.at(1).xy.y()) { + _errorString = "Invalid reference points tuple"; + return false; } - // full affine transformation (least squares method) + QPointF p0(_projection->ll2xy(points.at(0).ll)); + QPointF p1(_projection->ll2xy(points.at(1).ll)); + + qreal dX, dY, lat0, lon0; + dX = (p0.x() - p1.x()) / (points.at(0).xy.x() - points.at(1).xy.x()); + dY = (p1.y() - p0.y()) / (points.at(1).xy.y() - points.at(0).xy.y()); + lat0 = p0.y() - points.at(0).xy.y() * dY; + lon0 = p1.x() - points.at(1).xy.x() * dX; + + _transform = QTransform(1.0/dX, 0, 0, 1.0/dY, -lon0/dX, -lat0/dY); + _inverted = _transform.inverted(); + + return true; +} + +bool OfflineMap::affineTransformation(const QList &points) +{ Matrix c(3, 2); c.zeroize(); for (size_t i = 0; i < c.h(); i++) { @@ -317,6 +314,16 @@ bool OfflineMap::computeTransformation(const QList &points) return true; } +bool OfflineMap::computeTransformation(const QList &points) +{ + Q_ASSERT(points.size() >= 2); + + if (points.size() == 2) + return simpleTransformation(points); + else + return affineTransformation(points); +} + bool OfflineMap::computeResolution(QList &points) { Q_ASSERT(points.count() >= 2); diff --git a/src/offlinemap.h b/src/offlinemap.h index 7e2d74fa..93e924ed 100644 --- a/src/offlinemap.h +++ b/src/offlinemap.h @@ -75,6 +75,8 @@ private: bool totalSizeSet(); bool createProjection(const QString &datum, const QString &projection, const ProjectionSetup &setup, QList &points); + bool simpleTransformation(const QList &points); + bool affineTransformation(const QList &points); bool computeTransformation(const QList &points); bool computeResolution(QList &points); bool getTileInfo(const QStringList &tiles, const QString &path = QString());