mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-18 19:52:09 +01:00
Fixed layer bounding box & scale denominator range joining
This commit is contained in:
parent
e845e216bd
commit
b8815ca9f5
@ -8,13 +8,13 @@ void RangeF::resize(qreal size)
|
||||
_max += adj;
|
||||
}
|
||||
|
||||
RangeF RangeF::operator|(const RangeF &r) const
|
||||
RangeF RangeF::operator&(const RangeF &r) const
|
||||
{
|
||||
if (isNull())
|
||||
return r;
|
||||
if (r.isNull())
|
||||
return *this;
|
||||
return RangeF(qMax(this->_min, r._min), qMin(this->_max, r._max));
|
||||
if (isNull() || r.isNull())
|
||||
return RangeF();
|
||||
|
||||
RangeF tmp(qMax(this->_min, r._min), qMin(this->_max, r._max));
|
||||
return tmp.isValid() ? tmp : RangeF();
|
||||
}
|
||||
|
||||
#ifndef QT_NO_DEBUG
|
||||
|
@ -29,8 +29,8 @@ public:
|
||||
RangeF() {_min = 0; _max = 0;}
|
||||
RangeF(qreal min, qreal max) {_min = min, _max = max;}
|
||||
|
||||
RangeF operator|(const RangeF &r) const;
|
||||
RangeF &operator|=(const RangeF &r) {*this = *this | r; return *this;}
|
||||
RangeF operator&(const RangeF &r) const;
|
||||
RangeF &operator&=(const RangeF &r) {*this = *this & r; return *this;}
|
||||
|
||||
qreal min() const {return _min;}
|
||||
qreal max() const {return _max;}
|
||||
|
@ -44,6 +44,54 @@ RectC RectC::operator|(const RectC &r) const
|
||||
return tmp;
|
||||
}
|
||||
|
||||
RectC RectC::operator&(const RectC &r) const
|
||||
{
|
||||
if (isNull() || r.isNull())
|
||||
return RectC();
|
||||
|
||||
qreal l1 = _tl.lon();
|
||||
qreal r1 = _tl.lon();
|
||||
if (_br.lon() - _tl.lon() < 0)
|
||||
l1 = _br.lon();
|
||||
else
|
||||
r1 = _br.lon();
|
||||
|
||||
qreal l2 = r._tl.lon();
|
||||
qreal r2 = r._tl.lon();
|
||||
if (r._br.lon() - r._tl.lon() < 0)
|
||||
l2 = r._br.lon();
|
||||
else
|
||||
r2 = r._br.lon();
|
||||
|
||||
if (l1 > r2 || l2 > r1)
|
||||
return RectC();
|
||||
|
||||
qreal t1 = _tl.lat();
|
||||
qreal b1 = _tl.lat();
|
||||
if (_br.lat() - _tl.lat() < 0)
|
||||
t1 = _br.lat();
|
||||
else
|
||||
b1 = _br.lat();
|
||||
|
||||
qreal t2 = r._tl.lat();
|
||||
qreal b2 = r._tl.lat();
|
||||
if (r._br.lat() - r._tl.lat() < 0)
|
||||
t2 = r._br.lat();
|
||||
else
|
||||
b2 = r._br.lat();
|
||||
|
||||
if (t1 > b2 || t2 > b1)
|
||||
return RectC();
|
||||
|
||||
RectC tmp;
|
||||
tmp._tl.setLon(qMax(l1, l2));
|
||||
tmp._br.setLon(qMin(r1, r2));
|
||||
tmp._tl.setLat(qMax(t1, t2));
|
||||
tmp._br.setLat(qMin(b1, b2));
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void RectC::unite(const Coordinates &c)
|
||||
{
|
||||
if (isNull()) {
|
||||
|
@ -30,6 +30,8 @@ public:
|
||||
|
||||
RectC operator|(const RectC &r) const;
|
||||
RectC &operator|=(const RectC &r) {*this = *this | r; return *this;}
|
||||
RectC operator&(const RectC &r) const;
|
||||
RectC &operator&=(const RectC &r) {*this = *this & r; return *this;}
|
||||
|
||||
void unite(const Coordinates &c);
|
||||
|
||||
|
@ -96,11 +96,15 @@ void WMS::layer(QXmlStreamReader &reader, CTX &ctx,
|
||||
CRSs.append(reader.readElementText());
|
||||
else if (reader.name() == "Style")
|
||||
styles.append(style(reader));
|
||||
else if (reader.name() == "MinScaleDenominator")
|
||||
scaleDenominator.setMin(reader.readElementText().toDouble());
|
||||
else if (reader.name() == "MaxScaleDenominator")
|
||||
scaleDenominator.setMax(reader.readElementText().toDouble());
|
||||
else if (reader.name() == "LatLonBoundingBox") {
|
||||
else if (reader.name() == "MinScaleDenominator") {
|
||||
double sd = reader.readElementText().toDouble();
|
||||
if (!std::isnan(sd))
|
||||
scaleDenominator.setMin(sd);
|
||||
} else if (reader.name() == "MaxScaleDenominator") {
|
||||
double sd = reader.readElementText().toDouble();
|
||||
if (!std::isnan(sd))
|
||||
scaleDenominator.setMax(sd);
|
||||
} else if (reader.name() == "LatLonBoundingBox") {
|
||||
QXmlStreamAttributes attr = reader.attributes();
|
||||
boundingBox = RectC(Coordinates(
|
||||
attr.value("minx").toString().toDouble(),
|
||||
@ -208,13 +212,14 @@ bool WMS::parseCapabilities(const QString &path, const Setup &setup)
|
||||
+ layer.name;
|
||||
return false;
|
||||
}
|
||||
if (!layer.scaleDenominator.isValid()) {
|
||||
_errorString = "Invalid scale denominator range for layer"
|
||||
if (!layer.scaleDenominator.isValid()
|
||||
|| layer.scaleDenominator.isNull()) {
|
||||
_errorString = "Invalid scale denominator range for layer "
|
||||
+ layer.name;
|
||||
return false;
|
||||
}
|
||||
if (!layer.boundingBox.isValid()) {
|
||||
_errorString = "Invalid/missing bounding box for layer"
|
||||
_errorString = "Invalid/missing bounding box for layer "
|
||||
+ layer.name;
|
||||
return false;
|
||||
}
|
||||
@ -226,10 +231,21 @@ bool WMS::parseCapabilities(const QString &path, const Setup &setup)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ctx.layers.size(); i++)
|
||||
_boundingBox |= ctx.layers.at(i).boundingBox;
|
||||
for (int i = 0; i < ctx.layers.size(); i++)
|
||||
_scaleDenominator |= ctx.layers.first().scaleDenominator;
|
||||
_boundingBox = ctx.layers.first().boundingBox;
|
||||
for (int i = 1; i < ctx.layers.size(); i++)
|
||||
_boundingBox &= ctx.layers.at(i).boundingBox;
|
||||
if (_boundingBox.isNull()) {
|
||||
_errorString = "Empty layers bounding box join";
|
||||
return false;
|
||||
}
|
||||
|
||||
_scaleDenominator = ctx.layers.first().scaleDenominator;
|
||||
for (int i = 1; i < ctx.layers.size(); i++)
|
||||
_scaleDenominator &= ctx.layers.at(i).scaleDenominator;
|
||||
if (_scaleDenominator.isNull()) {
|
||||
_errorString = "Empty layers scale denominator range join";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user