This parses the guts of a 2D range.
| 280 | |
| 281 | // This parses the guts of a 2D range. |
| 282 | void BOX2D::parse(const std::string& s, std::string::size_type& pos) |
| 283 | { |
| 284 | |
| 285 | bool isJson(false); |
| 286 | bool isArray(false); |
| 287 | bool isObject(false); |
| 288 | std::string jsonParseMessage(""); |
| 289 | NL::json b; |
| 290 | try |
| 291 | { |
| 292 | b = NL::json::parse(s); |
| 293 | isJson = true; |
| 294 | isArray = b.is_array(); |
| 295 | isObject = b.is_object(); |
| 296 | } catch (std::exception& e) |
| 297 | { |
| 298 | jsonParseMessage = e.what(); |
| 299 | isJson = false; |
| 300 | } |
| 301 | |
| 302 | if (isArray && isJson) |
| 303 | { |
| 304 | if (b.size() != 4) |
| 305 | { |
| 306 | std::stringstream msg; |
| 307 | msg << "GeoJSON array size must be 4 for BOX2d. It was " << b.size(); |
| 308 | throw error(msg.str()); |
| 309 | } |
| 310 | minx = b[0].get<double>(); |
| 311 | miny = b[1].get<double>(); |
| 312 | maxx = b[2].get<double>(); |
| 313 | maxy = b[3].get<double>(); |
| 314 | |
| 315 | // parsed. we are done |
| 316 | pos = s.size(); |
| 317 | return; |
| 318 | } |
| 319 | |
| 320 | if (isObject && isJson) |
| 321 | { |
| 322 | if (!b.contains("minx")) |
| 323 | throw error("Object must contain 'minx'"); |
| 324 | minx = b["minx"].get<double>(); |
| 325 | |
| 326 | if (!b.contains("miny")) |
| 327 | throw error("Object must contain 'miny'"); |
| 328 | miny = b["miny"].get<double>(); |
| 329 | |
| 330 | if (!b.contains("maxx")) |
| 331 | throw error("Object must contain 'maxx'"); |
| 332 | maxx = b["maxx"].get<double>(); |
| 333 | |
| 334 | if (!b.contains("maxy")) |
| 335 | throw error("Object must contain 'maxy'"); |
| 336 | maxy = b["maxy"].get<double>(); |
| 337 | |
| 338 | if (b.contains("crs")) |
| 339 | wkt = b["crs"].get<std::string>(); |
no test coverage detected