mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 11:45:53 +01:00
Rather read the files twice than storing all the data in memory
This commit is contained in:
parent
75100cd500
commit
59523f46ef
@ -115,22 +115,12 @@ static uint depthLevel(const QString &str)
|
|||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
RectC MapData::Line::bounds() const
|
static Coordinates coordinates(int x, int y, uint COMF)
|
||||||
{
|
{
|
||||||
RectC b;
|
return Coordinates(x / (double)COMF, y / (double)COMF);
|
||||||
|
|
||||||
for (int i = 0; i < _path.size(); i++)
|
|
||||||
b = b.united(_path.at(i));
|
|
||||||
|
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Coordinates MapData::coordinates(int x, int y) const
|
static Coordinates point(const ISO8211::Record &r, uint COMF)
|
||||||
{
|
|
||||||
return Coordinates(x / (double)_COMF, y / (double)_COMF);
|
|
||||||
}
|
|
||||||
|
|
||||||
Coordinates MapData::point(const ISO8211::Record &r)
|
|
||||||
{
|
{
|
||||||
const ISO8211::Field *f = SGXD(r);
|
const ISO8211::Field *f = SGXD(r);
|
||||||
if (!f)
|
if (!f)
|
||||||
@ -139,10 +129,11 @@ Coordinates MapData::point(const ISO8211::Record &r)
|
|||||||
int y = f->data().at(0).at(0).toInt();
|
int y = f->data().at(0).at(0).toInt();
|
||||||
int x = f->data().at(0).at(1).toInt();
|
int x = f->data().at(0).at(1).toInt();
|
||||||
|
|
||||||
return coordinates(x, y);
|
return coordinates(x, y, COMF);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<MapData::Sounding> MapData::soundings(const ISO8211::Record &r)
|
QVector<MapData::Sounding> MapData::soundings(const ISO8211::Record &r,
|
||||||
|
uint COMF, uint SOMF)
|
||||||
{
|
{
|
||||||
QVector<Sounding> s;
|
QVector<Sounding> s;
|
||||||
const ISO8211::Field *f = r.field("SG3D");
|
const ISO8211::Field *f = r.field("SG3D");
|
||||||
@ -154,13 +145,14 @@ QVector<MapData::Sounding> MapData::soundings(const ISO8211::Record &r)
|
|||||||
int y = f->data().at(i).at(0).toInt();
|
int y = f->data().at(i).at(0).toInt();
|
||||||
int x = f->data().at(i).at(1).toInt();
|
int x = f->data().at(i).at(1).toInt();
|
||||||
int z = f->data().at(i).at(2).toInt();
|
int z = f->data().at(i).at(2).toInt();
|
||||||
s.append(Sounding(coordinates(x, y), z / (double)_SOMF));
|
s.append(Sounding(coordinates(x, y, COMF), z / (double)SOMF));
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<MapData::Sounding> MapData::soundingGeometry(const ISO8211::Record &r)
|
QVector<MapData::Sounding> MapData::soundingGeometry(const ISO8211::Record &r,
|
||||||
|
const RecordMap &vi, const RecordMap &vc, uint COMF, uint SOMF)
|
||||||
{
|
{
|
||||||
quint8 type;
|
quint8 type;
|
||||||
quint32 id;
|
quint32 id;
|
||||||
@ -173,21 +165,22 @@ QVector<MapData::Sounding> MapData::soundingGeometry(const ISO8211::Record &r)
|
|||||||
if (!parseNAME(FSPT, &type, &id))
|
if (!parseNAME(FSPT, &type, &id))
|
||||||
return QVector<Sounding>();
|
return QVector<Sounding>();
|
||||||
|
|
||||||
if (type == RCNM_VI)
|
if (type == RCNM_VI) {
|
||||||
it = _vi.find(id);
|
it = vi.find(id);
|
||||||
else if (type == RCNM_VC)
|
if (it == vi.constEnd())
|
||||||
it = _vc.find(id);
|
return QVector<Sounding>();
|
||||||
else
|
} else if (type == RCNM_VC) {
|
||||||
return QVector<Sounding>();
|
it = vc.find(id);
|
||||||
if (it == _ve.constEnd())
|
if (it == vc.constEnd())
|
||||||
|
return QVector<Sounding>();
|
||||||
|
} else
|
||||||
return QVector<Sounding>();
|
return QVector<Sounding>();
|
||||||
|
|
||||||
const ISO8211::Record &FRID = it.value();
|
return soundings(it.value(), COMF, SOMF);
|
||||||
|
|
||||||
return soundings(FRID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Coordinates MapData::pointGeometry(const ISO8211::Record &r)
|
Coordinates MapData::pointGeometry(const ISO8211::Record &r,
|
||||||
|
const RecordMap &vi, const RecordMap &vc, uint COMF)
|
||||||
{
|
{
|
||||||
quint8 type;
|
quint8 type;
|
||||||
quint32 id;
|
quint32 id;
|
||||||
@ -200,21 +193,22 @@ Coordinates MapData::pointGeometry(const ISO8211::Record &r)
|
|||||||
if (!parseNAME(FSPT, &type, &id))
|
if (!parseNAME(FSPT, &type, &id))
|
||||||
return Coordinates();
|
return Coordinates();
|
||||||
|
|
||||||
if (type == RCNM_VI)
|
if (type == RCNM_VI) {
|
||||||
it = _vi.find(id);
|
it = vi.find(id);
|
||||||
else if (type == RCNM_VC)
|
if (it == vi.constEnd())
|
||||||
it = _vc.find(id);
|
return Coordinates();
|
||||||
else
|
} else if (type == RCNM_VC) {
|
||||||
return Coordinates();
|
it = vc.find(id);
|
||||||
if (it == _ve.constEnd())
|
if (it == vc.constEnd())
|
||||||
|
return Coordinates();
|
||||||
|
} else
|
||||||
return Coordinates();
|
return Coordinates();
|
||||||
|
|
||||||
const ISO8211::Record &FRID = it.value();
|
return point(it.value(), COMF);
|
||||||
|
|
||||||
return point(FRID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<Coordinates> MapData::lineGeometry(const ISO8211::Record &r)
|
QVector<Coordinates> MapData::lineGeometry(const ISO8211::Record &r,
|
||||||
|
const RecordMap &vc, const RecordMap &ve, uint COMF)
|
||||||
{
|
{
|
||||||
QVector<Coordinates> path;
|
QVector<Coordinates> path;
|
||||||
Coordinates c[2];
|
Coordinates c[2];
|
||||||
@ -233,8 +227,8 @@ QVector<Coordinates> MapData::lineGeometry(const ISO8211::Record &r)
|
|||||||
MASK = FSPT->data().at(i).at(3).toUInt();
|
MASK = FSPT->data().at(i).at(3).toUInt();
|
||||||
Q_ASSERT(MASK != 1);
|
Q_ASSERT(MASK != 1);
|
||||||
|
|
||||||
RecordMapIterator it = _ve.find(id);
|
RecordMapIterator it = ve.find(id);
|
||||||
if (it == _ve.constEnd())
|
if (it == ve.constEnd())
|
||||||
return QVector<Coordinates>();
|
return QVector<Coordinates>();
|
||||||
const ISO8211::Record &FRID = it.value();
|
const ISO8211::Record &FRID = it.value();
|
||||||
const ISO8211::Field *VRPT = FRID.field("VRPT");
|
const ISO8211::Field *VRPT = FRID.field("VRPT");
|
||||||
@ -245,10 +239,10 @@ QVector<Coordinates> MapData::lineGeometry(const ISO8211::Record &r)
|
|||||||
if (!parseNAME(VRPT, &type, &id, j) || type != RCNM_VC)
|
if (!parseNAME(VRPT, &type, &id, j) || type != RCNM_VC)
|
||||||
return QVector<Coordinates>();
|
return QVector<Coordinates>();
|
||||||
|
|
||||||
RecordMapIterator jt = _vc.find(id);
|
RecordMapIterator jt = vc.find(id);
|
||||||
if (jt == _vc.constEnd())
|
if (jt == vc.constEnd())
|
||||||
return QVector<Coordinates>();
|
return QVector<Coordinates>();
|
||||||
c[j] = point(jt.value());
|
c[j] = point(jt.value(), COMF);
|
||||||
if (c[j].isNull())
|
if (c[j].isNull())
|
||||||
return QVector<Coordinates>();
|
return QVector<Coordinates>();
|
||||||
}
|
}
|
||||||
@ -259,7 +253,8 @@ QVector<Coordinates> MapData::lineGeometry(const ISO8211::Record &r)
|
|||||||
if (vertexes) {
|
if (vertexes) {
|
||||||
for (int j = vertexes->data().size() - 1; j >= 0; j--) {
|
for (int j = vertexes->data().size() - 1; j >= 0; j--) {
|
||||||
const QVector<QVariant> &cv = vertexes->data().at(j);
|
const QVector<QVariant> &cv = vertexes->data().at(j);
|
||||||
path.append(coordinates(cv.at(1).toInt(), cv.at(0).toInt()));
|
path.append(coordinates(cv.at(1).toInt(), cv.at(0).toInt(),
|
||||||
|
COMF));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
path.append(c[0]);
|
path.append(c[0]);
|
||||||
@ -268,7 +263,8 @@ QVector<Coordinates> MapData::lineGeometry(const ISO8211::Record &r)
|
|||||||
if (vertexes) {
|
if (vertexes) {
|
||||||
for (int j = 0; j < vertexes->data().size(); j++) {
|
for (int j = 0; j < vertexes->data().size(); j++) {
|
||||||
const QVector<QVariant> &cv = vertexes->data().at(j);
|
const QVector<QVariant> &cv = vertexes->data().at(j);
|
||||||
path.append(coordinates(cv.at(1).toInt(), cv.at(0).toInt()));
|
path.append(coordinates(cv.at(1).toInt(), cv.at(0).toInt(),
|
||||||
|
COMF));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
path.append(c[1]);
|
path.append(c[1]);
|
||||||
@ -278,7 +274,8 @@ QVector<Coordinates> MapData::lineGeometry(const ISO8211::Record &r)
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
Polygon MapData::polyGeometry(const ISO8211::Record &r)
|
Polygon MapData::polyGeometry(const ISO8211::Record &r, const RecordMap &vc,
|
||||||
|
const RecordMap &ve, uint COMF)
|
||||||
{
|
{
|
||||||
Polygon path;
|
Polygon path;
|
||||||
QVector<Coordinates> v;
|
QVector<Coordinates> v;
|
||||||
@ -304,8 +301,8 @@ Polygon MapData::polyGeometry(const ISO8211::Record &r)
|
|||||||
v.clear();
|
v.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
RecordMapIterator it = _ve.find(id);
|
RecordMapIterator it = ve.find(id);
|
||||||
if (it == _ve.constEnd())
|
if (it == ve.constEnd())
|
||||||
return Polygon();
|
return Polygon();
|
||||||
const ISO8211::Record &FRID = it.value();
|
const ISO8211::Record &FRID = it.value();
|
||||||
const ISO8211::Field *VRPT = FRID.field("VRPT");
|
const ISO8211::Field *VRPT = FRID.field("VRPT");
|
||||||
@ -316,10 +313,10 @@ Polygon MapData::polyGeometry(const ISO8211::Record &r)
|
|||||||
if (!parseNAME(VRPT, &type, &id, j) || type != RCNM_VC)
|
if (!parseNAME(VRPT, &type, &id, j) || type != RCNM_VC)
|
||||||
return Polygon();
|
return Polygon();
|
||||||
|
|
||||||
RecordMapIterator jt = _vc.find(id);
|
RecordMapIterator jt = vc.find(id);
|
||||||
if (jt == _vc.constEnd())
|
if (jt == vc.constEnd())
|
||||||
return Polygon();
|
return Polygon();
|
||||||
c[j] = point(jt.value());
|
c[j] = point(jt.value(), COMF);
|
||||||
if (c[j].isNull())
|
if (c[j].isNull())
|
||||||
return Polygon();
|
return Polygon();
|
||||||
}
|
}
|
||||||
@ -330,7 +327,8 @@ Polygon MapData::polyGeometry(const ISO8211::Record &r)
|
|||||||
if (vertexes) {
|
if (vertexes) {
|
||||||
for (int j = vertexes->data().size() - 1; j >= 0; j--) {
|
for (int j = vertexes->data().size() - 1; j >= 0; j--) {
|
||||||
const QVector<QVariant> &cv = vertexes->data().at(j);
|
const QVector<QVariant> &cv = vertexes->data().at(j);
|
||||||
v.append(coordinates(cv.at(1).toInt(), cv.at(0).toInt()));
|
v.append(coordinates(cv.at(1).toInt(), cv.at(0).toInt(),
|
||||||
|
COMF));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v.append(c[0]);
|
v.append(c[0]);
|
||||||
@ -339,7 +337,8 @@ Polygon MapData::polyGeometry(const ISO8211::Record &r)
|
|||||||
if (vertexes) {
|
if (vertexes) {
|
||||||
for (int j = 0; j < vertexes->data().size(); j++) {
|
for (int j = 0; j < vertexes->data().size(); j++) {
|
||||||
const QVector<QVariant> &cv = vertexes->data().at(j);
|
const QVector<QVariant> &cv = vertexes->data().at(j);
|
||||||
v.append(coordinates(cv.at(1).toInt(), cv.at(0).toInt()));
|
v.append(coordinates(cv.at(1).toInt(), cv.at(0).toInt(),
|
||||||
|
COMF));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v.append(c[1]);
|
v.append(c[1]);
|
||||||
@ -432,33 +431,59 @@ MapData::Point *MapData::pointObject(const Sounding &s)
|
|||||||
return new Point(SOUNDG<<16, s.c, QString::number(s.depth));
|
return new Point(SOUNDG<<16, s.c, QString::number(s.depth));
|
||||||
}
|
}
|
||||||
|
|
||||||
MapData::Point *MapData::pointObject(const ISO8211::Record &r, uint OBJL)
|
MapData::Point *MapData::pointObject(const ISO8211::Record &r,
|
||||||
|
const RecordMap &vi, const RecordMap &vc, uint COMF, uint OBJL)
|
||||||
{
|
{
|
||||||
Coordinates c(pointGeometry(r));
|
Coordinates c(pointGeometry(r, vi, vc, COMF));
|
||||||
Attr attr(pointAttr(r, OBJL));
|
Attr attr(pointAttr(r, OBJL));
|
||||||
|
|
||||||
return (c.isNull() ? 0 : new Point(OBJL<<16|attr.subtype(), c,
|
return (c.isNull() ? 0 : new Point(OBJL<<16|attr.subtype(), c,
|
||||||
attr.label()));
|
attr.label()));
|
||||||
}
|
}
|
||||||
|
|
||||||
MapData::Line *MapData::lineObject(const ISO8211::Record &r, uint OBJL)
|
MapData::Line *MapData::lineObject(const ISO8211::Record &r,
|
||||||
|
const RecordMap &vc, const RecordMap &ve, uint COMF, uint OBJL)
|
||||||
{
|
{
|
||||||
QVector<Coordinates> path(lineGeometry(r));
|
QVector<Coordinates> path(lineGeometry(r, vc, ve, COMF));
|
||||||
Attr attr(lineAttr(r, OBJL));
|
Attr attr(lineAttr(r, OBJL));
|
||||||
|
|
||||||
return (path.isEmpty() ? 0 : new Line(OBJL<<16|attr.subtype(), path,
|
return (path.isEmpty() ? 0 : new Line(OBJL<<16|attr.subtype(), path,
|
||||||
attr.label()));
|
attr.label()));
|
||||||
}
|
}
|
||||||
|
|
||||||
MapData::Poly *MapData::polyObject(const ISO8211::Record &r, uint OBJL)
|
MapData::Poly *MapData::polyObject(const ISO8211::Record &r,
|
||||||
|
const RecordMap &vc, const RecordMap &ve, uint COMF, uint OBJL)
|
||||||
{
|
{
|
||||||
Polygon path(polyGeometry(r));
|
Polygon path(polyGeometry(r, vc, ve, COMF));
|
||||||
Attr attr(polyAttr(r, OBJL));
|
Attr attr(polyAttr(r, OBJL));
|
||||||
|
|
||||||
return (path.isEmpty() ? 0 : new Poly(OBJL<<16|attr.subtype(), path));
|
return (path.isEmpty() ? 0 : new Poly(OBJL<<16|attr.subtype(), path));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MapData::processRecord(const ISO8211::Record &record)
|
bool MapData::processRecord(const ISO8211::Record &record,
|
||||||
|
QVector<ISO8211::Record> &rv, uint &COMF, QString &name)
|
||||||
|
{
|
||||||
|
const ISO8211::Field &f = record.at(1);
|
||||||
|
const QByteArray &ba = f.tag();
|
||||||
|
|
||||||
|
if (ba == "VRID") {
|
||||||
|
rv.append(record);
|
||||||
|
} else if (ba == "DSID") {
|
||||||
|
QByteArray DSNM;
|
||||||
|
if (!f.subfield("DSNM", &DSNM))
|
||||||
|
return false;
|
||||||
|
name = DSNM;
|
||||||
|
} else if (ba == "DSPM") {
|
||||||
|
if (!f.subfield("COMF", &COMF))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MapData::processRecord(const ISO8211::Record &record,
|
||||||
|
QVector<ISO8211::Record> &fe, RecordMap &vi, RecordMap &vc, RecordMap &ve,
|
||||||
|
RecordMap &vf, uint &COMF, uint &SOMF)
|
||||||
{
|
{
|
||||||
const ISO8211::Field &f = record.at(1);
|
const ISO8211::Field &f = record.at(1);
|
||||||
const QByteArray &ba = f.tag();
|
const QByteArray &ba = f.tag();
|
||||||
@ -471,31 +496,24 @@ bool MapData::processRecord(const ISO8211::Record &record)
|
|||||||
|
|
||||||
switch (RCNM) {
|
switch (RCNM) {
|
||||||
case RCNM_VI:
|
case RCNM_VI:
|
||||||
_vi.insert(RCID, record);
|
vi.insert(RCID, record);
|
||||||
break;
|
break;
|
||||||
case RCNM_VC:
|
case RCNM_VC:
|
||||||
_vc.insert(RCID, record);
|
vc.insert(RCID, record);
|
||||||
break;
|
break;
|
||||||
case RCNM_VE:
|
case RCNM_VE:
|
||||||
_ve.insert(RCID, record);
|
ve.insert(RCID, record);
|
||||||
break;
|
break;
|
||||||
case RCNM_VF:
|
case RCNM_VF:
|
||||||
_vf.insert(RCID, record);
|
vf.insert(RCID, record);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (ba == "FRID") {
|
} else if (ba == "FRID") {
|
||||||
_fe.append(record);
|
fe.append(record);
|
||||||
} else if (ba == "DSID") {
|
|
||||||
QByteArray DSNM;
|
|
||||||
|
|
||||||
if (!f.subfield("DSNM", &DSNM))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
_name = DSNM;
|
|
||||||
} else if (ba == "DSPM") {
|
} else if (ba == "DSPM") {
|
||||||
if (!(f.subfield("COMF", &_COMF) && f.subfield("SOMF", &_SOMF)))
|
if (!(f.subfield("COMF", &COMF) && f.subfield("SOMF", &SOMF)))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,9 +523,10 @@ bool MapData::processRecord(const ISO8211::Record &record)
|
|||||||
bool MapData::bounds(const ISO8211::Record &record, Rect &rect)
|
bool MapData::bounds(const ISO8211::Record &record, Rect &rect)
|
||||||
{
|
{
|
||||||
bool xok, yok;
|
bool xok, yok;
|
||||||
|
// edge geometries can be empty!
|
||||||
const ISO8211::Field *f = SGXD(record);
|
const ISO8211::Field *f = SGXD(record);
|
||||||
if (!f)
|
if (!f)
|
||||||
return false;
|
return true;
|
||||||
|
|
||||||
for (int i = 0; i < f->data().size(); i++) {
|
for (int i = 0; i < f->data().size(); i++) {
|
||||||
const QVector<QVariant> &c = f->data().at(i);
|
const QVector<QVariant> &c = f->data().at(i);
|
||||||
@ -519,54 +538,64 @@ bool MapData::bounds(const ISO8211::Record &record, Rect &rect)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
MapData::Rect MapData::bounds(const RecordMap &map)
|
bool MapData::bounds(const QVector<ISO8211::Record> &gv, Rect &b)
|
||||||
{
|
{
|
||||||
Rect b, r;
|
Rect r;
|
||||||
|
|
||||||
for (RecordMapIterator it = map.constBegin(); it != map.constEnd(); ++it)
|
for (int i = 0; i < gv.size(); i++) {
|
||||||
if (bounds(it.value(), r))
|
if (!bounds(gv.at(i), r))
|
||||||
b |= r;
|
return false;
|
||||||
|
b |= r;
|
||||||
|
}
|
||||||
|
|
||||||
return b;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RectC MapData::bounds() const
|
bool MapData::fetchBoundsAndName()
|
||||||
{
|
{
|
||||||
const RecordMap *maps[] = {&_vi, &_vc, &_ve, &_vf};
|
QFile file(_fileName);
|
||||||
Rect b;
|
QVector<ISO8211::Record> gv;
|
||||||
|
ISO8211 ddf;
|
||||||
for (size_t i = 0; i < ARRAY_SIZE(maps); i++)
|
uint COMF = 1;
|
||||||
b |= bounds(*maps[i]);
|
|
||||||
|
|
||||||
return RectC(
|
|
||||||
Coordinates(b.minX() / (double)_COMF, b.maxY() / (double)_COMF),
|
|
||||||
Coordinates(b.maxX() / (double)_COMF, b.minY() / (double)_COMF));
|
|
||||||
}
|
|
||||||
|
|
||||||
MapData::MapData(const QString &path): _valid(false)
|
|
||||||
{
|
|
||||||
QFile file(path);
|
|
||||||
|
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
_errorString = file.errorString();
|
_errorString = file.errorString();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_ddf.readDDR(file)) {
|
if (!ddf.readDDR(file)) {
|
||||||
_errorString = _ddf.errorString();
|
_errorString = ddf.errorString();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
while (!file.atEnd()) {
|
while (!file.atEnd()) {
|
||||||
ISO8211::Record record;
|
ISO8211::Record record;
|
||||||
if (!_ddf.readRecord(file, record)) {
|
if (!ddf.readRecord(file, record)) {
|
||||||
_errorString = _ddf.errorString();
|
_errorString = ddf.errorString();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if (!processRecord(record))
|
if (!processRecord(record, gv, COMF, _name))
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_valid = true;
|
Rect b;
|
||||||
|
if (!bounds(gv, b)) {
|
||||||
|
_errorString = "Error fetching geometries bounds";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
RectC br(Coordinates(b.minX() / (double)COMF, b.maxY() / (double)COMF),
|
||||||
|
Coordinates(b.maxX() / (double)COMF, b.minY() / (double)COMF));
|
||||||
|
if (!br.isValid()) {
|
||||||
|
_errorString = "Invalid geometries bounds";
|
||||||
|
return false;
|
||||||
|
} else
|
||||||
|
_bounds = br;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
MapData::MapData(const QString &path): _fileName(path)
|
||||||
|
{
|
||||||
|
fetchBoundsAndName();
|
||||||
}
|
}
|
||||||
|
|
||||||
MapData::~MapData()
|
MapData::~MapData()
|
||||||
@ -586,14 +615,33 @@ MapData::~MapData()
|
|||||||
|
|
||||||
void MapData::load()
|
void MapData::load()
|
||||||
{
|
{
|
||||||
|
QFile file(_fileName);
|
||||||
|
RecordMap vi, vc, ve, vf;
|
||||||
|
QVector<ISO8211::Record> fe;
|
||||||
|
uint COMF = 1, SOMF = 1;
|
||||||
|
ISO8211 ddf;
|
||||||
uint PRIM, OBJL;
|
uint PRIM, OBJL;
|
||||||
Poly *poly;
|
Poly *poly;
|
||||||
Line *line;
|
Line *line;
|
||||||
Point *point;
|
Point *point;
|
||||||
double min[2], max[2];
|
double min[2], max[2];
|
||||||
|
|
||||||
for (int i = 0; i < _fe.size(); i++) {
|
|
||||||
const ISO8211::Record &r = _fe.at(i);
|
if (!file.open(QIODevice::ReadOnly))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!ddf.readDDR(file))
|
||||||
|
return;
|
||||||
|
while (!file.atEnd()) {
|
||||||
|
ISO8211::Record record;
|
||||||
|
if (!ddf.readRecord(file, record))
|
||||||
|
return;
|
||||||
|
if (!processRecord(record, fe, vi, vc, ve, vf, COMF, SOMF))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < fe.size(); i++) {
|
||||||
|
const ISO8211::Record &r = fe.at(i);
|
||||||
const ISO8211::Field &f = r.at(1);
|
const ISO8211::Field &f = r.at(1);
|
||||||
|
|
||||||
if (f.data().at(0).size() < 5)
|
if (f.data().at(0).size() < 5)
|
||||||
@ -604,14 +652,14 @@ void MapData::load()
|
|||||||
switch (PRIM) {
|
switch (PRIM) {
|
||||||
case PRIM_P:
|
case PRIM_P:
|
||||||
if (OBJL == SOUNDG) {
|
if (OBJL == SOUNDG) {
|
||||||
QVector<Sounding> s(soundingGeometry(r));
|
QVector<Sounding> s(soundingGeometry(r, vi, vc, COMF, SOMF));
|
||||||
for (int i = 0; i < s.size(); i++) {
|
for (int i = 0; i < s.size(); i++) {
|
||||||
point = pointObject(s.at(i));
|
point = pointObject(s.at(i));
|
||||||
pointBounds(point->pos(), min, max);
|
pointBounds(point->pos(), min, max);
|
||||||
_points.Insert(min, max, point);
|
_points.Insert(min, max, point);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((point = pointObject(r, OBJL))) {
|
if ((point = pointObject(r, vi, vc, COMF, OBJL))) {
|
||||||
pointBounds(point->pos(), min, max);
|
pointBounds(point->pos(), min, max);
|
||||||
_points.Insert(min, max, point);
|
_points.Insert(min, max, point);
|
||||||
} else
|
} else
|
||||||
@ -619,14 +667,14 @@ void MapData::load()
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PRIM_L:
|
case PRIM_L:
|
||||||
if ((line = lineObject(r, OBJL))) {
|
if ((line = lineObject(r, vc, ve, COMF, OBJL))) {
|
||||||
rectcBounds(line->bounds(), min, max);
|
rectcBounds(line->bounds(), min, max);
|
||||||
_lines.Insert(min, max, line);
|
_lines.Insert(min, max, line);
|
||||||
} else
|
} else
|
||||||
warning(f, PRIM);
|
warning(f, PRIM);
|
||||||
break;
|
break;
|
||||||
case PRIM_A:
|
case PRIM_A:
|
||||||
if ((poly = polyObject(r, OBJL))) {
|
if ((poly = polyObject(r, vc, ve, COMF, OBJL))) {
|
||||||
rectcBounds(poly->bounds(), min, max);
|
rectcBounds(poly->bounds(), min, max);
|
||||||
_areas.Insert(min, max, poly);
|
_areas.Insert(min, max, poly);
|
||||||
} else
|
} else
|
||||||
|
@ -32,7 +32,15 @@ public:
|
|||||||
Line(uint type, const QVector<Coordinates> &path, const QString &label)
|
Line(uint type, const QVector<Coordinates> &path, const QString &label)
|
||||||
: _type(type), _path(path), _label(label) {}
|
: _type(type), _path(path), _label(label) {}
|
||||||
|
|
||||||
RectC bounds() const;
|
RectC bounds() const
|
||||||
|
{
|
||||||
|
RectC b;
|
||||||
|
|
||||||
|
for (int i = 0; i < _path.size(); i++)
|
||||||
|
b = b.united(_path.at(i));
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
const QVector<Coordinates> &path() const {return _path;}
|
const QVector<Coordinates> &path() const {return _path;}
|
||||||
uint type() const {return _type;}
|
uint type() const {return _type;}
|
||||||
const QString &label() const {return _label;}
|
const QString &label() const {return _label;}
|
||||||
@ -70,7 +78,7 @@ public:
|
|||||||
~MapData();
|
~MapData();
|
||||||
|
|
||||||
const QString &name() const {return _name;}
|
const QString &name() const {return _name;}
|
||||||
RectC bounds() const;
|
RectC bounds() const {return _bounds;}
|
||||||
|
|
||||||
void polygons(const RectC &rect, QList<Poly*> *polygons);
|
void polygons(const RectC &rect, QList<Poly*> *polygons);
|
||||||
void lines(const RectC &rect, QList<Line*> *lines);
|
void lines(const RectC &rect, QList<Line*> *lines);
|
||||||
@ -79,7 +87,7 @@ public:
|
|||||||
void load();
|
void load();
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
bool isValid() const {return _valid;}
|
bool isValid() const {return _bounds.isValid();}
|
||||||
QString errorString() const {return _errorString;}
|
QString errorString() const {return _errorString;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -121,7 +129,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
Attr() : _subtype(0) {}
|
Attr() : _subtype(0) {}
|
||||||
Attr(uint subtype, const QString &label = QString())
|
Attr(uint subtype, const QString &label = QString())
|
||||||
: _subtype(subtype), _label(label) {}
|
: _subtype(subtype), _label(label) {}
|
||||||
|
|
||||||
unsigned subtype() const {return _subtype;}
|
unsigned subtype() const {return _subtype;}
|
||||||
const QString &label() const {return _label;}
|
const QString &label() const {return _label;}
|
||||||
@ -145,36 +153,42 @@ private:
|
|||||||
typedef RTree<Line*, double, 2> LineTree;
|
typedef RTree<Line*, double, 2> LineTree;
|
||||||
typedef RTree<Point*, double, 2> PointTree;
|
typedef RTree<Point*, double, 2> PointTree;
|
||||||
|
|
||||||
bool processRecord(const ISO8211::Record &record);
|
bool fetchBoundsAndName();
|
||||||
Attr pointAttr(const ISO8211::Record &r, uint OBJL);
|
|
||||||
Attr lineAttr(const ISO8211::Record &r, uint OBJL);
|
|
||||||
Attr polyAttr(const ISO8211::Record &r, uint OBJL);
|
|
||||||
QVector<Sounding> soundingGeometry(const ISO8211::Record &r);
|
|
||||||
Coordinates pointGeometry(const ISO8211::Record &r);
|
|
||||||
QVector<Coordinates> lineGeometry(const ISO8211::Record &r);
|
|
||||||
Polygon polyGeometry(const ISO8211::Record &r);
|
|
||||||
Point *pointObject(const Sounding &s);
|
|
||||||
Point *pointObject(const ISO8211::Record &r, uint OBJL);
|
|
||||||
Line *lineObject(const ISO8211::Record &r, uint OBJL);
|
|
||||||
Poly *polyObject(const ISO8211::Record &r, uint OBJL);
|
|
||||||
Coordinates coordinates(int x, int y) const;
|
|
||||||
Coordinates point(const ISO8211::Record &r);
|
|
||||||
QVector<Sounding> soundings(const ISO8211::Record &r);
|
|
||||||
|
|
||||||
|
static QVector<Sounding> soundings(const ISO8211::Record &r, uint COMF,
|
||||||
|
uint SOMF);
|
||||||
|
static QVector<Sounding> soundingGeometry(const ISO8211::Record &r,
|
||||||
|
const RecordMap &vi, const RecordMap &vc, uint COMF, uint SOMF);
|
||||||
|
static Coordinates pointGeometry(const ISO8211::Record &r,
|
||||||
|
const RecordMap &vi, const RecordMap &vc, uint COMF);
|
||||||
|
static QVector<Coordinates> lineGeometry(const ISO8211::Record &r,
|
||||||
|
const RecordMap &vc, const RecordMap &ve, uint COMF);
|
||||||
|
static Polygon polyGeometry(const ISO8211::Record &r, const RecordMap &vc,
|
||||||
|
const RecordMap &ve, uint COMF);
|
||||||
|
static Attr pointAttr(const ISO8211::Record &r, uint OBJL);
|
||||||
|
static Attr lineAttr(const ISO8211::Record &r, uint OBJL);
|
||||||
|
static Attr polyAttr(const ISO8211::Record &r, uint OBJL);
|
||||||
|
static Point *pointObject(const Sounding &s);
|
||||||
|
static Point *pointObject(const ISO8211::Record &r, const RecordMap &vi,
|
||||||
|
const RecordMap &vc, uint COMF, uint OBJL);
|
||||||
|
static Line *lineObject(const ISO8211::Record &r, const RecordMap &vc,
|
||||||
|
const RecordMap &ve, uint COMF, uint OBJL);
|
||||||
|
static Poly *polyObject(const ISO8211::Record &r, const RecordMap &vc,
|
||||||
|
const RecordMap &ve, uint COMF,uint OBJL);
|
||||||
static bool bounds(const ISO8211::Record &record, Rect &rect);
|
static bool bounds(const ISO8211::Record &record, Rect &rect);
|
||||||
static Rect bounds(const RecordMap &map);
|
static bool bounds(const QVector<ISO8211::Record> &gv, Rect &b);
|
||||||
|
static bool processRecord(const ISO8211::Record &record,
|
||||||
|
QVector<ISO8211::Record> &fe, RecordMap &vi, RecordMap &vc, RecordMap &ve,
|
||||||
|
RecordMap &vf, uint &COMF, uint &SOMF);
|
||||||
|
static bool processRecord(const ISO8211::Record &record,
|
||||||
|
QVector<ISO8211::Record> &rv, uint &COMF, QString &name);
|
||||||
|
|
||||||
|
QString _fileName;
|
||||||
QString _name;
|
QString _name;
|
||||||
RecordMap _vi, _vc, _ve, _vf;
|
RectC _bounds;
|
||||||
QVector<ISO8211::Record> _fe;
|
|
||||||
uint _COMF, _SOMF;
|
|
||||||
ISO8211 _ddf;
|
|
||||||
|
|
||||||
PolygonTree _areas;
|
PolygonTree _areas;
|
||||||
LineTree _lines;
|
LineTree _lines;
|
||||||
PointTree _points;
|
PointTree _points;
|
||||||
|
|
||||||
bool _valid;
|
|
||||||
QString _errorString;
|
QString _errorString;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user