Browse Source

Another geo.json that includes the real latitudes and longitudes. Updated the point of interest files with the centroids computed from the geo.json

Rafael Arce Nazario 9 years ago
parent
commit
09100f7a6c
8 changed files with 154 additions and 58 deletions
  1. 7
    5
      country.cpp
  2. 0
    2
      data/pr-all-all.geo.json
  3. 6
    0
      data/pr.geo.json
  4. 78
    37
      data/pr.txt
  5. 11
    10
      data/pr10.txt
  6. 48
    1
      map.cpp
  7. 3
    2
      prMap.pro
  8. 1
    1
      prmap.qrc

+ 7
- 5
country.cpp View File

@@ -5,6 +5,8 @@
5 5
 #include <QJsonObject>
6 6
 #include <QJsonDocument>
7 7
 
8
+
9
+
8 10
 void Country::limits(){
9 11
     QMap<QString,QPolygonF*>::iterator it = Cities.begin();
10 12
 
@@ -42,7 +44,7 @@ bool Country::readInfoFromJSON(const QString &fileName) {
42 44
     QByteArray saveData = loadFile.readAll();
43 45
     QJsonDocument loadDoc(QJsonDocument::fromJson(saveData));
44 46
 
45
-    QJsonArray featureLevelArray = loadDoc.object()["features"].toArray();
47
+    QJsonArray featureLevelArray = loadDoc.object()["pueblos"].toObject()["features"].toArray();
46 48
     int ctr = 1;
47 49
     foreach(QJsonValue obj, featureLevelArray) {
48 50
         QPolygonF *poly = new QPolygonF;
@@ -54,7 +56,9 @@ bool Country::readInfoFromJSON(const QString &fileName) {
54 56
                 poly->push_back(QPointF(
55 57
                                 geometryArray[0].toArray()[i].toArray()[0].toDouble(),
56 58
                                 geometryArray[0].toArray()[i].toArray()[1].toDouble()));
59
+            qDebug() << geometryArray[0].toArray()[i].toArray()[0].toDouble();
57 60
             }
61
+
58 62
         }
59 63
         else {
60 64
             // for every city
@@ -71,12 +75,10 @@ bool Country::readInfoFromJSON(const QString &fileName) {
71 75
             }
72 76
         }
73 77
 
74
-        QString cityName = obj.toObject()["properties"].toObject()["name"].toString();
78
+        QString cityName = obj.toObject()["properties"].toObject()["NAME"].toString();
75 79
 
76 80
         qDebug() << "Storing: " << cityName;
77
-        Cities[cityName] = poly; //new City;
78
-        //Cities[cityName]->geometry = poly;
79
-
81
+        Cities[cityName] = poly;
80 82
         ctr++;
81 83
     }
82 84
     return true;

+ 0
- 2
data/pr-all-all.geo.json
File diff suppressed because it is too large
View File


+ 6
- 0
data/pr.geo.json
File diff suppressed because it is too large
View File


+ 78
- 37
data/pr.txt View File

@@ -1,37 +1,78 @@
1
-San_Juan 18.4516666667 -66.0688888889
2
-Ponce 18.0 -66.6167
3
-Vieques 18.1269 -65.4239
4
-Bayamon 18.3833 -66.15
5
-Mayaguez 18.2011111111 -67.1397222222
6
-Culebra 18.3169 -65.29
7
-Carolina 18.4112152674 -65.9710121155
8
-Caguas 18.2342 -66.0486
9
-Aguadilla 18.43 -67.1544
10
-Arecibo 18.4705555556 -66.7208333333
11
-Dorado 18.4589 -66.2678
12
-Fajardo 18.3258 -65.6525
13
-Rincon 18.3402777778 -67.2516666667
14
-Guaynabo 18.1144444444 -66.1680555556
15
-Humacao 18.1497 -65.8275
16
-Cidra 18.1758333333 -66.1613888889
17
-Guayama 17.9936 -66.1308
18
-Santurce 18.4408333333 -66.0472222222
19
-Cayey 18.1144 -66.1681
20
-Utuado 18.2656 -66.7006
21
-Rio_Grande 18.3803 -65.8314
22
-Barceloneta 18.4506 -66.5386
23
-Yauco 18.0369444444 -66.8502777778
24
-Jayuya 18.2186 -66.5917
25
-Vega_Baja 18.4461111111 -66.3875
26
-Trujillo_Alto 18.3628 -66.0175
27
-Juana_Diaz 18.0525 -66.5067
28
-Yabucoa 18.0506 -65.8794
29
-Toa_Baja 18.4439 -66.2597
30
-Rio_Piedras 18.3997222222 -66.05
31
-Gurabo 18.2544 -65.9731
32
-Canovanas 18.3792 -65.9014
33
-Catano 18.4414 -66.1183
34
-Arroyo 17.9658 -66.0614
35
-Anasco 18.2818442291 -67.1422576904
36
-Toa_Alta 18.3883 -66.2483
37
-Levittown 18.45 -66.1817
1
+Adjuntas 18.1811 -66.7559
2
+Aguada 18.3604 -67.1764
3
+Aguadilla 18.4611 -67.1194
4
+AguasBuenas 18.2495 -66.1256
5
+Aibonito 18.1321 -66.2635
6
+Arecibo 18.4078 -66.6824
7
+Arroyo 18.0016 -66.0593
8
+Anasco 18.2875 -67.1262
9
+Barceloneta 18.4447 -66.56
10
+Barranquitas 18.2035 -66.3161
11
+Bayamon 18.3504 -66.1749
12
+CaboRojo 18.0403 -67.1422
13
+Caguas 18.212 -66.051
14
+Camuy 18.4199 -66.8582
15
+Canovanas 18.3287 -65.8799
16
+Carolina 18.3754 -65.9549
17
+Catano 18.4393 -66.1284
18
+Cayey 18.1038 -66.1505
19
+Ceiba 18.2532 -65.673
20
+Ciales 18.2902 -66.5248
21
+Cidra 18.171 -66.152
22
+Coamo 18.0955 -66.3613
23
+Comerio 18.2254 -66.2185
24
+Corozal 18.3081 -66.343
25
+Culebra 18.3199 -65.2912
26
+Dorado 18.4332 -66.2758
27
+Fajardo 18.3167 -65.6667
28
+Florida 18.3734 -66.5591
29
+Guayama 18.0087 -66.135
30
+Guayanilla 18.0446 -66.7924
31
+Guaynabo 18.3334 -66.0713
32
+Gurabo 18.2668 -65.977
33
+Guanica 17.9831 -66.921
34
+Hatillo 18.4094 -66.7982
35
+Hormigueros 18.1339 -67.1188
36
+Humacao 18.1445 -65.8113
37
+Isabela 18.4501 -67.0074
38
+Jayuya 18.21 -66.5878
39
+JuanaDiaz 18.0568 -66.5073
40
+Juncos 18.2278 -65.9221
41
+Lajas 18.0119 -67.0431
42
+Lares 18.2705 -66.8734
43
+LasMarias 18.2373 -66.9814
44
+LasPiedras 18.1883 -65.8735
45
+Loiza 18.425 -65.9025
46
+Luquillo 18.3418 -65.7361
47
+Manati 18.4164 -66.4827
48
+Maricao 18.1706 -66.9397
49
+Maunabo 18.0183 -65.9237
50
+Mayaguez 18.2083 -67.1081
51
+Moca 18.3758 -67.0883
52
+Morovis 18.3169 -66.4187
53
+Naguabo 18.2305 -65.7544
54
+Naranjito 18.2855 -66.2456
55
+Orocovis 18.2137 -66.4315
56
+Patillas 18.0328 -66.0134
57
+Penuelas 18.0614 -66.7253
58
+Ponce 18.059 -66.6084
59
+Quebradillas 18.4365 -66.9075
60
+Rincon 18.3367 -67.2341
61
+RioGrande 18.3464 -65.8119
62
+SabanaGrande 18.0837 -66.9399
63
+Salinas 18.0121 -66.2615
64
+SanGerman 18.1115 -67.0426
65
+SanJuan 18.3891 -66.0539
66
+SanLorenzo 18.1472 -65.9789
67
+SanSebastian 18.3292 -66.9719
68
+SantaIsabel 17.9963 -66.3879
69
+ToaAlta 18.3631 -66.2466
70
+ToaBaja 18.4274 -66.2015
71
+TrujilloAlto 18.3381 -66.0084
72
+Utuado 18.2717 -66.7067
73
+VegaAlta 18.4113 -66.3454
74
+VegaBaja 18.4288 -66.3906
75
+Vieques 18.1226 -65.4372
76
+Villalba 18.1296 -66.473
77
+Yabucoa 18.0717 -65.9018
78
+Yauco 18.079 -66.8592

+ 11
- 10
data/pr10.txt View File

@@ -1,10 +1,11 @@
1
-Arroyo 17.9658 -66.0614
2
-Bayamon 18.3833 -66.15
3
-Caguas 18.2342 -66.0486
4
-Dorado 18.4589 -66.2678
5
-Fajardo 18.3258 -65.6525
6
-Guayama 17.9936 -66.1308
7
-Humacao 18.1497 -65.8275
8
-Jayuya 18.2186 -66.5917
9
-Mayaguez 18.2011111111 -67.1397222222
10
-Ponce 18.0 -66.6167
1
+Arroyo 18.0016 -66.0593
2
+Bayamon 18.3504 -66.1749
3
+Caguas 18.212 -66.051
4
+Dorado 18.4332 -66.2758
5
+Fajardo 18.3167 -65.6667
6
+Guayama 18.0087 -66.135
7
+Humacao 18.1445 -65.8113
8
+Jayuya 18.21 -66.5878
9
+Mayaguez 18.2083 -67.1081
10
+Ponce 18.059 -66.6084
11
+

+ 48
- 1
map.cpp View File

@@ -3,6 +3,31 @@
3 3
 #include <QDesktopWidget>
4 4
 #include <QPainter>
5 5
 #include <QPen>
6
+#include "gispoi.h"
7
+
8
+
9
+QPointF centroid(const QPolygonF &poly) {
10
+    float A = 0.0f;
11
+    float Cx = 0.0f;
12
+    float Cy = 0.0f;
13
+    QVector<float> VA;
14
+
15
+    //VA.resize(poly.size());
16
+    int size = poly.size();
17
+    int ip1;
18
+    float prodDif;
19
+    for (int i = 0; i < size; i++) {
20
+        ip1 = (i + 1)%size;
21
+        prodDif = poly.at(i).x() * poly.at(ip1).y() - poly.at(i).y() * poly.at(ip1).x();
22
+        A += prodDif;
23
+        Cx += ( poly.at(i).x() + poly.at(ip1).x()) * prodDif;
24
+        Cy += ( poly.at(i).y() + poly.at(ip1).y()) * prodDif;
25
+    }
26
+    A = A / 2.0;
27
+    Cx = Cx / (6.0 * A);
28
+    Cy = Cy / (6.0 * A);
29
+    return QPointF(Cx,Cy);
30
+}
6 31
 
7 32
 Map::Map(QWidget *parent) :
8 33
     QWidget(parent)
@@ -12,7 +37,7 @@ Map::Map(QWidget *parent) :
12 37
     // Create country object and read data from the json file
13 38
     qDebug() << "Reading the Json...";
14 39
     myCountry = new Country;
15
-    myCountry->readInfoFromJSON(":/data/pr-all-all.geo.json");
40
+    myCountry->readInfoFromJSON(":/data/pr.geo.json");
16 41
     qDebug() << "...done, read " << myCountry->Cities.size();
17 42
 
18 43
 
@@ -33,6 +58,7 @@ Map::Map(QWidget *parent) :
33 58
 
34 59
     if (diffX > diffY) resize(mainScreenSize.width() * 0.5 , 0.5 * mainScreenSize.width()*(diffY/diffX));
35 60
     else               resize(mainScreenSize.width() * 0.5,  0.5 * mainScreenSize.width()*(diffX/diffY));
61
+
36 62
 }
