deps and lint
This commit is contained in:
parent
91e1ac83d9
commit
65746edd2d
@ -17,8 +17,11 @@ inline void ValidateCoordinate(const rapidjson::Value &coordinate)
|
||||
throw osrm::util::exception("Feature geometry has a non-array coordinate.");
|
||||
if (coordinate.Capacity() != 2)
|
||||
{
|
||||
throw osrm::util::exception("Feature geometry has a malformed coordinate with more than 2 values.");
|
||||
} else {
|
||||
throw osrm::util::exception(
|
||||
"Feature geometry has a malformed coordinate with more than 2 values.");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (rapidjson::SizeType i = 0; i < coordinate.Size(); i++)
|
||||
{
|
||||
if (!coordinate[i].IsNumber() && !coordinate[i].IsDouble())
|
||||
@ -32,7 +35,8 @@ inline void ValidateFeature(const rapidjson::Value &feature)
|
||||
if (!feature.HasMember("type"))
|
||||
{
|
||||
throw osrm::util::exception("Feature is missing type member.");
|
||||
} else if (!feature["type"].IsString())
|
||||
}
|
||||
else if (!feature["type"].IsString())
|
||||
{
|
||||
throw osrm::util::exception("Feature has non-string type member.");
|
||||
}
|
||||
@ -56,13 +60,17 @@ inline void ValidateFeature(const rapidjson::Value &feature)
|
||||
if (!feature["geometry"].GetObject().HasMember("type"))
|
||||
{
|
||||
throw osrm::util::exception("Feature geometry is missing type member.");
|
||||
} else if (!feature["geometry"].GetObject()["type"].IsString()) {
|
||||
}
|
||||
else if (!feature["geometry"].GetObject()["type"].IsString())
|
||||
{
|
||||
throw osrm::util::exception("Feature geometry has non-string type member.");
|
||||
}
|
||||
if (!feature["geometry"].GetObject().HasMember("coordinates"))
|
||||
{
|
||||
throw osrm::util::exception("Feature geometry is missing coordinates member.");
|
||||
} else if (!feature["geometry"].GetObject()["coordinates"].IsArray()) {
|
||||
}
|
||||
else if (!feature["geometry"].GetObject()["coordinates"].IsArray())
|
||||
{
|
||||
throw osrm::util::exception("Feature geometry has a non-array coordinates member.");
|
||||
}
|
||||
const auto coord_array = feature["geometry"].GetObject()["coordinates"].GetArray();
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/geometry.hpp>
|
||||
#include <boost/geometry/index/rtree.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
|
||||
@ -36,6 +37,7 @@ class Timezoner
|
||||
Timezoner(const boost::filesystem::path &tz_shapes_filename, std::time_t utc_time_now);
|
||||
|
||||
boost::optional<struct tm> operator()(const point_t &point) const;
|
||||
|
||||
private:
|
||||
void LoadLocalTimesRTree(rapidjson::Document &geojson, std::time_t utc_time);
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <util/timezones.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
@ -5,15 +5,15 @@
|
||||
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/scope_exit.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/scope_exit.hpp>
|
||||
|
||||
#include "rapidjson/document.h"
|
||||
#include "rapidjson/istreamwrapper.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
// Function loads time zone shape polygons, computes a zone local time for utc_time,
|
||||
@ -33,7 +33,9 @@ Timezoner::Timezoner(const char geojson[], std::time_t utc_time_now)
|
||||
{
|
||||
auto code = ok.Code();
|
||||
auto offset = ok.Offset();
|
||||
throw osrm::util::exception("Failed to parse timezone geojson with error code " + std::to_string(code) + " malformed at offset " + std::to_string(offset));
|
||||
throw osrm::util::exception("Failed to parse timezone geojson with error code " +
|
||||
std::to_string(code) + " malformed at offset " +
|
||||
std::to_string(offset));
|
||||
}
|
||||
LoadLocalTimesRTree(doc, utc_time_now);
|
||||
}
|
||||
@ -56,8 +58,9 @@ Timezoner::Timezoner(const boost::filesystem::path &tz_shapes_filename, std::tim
|
||||
{
|
||||
auto error_code = geojson.GetParseError();
|
||||
auto error_offset = geojson.GetErrorOffset();
|
||||
throw osrm::util::exception("Failed to parse " + tz_shapes_filename.string() + " with error " +
|
||||
std::to_string(error_code) + ". JSON malformed at " + std::to_string(error_offset));
|
||||
throw osrm::util::exception("Failed to parse " + tz_shapes_filename.string() +
|
||||
" with error " + std::to_string(error_code) +
|
||||
". JSON malformed at " + std::to_string(error_offset));
|
||||
}
|
||||
LoadLocalTimesRTree(geojson, utc_time_now);
|
||||
}
|
||||
@ -67,9 +70,11 @@ void Timezoner::LoadLocalTimesRTree(rapidjson::Document &geojson, std::time_t ut
|
||||
if (!geojson.HasMember("type"))
|
||||
throw osrm::util::exception("Failed to parse time zone file. Missing type member.");
|
||||
if (!geojson["type"].IsString())
|
||||
throw osrm::util::exception("Failed to parse time zone file. Missing string-based type member.");
|
||||
throw osrm::util::exception(
|
||||
"Failed to parse time zone file. Missing string-based type member.");
|
||||
if (geojson["type"].GetString() != std::string("FeatureCollection"))
|
||||
throw osrm::util::exception("Failed to parse time zone file. Geojson is not of FeatureCollection type");
|
||||
throw osrm::util::exception(
|
||||
"Failed to parse time zone file. Geojson is not of FeatureCollection type");
|
||||
if (!geojson.HasMember("features"))
|
||||
throw osrm::util::exception("Failed to parse time zone file. Missing features list.");
|
||||
|
||||
@ -96,7 +101,8 @@ void Timezoner::LoadLocalTimesRTree(rapidjson::Document &geojson, std::time_t ut
|
||||
{
|
||||
util::ValidateFeature(features_array[i]);
|
||||
// time zone geojson specific checks
|
||||
if (!features_array[i]["properties"].GetObject().HasMember("TZID") && !features_array[i]["properties"].GetObject().HasMember("tzid"))
|
||||
if (!features_array[i]["properties"].GetObject().HasMember("TZID") &&
|
||||
!features_array[i]["properties"].GetObject().HasMember("tzid"))
|
||||
{
|
||||
throw osrm::util::exception("Feature is missing TZID member in properties.");
|
||||
}
|
||||
@ -104,13 +110,15 @@ void Timezoner::LoadLocalTimesRTree(rapidjson::Document &geojson, std::time_t ut
|
||||
{
|
||||
throw osrm::util::exception("Feature has non-string TZID value.");
|
||||
}
|
||||
const std::string &feat_type = features_array[i].GetObject()["geometry"].GetObject()["type"].GetString();
|
||||
const std::string &feat_type =
|
||||
features_array[i].GetObject()["geometry"].GetObject()["type"].GetString();
|
||||
std::regex polygon_match("polygon", std::regex::icase);
|
||||
std::smatch res;
|
||||
if (std::regex_match(feat_type, res, polygon_match))
|
||||
{
|
||||
polygon_t polygon;
|
||||
// per geojson spec, the first array of polygon coords is the exterior ring, we only want to access that
|
||||
// per geojson spec, the first array of polygon coords is the exterior ring, we only
|
||||
// want to access that
|
||||
auto coords_outer_array = features_array[i]
|
||||
.GetObject()["geometry"]
|
||||
.GetObject()["coordinates"]
|
||||
@ -149,7 +157,6 @@ boost::optional<struct tm> Timezoner::operator()(const point_t &point) const
|
||||
const auto index = v.second;
|
||||
if (boost::geometry::within(point, local_times[index].first))
|
||||
return local_times[index].second;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,11 +39,11 @@ BOOST_AUTO_TEST_CASE(timezone_validation_test)
|
||||
doc.Parse(json);
|
||||
BOOST_CHECK_NO_THROW(util::ValidateFeature(doc));
|
||||
|
||||
char missing_type[] =
|
||||
"{\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
char missing_type[] = "{\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { "
|
||||
"\"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
doc.Parse(missing_type);
|
||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
||||
|
||||
@ -65,30 +65,28 @@ BOOST_AUTO_TEST_CASE(timezone_validation_test)
|
||||
doc.Parse(nonobj_props);
|
||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
||||
|
||||
char missing_tzid[] =
|
||||
"{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { }, \"geometry\" : { \"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
char missing_tzid[] = "{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { }, \"geometry\" : { \"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
doc.Parse(missing_tzid);
|
||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
||||
|
||||
char tzid_err[] =
|
||||
"{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : []}, \"geometry\" : { \"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
char tzid_err[] = "{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : []}, \"geometry\" : { \"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
doc.Parse(tzid_err);
|
||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
||||
|
||||
char missing_geom[] =
|
||||
"{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometries\" : { \"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
char missing_geom[] = "{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometries\" : { "
|
||||
"\"type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
doc.Parse(missing_geom);
|
||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
||||
|
||||
@ -101,21 +99,21 @@ BOOST_AUTO_TEST_CASE(timezone_validation_test)
|
||||
doc.Parse(nonobj_geom);
|
||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
||||
|
||||
char missing_geom_type[] =
|
||||
"{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"no_type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
char missing_geom_type[] = "{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { "
|
||||
"\"no_type\": \"polygon\", "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
doc.Parse(missing_geom_type);
|
||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
||||
|
||||
char nonstring_geom_type[] =
|
||||
"{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : { \"type\": [\"polygon\"], "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
char nonstring_geom_type[] = "{ \"type\" : \"Feature\","
|
||||
"\"properties\" : { \"TZID\" : \"Europe/Berlin\"}, \"geometry\" : "
|
||||
"{ \"type\": [\"polygon\"], "
|
||||
"\"coordinates\": [[[8.28369,48.88277], [8.57757, "
|
||||
"48.88277], [8.57757, 49.07206], [8.28369, "
|
||||
"49.07206], [8.28369, 48.88277]]] }}";
|
||||
doc.Parse(nonstring_geom_type);
|
||||
BOOST_CHECK_THROW(util::ValidateFeature(doc), util::exception);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user