mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-27 03:29:16 +02:00
Added support for Mapsforge maps
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include "polygon.h"
|
||||
#include "common/polygon.h"
|
||||
|
||||
class Area
|
||||
{
|
||||
@ -11,15 +11,10 @@ public:
|
||||
Area() {}
|
||||
Area(const RectC &rect)
|
||||
{
|
||||
QVector<Coordinates> v(4);
|
||||
v[0] = Coordinates(rect.left(), rect.top());
|
||||
v[1] = Coordinates(rect.right(), rect.top());
|
||||
v[2] = Coordinates(rect.right(), rect.bottom());
|
||||
v[3] = Coordinates(rect.left(), rect.bottom());
|
||||
|
||||
Polygon polygon(rect);
|
||||
_polygons.reserve(1);
|
||||
_polygons.append(v);
|
||||
_boundingRect = RectC(v.at(0), v.at(2));
|
||||
_polygons.append(polygon);
|
||||
_boundingRect = polygon.boundingRect();
|
||||
}
|
||||
Area(const Polygon &polygon)
|
||||
{
|
||||
@ -38,8 +33,9 @@ public:
|
||||
if (_polygons.isEmpty())
|
||||
return false;
|
||||
for (int i = 0; i < _polygons.size(); i++)
|
||||
if (!_polygons.at(i).isValid())
|
||||
if (_polygons.at(i).isEmpty() || _polygons.at(i).first().size() < 3)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -143,8 +143,7 @@ bool GeoJSONParser::polygon(const QJsonArray &coordinates, ::Polygon &pg)
|
||||
}
|
||||
|
||||
const QJsonArray lr(coordinates.at(i).toArray());
|
||||
pg.append(QVector<Coordinates>());
|
||||
QVector<Coordinates> &data = pg.last();
|
||||
QVector<Coordinates> data;
|
||||
|
||||
for (int j = 0; j < lr.size(); j++) {
|
||||
QJsonArray point(lr.at(j).toArray());
|
||||
@ -156,6 +155,8 @@ bool GeoJSONParser::polygon(const QJsonArray &coordinates, ::Polygon &pg)
|
||||
data.append(Coordinates(point.at(0).toDouble(),
|
||||
point.at(1).toDouble()));
|
||||
}
|
||||
|
||||
pg.append(data);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -266,20 +266,22 @@ void KMLParser::polygon(Area &area)
|
||||
Polygon polygon;
|
||||
|
||||
while (_reader.readNextStartElement()) {
|
||||
QVector<Coordinates> path;
|
||||
|
||||
if (_reader.name() == QLatin1String("outerBoundaryIs")) {
|
||||
if (!polygon.isEmpty()) {
|
||||
_reader.raiseError("Multiple polygon outerBoundaryIss");
|
||||
return;
|
||||
}
|
||||
polygon.append(QVector<Coordinates>());
|
||||
boundary(polygon.last());
|
||||
boundary(path);
|
||||
polygon.append(path);
|
||||
} else if (_reader.name() == QLatin1String("innerBoundaryIs")) {
|
||||
if (polygon.isEmpty()) {
|
||||
_reader.raiseError("Missing polygon outerBoundaryIs");
|
||||
return;
|
||||
}
|
||||
polygon.append(QVector<Coordinates>());
|
||||
boundary(polygon.last());
|
||||
boundary(path);
|
||||
polygon.append(path);
|
||||
} else
|
||||
_reader.skipCurrentElement();
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
#ifndef POLYGON_H
|
||||
#define POLYGON_H
|
||||
|
||||
#include <QList>
|
||||
#include <QVector>
|
||||
#include "common/coordinates.h"
|
||||
#include "common/rectc.h"
|
||||
|
||||
class Polygon : public QList<QVector<Coordinates> >
|
||||
{
|
||||
public:
|
||||
Polygon() {}
|
||||
Polygon(const QVector<Coordinates> &c)
|
||||
{
|
||||
reserve(1);
|
||||
append(c);
|
||||
}
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return !isEmpty() && first().size() >= 3;
|
||||
}
|
||||
|
||||
RectC boundingRect() const
|
||||
{
|
||||
RectC rect;
|
||||
|
||||
if (isEmpty() || first().size() < 3)
|
||||
return rect;
|
||||
|
||||
for (int i = 0; i < first().size(); i++)
|
||||
rect = rect.united(first().at(i));
|
||||
|
||||
return rect;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // POLYGON_H
|
Reference in New Issue
Block a user