diff --git a/gpxsee.pro b/gpxsee.pro index 809bb7a6..d0227c07 100644 --- a/gpxsee.pro +++ b/gpxsee.pro @@ -151,7 +151,8 @@ SOURCES += src/main.cpp \ src/tar.cpp \ src/atlas.cpp \ src/mercator.cpp \ - src/transversemercator.cpp + src/transversemercator.cpp \ + src/utm.cpp RESOURCES += gpxsee.qrc TRANSLATIONS = lang/gpxsee_cs.ts \ lang/gpxsee_sv.ts diff --git a/src/offlinemap.cpp b/src/offlinemap.cpp index 353ca953..223b986b 100644 --- a/src/offlinemap.cpp +++ b/src/offlinemap.cpp @@ -128,6 +128,12 @@ int OfflineMap::parseMapFile(QIODevice &device, QList &points, bool OfflineMap::createProjection(const QString &projection, const ProjectionSetup &setup, QList &points) { + if (points.count() < 2) { + qWarning("%s: insufficient number of reference points", + qPrintable(_name)); + return false; + } + if (projection == "Mercator") _projection = new Mercator(); else if (projection == "Transverse Mercator") @@ -135,9 +141,16 @@ bool OfflineMap::createProjection(const QString &projection, setup.falseEasting, setup.falseNorthing); else if (projection == "Latitude/Longitude") _projection = new LatLon(); - else if (projection == "(UTM) Universal Transverse Mercator") - _projection = new UTM(setup.zone); - else { + else if (projection == "(UTM) Universal Transverse Mercator") { + if (setup.zone) + _projection = new UTM(setup.zone); + else if (!points.first().ll.isNull()) + _projection = new UTM(points.first().ll); + else { + qWarning("%s: Can not determine UTM zone", qPrintable(_name)); + return false; + } + } else { qWarning("%s: %s: unsupported map projection", qPrintable(_name), qPrintable(projection)); return false; @@ -152,11 +165,7 @@ bool OfflineMap::createProjection(const QString &projection, bool OfflineMap::computeTransformation(const QList &points) { - if (points.count() < 2) { - qWarning("%s: insufficient number of reference points", - qPrintable(_name)); - return false; - } + Q_ASSERT(points.count() >= 2); Matrix c(3, 2); c.zeroize(); diff --git a/src/transversemercator.cpp b/src/transversemercator.cpp index e4235d92..47868d52 100644 --- a/src/transversemercator.cpp +++ b/src/transversemercator.cpp @@ -3,6 +3,15 @@ #include "wgs84.h" #include "transversemercator.h" + +TransverseMercator::TransverseMercator() +{ + _centralMeridian = 0; + _scale = 1.0; + _falseEasting = 0; + _falseNorthing = 0; +} + TransverseMercator::TransverseMercator(double centralMeridian, double scale, double falseEasting, double falseNorthing) { diff --git a/src/transversemercator.h b/src/transversemercator.h index 00fdf74d..4cf4cc19 100644 --- a/src/transversemercator.h +++ b/src/transversemercator.h @@ -6,6 +6,7 @@ class TransverseMercator : public Projection { public: + TransverseMercator(); TransverseMercator(double centralMeridian, double scale, double falseEasting, double falseNorthing); diff --git a/src/utm.h b/src/utm.h index d7efd122..5a7a3eb5 100644 --- a/src/utm.h +++ b/src/utm.h @@ -9,6 +9,7 @@ class UTM : public Projection public: UTM(int zone) : _tm((qAbs(zone) - 1)*6 - 180 + 3, 0.9996, 500000, zone < 0 ? 10000000 : 0) {} + UTM(const Coordinates &c); virtual QPointF ll2xy(const Coordinates &c) const {return _tm.ll2xy(c);}