geojson.input - rely on expectation failure to select optional single Feature/Geometry parser
This commit is contained in:
parent
998164dc72
commit
938702dc8b
1 changed files with 24 additions and 12 deletions
|
@ -345,22 +345,20 @@ void geojson_datasource::initialise_index(Iterator start, Iterator end)
|
|||
template <typename Iterator>
|
||||
void geojson_datasource::parse_geojson(Iterator start, Iterator end)
|
||||
{
|
||||
using boost::spirit::qi::expectation_failure;
|
||||
boost::spirit::standard::space_type space;
|
||||
mapnik::context_ptr ctx = std::make_shared<mapnik::context_type>();
|
||||
std::size_t start_id = 1;
|
||||
|
||||
mapnik::json::default_feature_callback callback(features_);
|
||||
Iterator itr = start;
|
||||
|
||||
try
|
||||
{
|
||||
bool result = boost::spirit::qi::phrase_parse(itr, end, (geojson_datasource_static_fc_grammar)
|
||||
(boost::phoenix::ref(ctx),boost::phoenix::ref(start_id), boost::phoenix::ref(callback)),
|
||||
space);
|
||||
if (!result || itr != end)
|
||||
{
|
||||
if (!inline_string_.empty()) throw mapnik::datasource_exception("geojson_datasource: Failed to parse GeoJSON file from in-memory string");
|
||||
else throw mapnik::datasource_exception("geojson_datasource: Failed to parse GeoJSON file '" + filename_ + "'");
|
||||
}
|
||||
|
||||
if (features_.size() == 0)
|
||||
{
|
||||
itr = start;
|
||||
// try parsing as single Feature or single Geometry JSON
|
||||
|
@ -373,6 +371,20 @@ void geojson_datasource::parse_geojson(Iterator start, Iterator end)
|
|||
else throw mapnik::datasource_exception("geojson_datasource: Failed parse GeoJSON file '" + filename_ + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (expectation_failure<char const*> const& ex)
|
||||
{
|
||||
itr = start;
|
||||
// try parsing as single Feature or single Geometry JSON
|
||||
bool result = boost::spirit::qi::phrase_parse(itr, end, (geojson_datasource_static_feature_callback_grammar)
|
||||
(boost::phoenix::ref(ctx),boost::phoenix::ref(start_id), boost::phoenix::ref(callback)),
|
||||
space);
|
||||
if (!result || itr != end)
|
||||
{
|
||||
if (!inline_string_.empty()) throw mapnik::datasource_exception("geojson_datasource: Failed parse GeoJSON file from in-memory string");
|
||||
else throw mapnik::datasource_exception("geojson_datasource: Failed parse GeoJSON file '" + filename_ + "'");
|
||||
}
|
||||
}
|
||||
|
||||
using values_container = std::vector< std::pair<box_type, std::pair<std::size_t, std::size_t>>>;
|
||||
values_container values;
|
||||
|
|
Loading…
Reference in a new issue