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