37 63
 
38 64
 
@@ -170,6 +196,27 @@ void Map::paintEvent(QPaintEvent *) {
170 196
     int cX, cY, pX, pY;
171 197
     cX = cY = pX = pY = -1;
172 198
 
199
+
200
+/*
201
+    myPen.setWidth(2);
202
+    myPen.setColor(QColor(0x100000));
203
+    myPen.setBrush(QBrush(Qt::black));
204
+    p->setBrush(Qt::SolidPattern);
205
+    p->setBrush(QBrush(0xff0000));
206
+
207
+
208
+    QMap<QString,QPolygonF*>::iterator itc = this->myCountry->Cities.begin();
209
+    for (; itc != this->myCountry->Cities.end(); itc++) {
210
+        QPointF cent = centroid(*(itc.value()));
211
+        cX = factorX * (cent.x() - myCountry->minX);
212
+        cY = height() - factorY*(cent.y() - myCountry->minY);
213
+
214
+        p->drawEllipse(static_cast<int>(cX) - circleRadius/2, static_cast<int>(cY)- circleRadius/2, circleRadius, circleRadius);
215
+        qDebug() << itc.key() << cent.y() << cent.x();
216
+
217
+    }
218
+*/
219
+
173 220
     if(gisLocations) {
174 221
         myPen.setWidth(2);
175 222
         myPen.setColor(QColor(0x100000));

+ 3
- 2
prMap.pro View File

@@ -14,10 +14,11 @@ TEMPLATE = app
14 14
 # CONFIG += c++11
15 15
 
16 16
 SOURCES += main.cpp\
17
+    gispoi.cpp\
17 18
         mainwindow.cpp \
18 19
     country.cpp \
19
-    map.cpp \
20
-    gispoi.cpp
20
+    map.cpp
21
+
21 22
 
22 23
 HEADERS  += mainwindow.h \
23 24
     country.h \

+ 1
- 1
prmap.qrc View File

@@ -1,5 +1,5 @@
1 1
 <RCC>
2 2
     <qresource prefix="/">
3
-        <file>data/pr-all-all.geo.json</file>
3
+        <file>data/pr.geo.json</file>
4 4
     </qresource>
5 5
 </RCC>