Bridges-C++ 3.5.0-dev2-1-ge3e57bf
Bridges(C++ API)
USMap.h
Go to the documentation of this file.
1#ifndef US_MAP_H
2
3#define US_MAP_H
4
5#include <math.h>
6#include <cmath>
7
8#include <algorithm>
9
10#include <string>
11#include <vector>
12#include <unordered_map>
13
14using std::string;
15using std::vector;
16using std::unordered_map;
17
18#include "DataStructure.h"
19#include "Map.h"
20#include "./data_src/USState.h"
21#include "./data_src/USCounty.h"
22#include <JSONutil.h>
23
24#include <rapidjson/document.h>
25#include <rapidjson/stringbuffer.h>
26#include <rapidjson/writer.h>
27
28namespace bridges {
29 namespace datastructure {
30
31 using namespace bridges::datastructure;
33
56 class USMap : public Map, public DataStructure {
57 private:
58 vector<string> state_names;
59 vector<USState> state_data;
60
61 bool all;
62
63 virtual const string getDataStructureRepresentation ()
64 const override {
66 return JSONencode("mapdummy") + COLON + JSONencode(true) + CLOSE_CURLY;
67 }
68 unordered_map<string, string> state_codes = {
69 {"Alabama", "AL"},
70 {"Alaska", "AK"},
71 {"Arizona", "AZ"},
72 {"Arkansas", "AR"},
73 {"California", "CA"},
74 {"Colorado", "CO"},
75 {"Connecticut", "CT"},
76 {"Delaware", "DE"},
77 {"District of Columbia", "DC"},
78 {"Florida", "FL"},
79 {"Georgia", "GA"},
80 {"Guam", "GU"},
81 {"Hawaii", "HI"},
82 {"Idaho", "ID"},
83 {"Illinois", "IL"},
84 {"Indiana", "IN"},
85 {"Iowa", "IA"},
86 {"Kansas", "KS"},
87 {"Kentucky", "KY"},
88 {"Louisiana", "LA"},
89 {"Maine", "ME"},
90 {"Maryland", "MD"},
91 {"Massachusetts", "MA"},
92 {"Michigan", "MI"},
93 {"Minnesota", "MN"},
94 {"Mississippi", "MS"},
95 {"Missouri", "MO"},
96 {"Montana", "MT"},
97 {"Nebraska", "NE"},
98 {"Nevada", "NV"},
99 {"New Hampshire", "NH"},
100 {"New Jersey", "NJ"},
101 {"New Mexico", "NM"},
102 {"New York", "NY"},
103 {"North Carolina", "NC"},
104 {"North Dakota", "ND"},
105 {"Ohio", "OH"},
106 {"Oklahoma", "OK"},
107 {"Oregon", "OR"},
108 {"Pennsylvania", "PA"},
109 {"Puerto Rico", "PR"},
110 {"Rhode Island", "RI"},
111 {"South Carolina", "SC"},
112 {"South Dakota", "SD"},
113 {"Tennessee", "TN"},
114 {"Texas", "TX"},
115 {"Utah", "UT"},
116 {"Vermont", "VT"},
117 {"Virginia", "VA"},
118 {"Virgin Islands", "VI"},
119 {"Washington", "WA"},
120 {"West Virginia", "WV"},
121 {"Wisconsin", "WI"},
122 {"Wyoming", "WY "}
123 };
124 public:
130 const string getProjection() const override {
131 return "albersusa";
132 }
138 const bool getOverlay() const override {
139 return true;
140 }
141
147 virtual const string getMapRepresentation () const override {
148 if (this->all)
149 return "[\"all\"]";
150
151 // generates a JSON of the states with county information
152 string map_str = OPEN_BOX;
154 for (auto& st : state_data) {
155 map_str += OPEN_CURLY +
156 QUOTE + "_state_name" + QUOTE + COLON +
157 JSONencode(st.getStateName()) + COMMA +
158 QUOTE + "_state_code" + QUOTE + COLON +
159 JSONencode(state_codes.at(st.getStateName())) + COMMA +
160 QUOTE + "_stroke_color" + QUOTE + COLON
161 + st.getStrokeColor().getCSSRepresentation() + COMMA +
162 QUOTE + "_stroke_width" + QUOTE + COLON +
163 JSONencode(st.getStrokeWidth()) + COMMA +
164 QUOTE + "_fill_color" + QUOTE + COLON +
165 st.getFillColor().getCSSRepresentation() + COMMA +
166 QUOTE + "_view_counties" + QUOTE + COLON +
167 JSONencode(st.getViewCountiesFlag()) + COMMA +
168 QUOTE + "_counties" + QUOTE + COLON;
169
170 // get all the counties
171 map_str += OPEN_BOX; // array of counties
172 for (auto& c : st.getCounties()) {
173 map_str += OPEN_CURLY +
174 QUOTE + "_geoid" + QUOTE + COLON +
175 JSONencode(c.second.getGeoId()) + COMMA +
176 QUOTE + "_fips_code" + QUOTE + COLON +
177 JSONencode(c.second.getFipsCode()) + COMMA +
178 QUOTE + "_county_name" + QUOTE + COLON +
179 JSONencode(c.second.getCountyName()) + COMMA +
180 QUOTE + "_state_name" + QUOTE + COLON +
181 JSONencode(c.second.getStateName()) + COMMA +
182 QUOTE + "_stroke_color" + QUOTE + COLON +
183 c.second.getStrokeColor().getCSSRepresentation() + COMMA +
184 QUOTE + "_stroke_width" + QUOTE + COLON +
185 JSONencode(c.second.getStrokeWidth()) + COMMA +
186 QUOTE + "_fill_color" + QUOTE + COLON +
187 c.second.getFillColor().getCSSRepresentation() + COMMA +
188 QUOTE + "_hide" + QUOTE + COLON +
189 JSONencode(c.second.getHideFlag()) +
191 }
192 // remove last comma
193 if (st.getCounties().size()) // case where counties are on
194 map_str = map_str.substr(0, map_str.size() - 1);
195 map_str += CLOSE_BOX + CLOSE_CURLY + COMMA;
196 }
197 // close the states array
198 map_str = map_str.substr(0, map_str.size() - 1) + CLOSE_BOX;
199 return map_str;
200 }
201 public:
203 all = true;
204 }
205 /*
206 * @brief Constructs a US Map object with map data
207 *
208 * @param st_data data containg state/county information
209 */
210 USMap(vector<USState> st_data) {
211 all = false;
212 state_data = st_data;
213 }
214
215 /*
216 * @brief This function returns the current state/county data
217 * in the US map object.
218 *
219 * @return list of state information
220 */
221 vector<USState>& getMapData() {
222 return state_data;
223 }
224
225 /*
226 * @brief This function sets the state/county data
227 * in the US map object.
228 *
229 * @param list of state information
230 */
231 void setStateData(vector<USState> st_data) {
232 all = false;
233 state_data = st_data;
234 }
235
236 /*
237 *
238 * @brief This function gets the data structure type for
239 * the US map,
240 *
241 */
242 virtual const string getDStype() const override {
243 return "us_map";
244 }
245 };
246 }
247}
248#endif
Definition: USState.h:25
This is the superclass of all data structure types in BRIDGES.
Definition: DataStructure.h:74
Abstract class for Map API.
Definition: Map.h:16
This class provides an API to building, displaying and manipulating US maps and counties in BRIDGES.
Definition: USMap.h:56
USMap()
Definition: USMap.h:202
virtual const string getMapRepresentation() const override
Generates the JSON representation of the US map.
Definition: USMap.h:147
vector< USState > & getMapData()
Definition: USMap.h:221
void setStateData(vector< USState > st_data)
Definition: USMap.h:231
virtual const string getDStype() const override
Definition: USMap.h:242
const string getProjection() const override
Gets the type of map projection. For US map we currently use albersusa.
Definition: USMap.h:130
USMap(vector< USState > st_data)
Definition: USMap.h:210
const bool getOverlay() const override
Gets the map overlay flag.
Definition: USMap.h:138
std::string JSONencode(const T &d)
Definition: JSONutil.h:38
Definition: Array.h:9
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
const string COLON
Definition: DataStructure.h:52
const string OPEN_BOX
Definition: DataStructure.h:55
const string COMMA
Definition: DataStructure.h:51
const string OPEN_CURLY
Definition: DataStructure.h:53
const string CLOSE_BOX
Definition: DataStructure.h:56
const string CLOSE_CURLY
Definition: DataStructure.h:54
const string QUOTE
Definition: DataStructure.h:50