mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
Improved map errors reporting
This commit is contained in:
parent
e7d6c3f76a
commit
0f3fea5460
@ -96,8 +96,7 @@ Atlas::Atlas(const QString &fileName, bool TAR, QObject *parent)
|
|||||||
} else {
|
} else {
|
||||||
QFile tbaFile(fileName);
|
QFile tbaFile(fileName);
|
||||||
if (!tbaFile.open(QIODevice::ReadOnly)) {
|
if (!tbaFile.open(QIODevice::ReadOnly)) {
|
||||||
_errorString = QString("Error opening tba file: %1")
|
_errorString = tbaFile.errorString();
|
||||||
.arg(tbaFile.errorString());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ba = tbaFile.readAll();
|
ba = tbaFile.readAll();
|
||||||
@ -121,7 +120,7 @@ Atlas::Atlas(const QString &fileName, bool TAR, QObject *parent)
|
|||||||
if (tar.isOpen())
|
if (tar.isOpen())
|
||||||
map = new OziMap(mapFile, tar, this);
|
map = new OziMap(mapFile, tar, this);
|
||||||
else
|
else
|
||||||
map = new OziMap(mapFile, this);
|
map = new OziMap(mapFile, TAR, this);
|
||||||
|
|
||||||
if (map->isValid())
|
if (map->isValid())
|
||||||
_maps.append(map);
|
_maps.append(map);
|
||||||
|
@ -148,8 +148,7 @@ bool MapFile::parseMapFile(QIODevice &device, QList<CalibrationPoint> &points,
|
|||||||
int el;
|
int el;
|
||||||
|
|
||||||
if (!device.open(QIODevice::ReadOnly)) {
|
if (!device.open(QIODevice::ReadOnly)) {
|
||||||
_errorString = QString("Error opening file: %1")
|
_errorString = device.errorString();
|
||||||
.arg(device.errorString());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ MapList::ParserMap MapList::parsers()
|
|||||||
MapList::ParserMap map;
|
MapList::ParserMap map;
|
||||||
|
|
||||||
map.insert("tar", &Atlas::createTAR);
|
map.insert("tar", &Atlas::createTAR);
|
||||||
map.insert("tar", &OziMap::create);
|
map.insert("tar", &OziMap::createTAR);
|
||||||
map.insert("tba", &Atlas::createTBA);
|
map.insert("tba", &Atlas::createTBA);
|
||||||
map.insert("xml", &MapSource::create);
|
map.insert("xml", &MapSource::create);
|
||||||
map.insert("xml", &IMGMap::createGMAP);
|
map.insert("xml", &IMGMap::createGMAP);
|
||||||
@ -37,7 +37,7 @@ MapList::ParserMap MapList::parsers()
|
|||||||
map.insert("rmap", &RMap::create);
|
map.insert("rmap", &RMap::create);
|
||||||
map.insert("rtmap", &RMap::create);
|
map.insert("rtmap", &RMap::create);
|
||||||
map.insert("map", &MapsforgeMap::create);
|
map.insert("map", &MapsforgeMap::create);
|
||||||
map.insert("map", &OziMap::create);
|
map.insert("map", &OziMap::createMAP);
|
||||||
map.insert("kap", &BSBMap::create);
|
map.insert("kap", &BSBMap::create);
|
||||||
map.insert("kmz", &KMZMap::create);
|
map.insert("kmz", &KMZMap::create);
|
||||||
map.insert("aqm", &AQMMap::create);
|
map.insert("aqm", &AQMMap::create);
|
||||||
@ -71,15 +71,24 @@ Map *MapList::loadFile(const QString &path, const Projection &proj, bool *isDir)
|
|||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
QStringList errors;
|
||||||
|
|
||||||
for (it = _parsers.begin(); it != _parsers.end(); it++) {
|
for (it = _parsers.begin(); it != _parsers.end(); it++) {
|
||||||
map = it.value()(path, proj, isDir);
|
map = it.value()(path, proj, isDir);
|
||||||
if (map->isValid())
|
if (map->isValid())
|
||||||
break;
|
break;
|
||||||
else {
|
else {
|
||||||
|
errors.append(it.key() + ": " + map->errorString());
|
||||||
delete map;
|
delete map;
|
||||||
map = 0;
|
map = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!map) {
|
||||||
|
qWarning("Error loading map file: %s:", qPrintable(path));
|
||||||
|
for (int i = 0; i < errors.size(); i++)
|
||||||
|
qWarning(qPrintable(errors.at(i)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return map ? map : new InvalidMap(path, "Unknown file format");
|
return map ? map : new InvalidMap(path, "Unknown file format");
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
using namespace Mapsforge;
|
using namespace Mapsforge;
|
||||||
|
|
||||||
#define MAGIC "mapsforge binary OSM"
|
#define MAGIC "mapsforge binary OSM"
|
||||||
|
#define MAGIC_SIZE (sizeof(MAGIC) - 1)
|
||||||
#define MD(val) ((val) / 1e6)
|
#define MD(val) ((val) / 1e6)
|
||||||
#define OFFSET_MASK 0x7FFFFFFFFFL
|
#define OFFSET_MASK 0x7FFFFFFFFFL
|
||||||
|
|
||||||
@ -282,43 +283,68 @@ bool MapData::readSubFiles()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MapData::readHeader()
|
bool MapData::readZoomInfo(SubFile &subfile)
|
||||||
|
{
|
||||||
|
quint8 zooms;
|
||||||
|
|
||||||
|
if (!subfile.readByte(zooms))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
_subFiles.resize(zooms);
|
||||||
|
for (quint8 i = 0; i < zooms; i++) {
|
||||||
|
if (!(subfile.readByte(_subFiles[i].base)
|
||||||
|
&& subfile.readByte(_subFiles[i].min)
|
||||||
|
&& subfile.readByte(_subFiles[i].max)
|
||||||
|
&& subfile.readUInt64(_subFiles[i].offset)
|
||||||
|
&& subfile.readUInt64(_subFiles[i].size)))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MapData::readTagInfo(SubFile &subfile)
|
||||||
{
|
{
|
||||||
char magic[sizeof(MAGIC) - 1];
|
|
||||||
quint32 hdrSize, version;
|
|
||||||
quint64 fileSize, date;
|
|
||||||
qint32 minLat, minLon, maxLat, maxLon;
|
|
||||||
quint16 tags;
|
quint16 tags;
|
||||||
quint8 flags, zooms;
|
QByteArray tag;
|
||||||
QByteArray projection, tag;
|
|
||||||
|
|
||||||
|
if (!subfile.readUInt16(tags))
|
||||||
|
return false;
|
||||||
|
_pointTags.resize(tags);
|
||||||
|
for (quint16 i = 0; i < tags; i++) {
|
||||||
|
if (!subfile.readString(tag))
|
||||||
|
return false;
|
||||||
|
_pointTags[i] = tag;
|
||||||
|
}
|
||||||
|
|
||||||
if (_file.read(magic, sizeof(magic)) < (int)sizeof(magic)
|
if (!subfile.readUInt16(tags))
|
||||||
|| memcmp(magic, MAGIC, sizeof(magic)))
|
|
||||||
return false;
|
|
||||||
if (_file.read((char*)&hdrSize, sizeof(hdrSize)) < (qint64)sizeof(hdrSize))
|
|
||||||
return false;
|
return false;
|
||||||
|
_pathTags.resize(tags);
|
||||||
|
for (quint16 i = 0; i < tags; i++) {
|
||||||
|
if (!subfile.readString(tag))
|
||||||
|
return false;
|
||||||
|
_pathTags[i] = tag;
|
||||||
|
}
|
||||||
|
|
||||||
SubFile subfile(_file, sizeof(magic) + sizeof(hdrSize),
|
return true;
|
||||||
qFromBigEndian(hdrSize));
|
}
|
||||||
if (!subfile.seek(0))
|
|
||||||
return false;
|
bool MapData::readMapInfo(SubFile &subfile, QByteArray &projection,
|
||||||
if (!(subfile.readUInt32(version) && subfile.readUInt64(fileSize)
|
bool &debugMap)
|
||||||
|
{
|
||||||
|
quint64 fileSize, date;
|
||||||
|
quint32 version;
|
||||||
|
qint32 minLat, minLon, maxLat, maxLon;
|
||||||
|
quint8 flags;
|
||||||
|
|
||||||
|
if (!(subfile.seek(MAGIC_SIZE + 4)
|
||||||
|
&& subfile.readUInt32(version) && subfile.readUInt64(fileSize)
|
||||||
&& subfile.readUInt64(date) && subfile.readInt32(minLat)
|
&& subfile.readUInt64(date) && subfile.readInt32(minLat)
|
||||||
&& subfile.readInt32(minLon) && subfile.readInt32(maxLat)
|
&& subfile.readInt32(minLon) && subfile.readInt32(maxLat)
|
||||||
&& subfile.readInt32(maxLon) && subfile.readUInt16(_tileSize)
|
&& subfile.readInt32(maxLon) && subfile.readUInt16(_tileSize)
|
||||||
&& subfile.readString(projection) && subfile.readByte(flags)))
|
&& subfile.readString(projection) && subfile.readByte(flags)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (projection != "Mercator") {
|
|
||||||
_errorString = projection + ": invalid/unsupported projection";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (flags & 0x80) {
|
|
||||||
_errorString = "DEBUG maps not supported";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & 0x40) {
|
if (flags & 0x40) {
|
||||||
qint32 startLon, startLat;
|
qint32 startLon, startLat;
|
||||||
if (!(subfile.readInt32(startLat) && subfile.readInt32(startLon)))
|
if (!(subfile.readInt32(startLat) && subfile.readInt32(startLon)))
|
||||||
@ -345,39 +371,58 @@ bool MapData::readHeader()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!subfile.readUInt16(tags))
|
|
||||||
return false;
|
|
||||||
_pointTags.resize(tags);
|
|
||||||
for (quint16 i = 0; i < tags; i++) {
|
|
||||||
if (!subfile.readString(tag))
|
|
||||||
return false;
|
|
||||||
_pointTags[i] = tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!subfile.readUInt16(tags))
|
|
||||||
return false;
|
|
||||||
_pathTags.resize(tags);
|
|
||||||
for (quint16 i = 0; i < tags; i++) {
|
|
||||||
if (!subfile.readString(tag))
|
|
||||||
return false;
|
|
||||||
_pathTags[i] = tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!subfile.readByte(zooms))
|
|
||||||
return false;
|
|
||||||
_subFiles.resize(zooms);
|
|
||||||
for (quint8 i = 0; i < zooms; i++) {
|
|
||||||
if (!(subfile.readByte(_subFiles[i].base)
|
|
||||||
&& subfile.readByte(_subFiles[i].min)
|
|
||||||
&& subfile.readByte(_subFiles[i].max)
|
|
||||||
&& subfile.readUInt64(_subFiles[i].offset)
|
|
||||||
&& subfile.readUInt64(_subFiles[i].size)))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_bounds = RectC(Coordinates(MD(minLon), MD(maxLat)),
|
_bounds = RectC(Coordinates(MD(minLon), MD(maxLat)),
|
||||||
Coordinates(MD(maxLon), MD(minLat)));
|
Coordinates(MD(maxLon), MD(minLat)));
|
||||||
_bounds &= OSM::BOUNDS;
|
_bounds &= OSM::BOUNDS;
|
||||||
|
debugMap = flags & 0x80;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MapData::readHeader()
|
||||||
|
{
|
||||||
|
char magic[MAGIC_SIZE];
|
||||||
|
quint32 hdrSize;
|
||||||
|
QByteArray projection;
|
||||||
|
bool debugMap;
|
||||||
|
|
||||||
|
|
||||||
|
if (_file.read(magic, MAGIC_SIZE) < (qint64)MAGIC_SIZE
|
||||||
|
|| memcmp(magic, MAGIC, MAGIC_SIZE)) {
|
||||||
|
_errorString = "Not a Mapsforge map";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_file.read((char*)&hdrSize, sizeof(hdrSize)) < (qint64)sizeof(hdrSize)) {
|
||||||
|
_errorString = "Unexpected EOF";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SubFile subfile(_file, 0, qFromBigEndian(hdrSize));
|
||||||
|
|
||||||
|
if (!readMapInfo(subfile, projection, debugMap)) {
|
||||||
|
_errorString = "Error reading map info";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!readTagInfo(subfile)) {
|
||||||
|
_errorString = "Error reading tags info";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!readZoomInfo(subfile)) {
|
||||||
|
_errorString = "Error reading zooms info";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (projection != "Mercator") {
|
||||||
|
_errorString = projection + ": invalid/unsupported projection";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (debugMap) {
|
||||||
|
_errorString = "DEBUG maps not supported";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
namespace Mapsforge {
|
namespace Mapsforge {
|
||||||
|
|
||||||
|
class SubFile;
|
||||||
|
|
||||||
class MapData
|
class MapData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -129,6 +131,9 @@ private:
|
|||||||
|
|
||||||
typedef RTree<VectorTile *, double, 2> TileTree;
|
typedef RTree<VectorTile *, double, 2> TileTree;
|
||||||
|
|
||||||
|
bool readZoomInfo(SubFile &subfile);
|
||||||
|
bool readTagInfo(SubFile &subfile);
|
||||||
|
bool readMapInfo(SubFile &subfile, QByteArray &projection, bool &debugMap);
|
||||||
bool readHeader();
|
bool readHeader();
|
||||||
bool readSubFiles();
|
bool readSubFiles();
|
||||||
void clearTiles();
|
void clearTiles();
|
||||||
|
@ -17,15 +17,13 @@
|
|||||||
#include "ozimap.h"
|
#include "ozimap.h"
|
||||||
|
|
||||||
|
|
||||||
OziMap::OziMap(const QString &fileName, QObject *parent)
|
OziMap::OziMap(const QString &fileName, bool TAR, QObject *parent)
|
||||||
: Map(fileName, parent), _img(0), _tar(0), _ozf(0), _zoom(0), _mapRatio(1.0),
|
: Map(fileName, parent), _img(0), _tar(0), _ozf(0), _zoom(0), _mapRatio(1.0),
|
||||||
_valid(false)
|
_valid(false)
|
||||||
{
|
{
|
||||||
QFileInfo fi(fileName);
|
QFileInfo fi(fileName);
|
||||||
QString suffix = fi.suffix().toLower();
|
|
||||||
|
|
||||||
|
if (TAR) {
|
||||||
if (suffix == "tar") {
|
|
||||||
_tar = new Tar(fileName);
|
_tar = new Tar(fileName);
|
||||||
if (!_tar->open()) {
|
if (!_tar->open()) {
|
||||||
_errorString = "Error reading tar file";
|
_errorString = "Error reading tar file";
|
||||||
@ -380,10 +378,18 @@ void OziMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
|
|||||||
_img->setDevicePixelRatio(_mapRatio);
|
_img->setDevicePixelRatio(_mapRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map *OziMap::create(const QString &path, const Projection &, bool *isDir)
|
Map *OziMap::createTAR(const QString &path, const Projection &, bool *isDir)
|
||||||
{
|
{
|
||||||
if (isDir)
|
if (isDir)
|
||||||
*isDir = true;
|
*isDir = true;
|
||||||
|
|
||||||
return new OziMap(path);
|
return new OziMap(path, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map *OziMap::createMAP(const QString &path, const Projection &, bool *isDir)
|
||||||
|
{
|
||||||
|
if (isDir)
|
||||||
|
*isDir = true;
|
||||||
|
|
||||||
|
return new OziMap(path, false);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ class OziMap : public Map
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OziMap(const QString &fileName, QObject *parent = 0);
|
OziMap(const QString &fileName, bool TAR, QObject *parent = 0);
|
||||||
OziMap(const QString &fileName, Tar &tar, QObject *parent = 0);
|
OziMap(const QString &fileName, Tar &tar, QObject *parent = 0);
|
||||||
~OziMap();
|
~OziMap();
|
||||||
|
|
||||||
@ -47,7 +47,8 @@ public:
|
|||||||
QPointF pp2xy(const PointD &p) const
|
QPointF pp2xy(const PointD &p) const
|
||||||
{return _transform.proj2img(p) / _mapRatio;}
|
{return _transform.proj2img(p) / _mapRatio;}
|
||||||
|
|
||||||
static Map *create(const QString &path, const Projection &, bool *isDir);
|
static Map *createTAR(const QString &path, const Projection &, bool *isDir);
|
||||||
|
static Map *createMAP(const QString &path, const Projection &, bool *isDir);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct ImageInfo {
|
struct ImageInfo {
|
||||||
|
Loading…
Reference in New Issue
Block a user