Support both tzid and TZID properties on timezone geometry. Improve validation of timezone polygons.
This commit is contained in:
parent
9b45d0fbbb
commit
9b3aa33d66
@ -48,6 +48,20 @@ inline void validateFeature(const rapidjson::Value &feature)
|
||||
{
|
||||
throw osrm::util::exception("Feature has non-object properties member.");
|
||||
}
|
||||
if (feature["properties"].HasMember("tzid"))
|
||||
{
|
||||
if (!feature["properties"]["tzid"].IsString())
|
||||
throw osrm::util::exception("Feature has non-string tzid property");
|
||||
}
|
||||
else if (feature["properties"].HasMember("TZID"))
|
||||
{
|
||||
if (!feature["properties"]["TZID"].IsString())
|
||||
throw osrm::util::exception("Feature has non-string TZID property");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw osrm::util::exception("Feature is missing tzid property.");
|
||||
}
|
||||
if (!feature.HasMember("geometry"))
|
||||
{
|
||||
throw osrm::util::exception("Feature is missing geometry member.");
|
||||
@ -76,6 +90,14 @@ inline void validateFeature(const rapidjson::Value &feature)
|
||||
const auto coord_array = feature["geometry"].GetObject()["coordinates"].GetArray();
|
||||
if (coord_array.Empty())
|
||||
throw osrm::util::exception("Feature geometry coordinates member is empty.");
|
||||
|
||||
if (feature["geometry"]["type"] == "polygon" || feature["geometry"]["type"] == "Polygon")
|
||||
{
|
||||
if (!coord_array[0].IsArray() || !coord_array[0][0].IsArray())
|
||||
{
|
||||
throw osrm::util::exception("Polygon geometry missing outer ring");
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace util
|
||||
} // namespace osrm
|
||||
|
||||
@ -110,14 +110,23 @@ void Timezoner::LoadLocalTimesRTree(rapidjson::Document &geojson, std::time_t ut
|
||||
// time zone geojson specific checks
|
||||
const auto &feature = features_array[i].GetObject();
|
||||
const auto &properties = feature["properties"].GetObject();
|
||||
if (!properties.HasMember("tzid"))
|
||||
std::string tzid_key = "tzid";
|
||||
if (properties.HasMember("tzid"))
|
||||
{
|
||||
if (!properties["tzid"].IsString())
|
||||
throw osrm::util::exception("Feature has non-string 'tzid' value.");
|
||||
tzid_key = "tzid";
|
||||
}
|
||||
else if (properties.HasMember("TZID"))
|
||||
{
|
||||
if (!properties["TZID"].IsString())
|
||||
throw osrm::util::exception("Feature has non-string 'TZID' value.");
|
||||
tzid_key = "TZID";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw osrm::util::exception("Feature is missing 'tzid' member in properties.");
|
||||
}
|
||||
else if (!properties["tzid"].IsString())
|
||||
{
|
||||
throw osrm::util::exception("Feature has non-string 'tzid' value.");
|
||||
}
|
||||
|
||||
// Case-sensitive check of type https://tools.ietf.org/html/rfc7946#section-1.4
|
||||
const auto &geometry = feature["geometry"].GetObject();
|
||||
@ -137,7 +146,7 @@ void Timezoner::LoadLocalTimesRTree(rapidjson::Document &geojson, std::time_t ut
|
||||
local_times.size());
|
||||
|
||||
// Get time zone name and emplace polygon and local time for the UTC input
|
||||
const auto &tzname = properties["tzid"].GetString();
|
||||
const auto &tzname = properties[tzid_key.c_str()].GetString();
|
||||
local_times.push_back(local_time_t{polygon, get_local_time_in_tz(tzname)});
|
||||
}
|
||||
else
|
||||
|
||||
Loading…
Reference in New Issue
Block a user