|
@@ -6,21 +6,21 @@
|
6
|
6
|
#include <QJsonDocument>
|
7
|
7
|
|
8
|
8
|
void Country::limits(){
|
9
|
|
- QMap<QString,City*>::iterator it = Cities.begin();
|
|
9
|
+ QMap<QString,QPolygonF*>::iterator it = Cities.begin();
|
10
|
10
|
|
11
|
|
- minX = maxX = Cities.begin().value()->geometry->at(0).x();
|
12
|
|
- minY = maxY = Cities.begin().value()->geometry->at(0).y();
|
|
11
|
+ minX = maxX = Cities.begin().value()->at(0).x();
|
|
12
|
+ minY = maxY = Cities.begin().value()->at(0).y();
|
13
|
13
|
|
14
|
14
|
for (it = Cities.begin() + 1; it != Cities.end(); ++it) {
|
15
|
15
|
|
16
|
|
- City *c = it.value();
|
|
16
|
+ QPolygonF *c = it.value();
|
17
|
17
|
|
18
|
|
- for (int i = 0; i < c->getSize(); i++) {
|
19
|
|
- if (c->geometry->at(i).x() != 0.0) {
|
20
|
|
- if (c->geometry->at(i).x() > maxX ) maxX = c->geometry->at(i).x();
|
21
|
|
- if (c->geometry->at(i).y() > maxY ) maxY = c->geometry->at(i).y();
|
22
|
|
- if (c->geometry->at(i).x() < minX ) minX = c->geometry->at(i).x();
|
23
|
|
- if (c->geometry->at(i).y() < minY ) minY = c->geometry->at(i).y();
|
|
18
|
+ for (int i = 0; i < c->size(); i++) {
|
|
19
|
+ if (c->at(i).x() != 0.0) {
|
|
20
|
+ if (c->at(i).x() > maxX ) maxX = c->at(i).x();
|
|
21
|
+ if (c->at(i).y() > maxY ) maxY = c->at(i).y();
|
|
22
|
+ if (c->at(i).x() < minX ) minX = c->at(i).x();
|
|
23
|
+ if (c->at(i).y() < minY ) minY = c->at(i).y();
|
24
|
24
|
}
|
25
|
25
|
}
|
26
|
26
|
}
|
|
@@ -33,22 +33,25 @@ bool Country::readInfoFromJSON(const QString &fileName) {
|
33
|
33
|
QFile loadFile(fileName);
|
34
|
34
|
|
35
|
35
|
if (!loadFile.open(QIODevice::ReadOnly)) {
|
36
|
|
- qWarning("Couldn't open save file.");
|
|
36
|
+ qWarning("Couldn't open read file.");
|
37
|
37
|
return false;
|
38
|
38
|
}
|
39
|
39
|
|
|
40
|
+ qDebug() << "JSON ok...";
|
|
41
|
+
|
40
|
42
|
QByteArray saveData = loadFile.readAll();
|
41
|
43
|
QJsonDocument loadDoc(QJsonDocument::fromJson(saveData));
|
42
|
|
- QJsonArray topLevelArray = loadDoc.array();
|
43
|
44
|
|
|
45
|
+ QJsonArray featureLevelArray = loadDoc.object()["features"].toArray();
|
44
|
46
|
int ctr = 1;
|
45
|
|
- foreach(QJsonValue obj, topLevelArray) {
|
46
|
|
- QVector<QPointF> *points = new QVector<QPointF>;
|
|
47
|
+ foreach(QJsonValue obj, featureLevelArray) {
|
|
48
|
+ QPolygonF *poly = new QPolygonF;
|
47
|
49
|
QJsonArray geometryArray = obj.toObject()["geometry"].toObject()["coordinates"].toArray();
|
48
|
50
|
QString polyType = obj.toObject()["geometry"].toObject()["type"].toString();
|
|
51
|
+ qDebug() << polyType;
|
49
|
52
|
if (polyType == "Polygon") {
|
50
|
53
|
for (int i = 0; i < geometryArray[0].toArray().size(); i++) {
|
51
|
|
- points->push_back(QPointF(
|
|
54
|
+ poly->push_back(QPointF(
|
52
|
55
|
geometryArray[0].toArray()[i].toArray()[0].toDouble(),
|
53
|
56
|
geometryArray[0].toArray()[i].toArray()[1].toDouble()));
|
54
|
57
|
}
|
|
@@ -58,21 +61,21 @@ bool Country::readInfoFromJSON(const QString &fileName) {
|
58
|
61
|
for (int i = 0; i <geometryArray.size() ; i++) {
|
59
|
62
|
// for every point in the city's polygon
|
60
|
63
|
for (int j = 0; j < geometryArray[i].toArray()[0].toArray().size(); j++) {
|
61
|
|
- points->push_back(QPointF(
|
|
64
|
+ poly->push_back(QPointF(
|
62
|
65
|
geometryArray[i].toArray()[0].toArray()[j].toArray()[0].toDouble(),
|
63
|
66
|
geometryArray[i].toArray()[0].toArray()[j].toArray()[1].toDouble()));
|
64
|
67
|
|
65
|
68
|
}
|
66
|
69
|
// I will push a 0,0 between each polygon of a multipolygon to distinguish
|
67
|
|
- points->push_back(QPointF(0,0));
|
|
70
|
+ poly->push_back(QPointF(0,0));
|
68
|
71
|
}
|
69
|
72
|
}
|
70
|
73
|
|
71
|
|
- QString cityName = obj.toObject()["properties"].toObject()["city"].toString();
|
|
74
|
+ QString cityName = obj.toObject()["properties"].toObject()["name"].toString();
|
72
|
75
|
|
73
|
76
|
qDebug() << "Storing: " << cityName;
|
74
|
|
- Cities[cityName] = new City;
|
75
|
|
- Cities[cityName]->geometry = points;
|
|
77
|
+ Cities[cityName] = poly; //new City;
|
|
78
|
+ //Cities[cityName]->geometry = poly;
|
76
|
79
|
|
77
|
80
|
ctr++;
|
78
|
81
|
}
|