Skip to content

Commit

Permalink
Relax bounding box extracting grammar (ref mapnik#4140) + unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
artemp committed May 7, 2020
1 parent 9bfe888 commit d0b40f6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/json/extract_bounding_boxes_x3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ auto const coordinates_rule_def = lit("\"coordinates\"") >> lit(':') >> position

auto const bounding_box_def = raw[lit('{')[open_bracket]
>> *(eps[check_brackets] >>
((lit("\"FeatureCollection\"") > eps(false))
|
lit('{')[open_bracket]
(lit('{')[open_bracket]
|
lit('}')[close_bracket]
|
Expand Down
2 changes: 1 addition & 1 deletion test/data
54 changes: 54 additions & 0 deletions test/unit/datasource/geojson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,61 @@ TEST_CASE("geojson") {
{
mapnik::util::remove(filename + ".index");
}
}
}

SECTION("GeoJSON \"type\":\"FeatureCollection\" in Feature properties (#4140)")
{
// Create datasource
mapnik::parameters params;
params["type"] = "geojson";
std::string filename("./test/data/json/feature_collection_issue_4140.json");
params["file"] = filename;

// cleanup in the case of a failed previous run
if (mapnik::util::exists(filename + ".index"))
{
mapnik::util::remove(filename + ".index");
}

for (auto create_index : { true, false })
{
if (create_index)
{
int ret = create_disk_index(filename);
int ret_posix = (ret >> 8) & 0x000000ff;
INFO(ret);
INFO(ret_posix);
CHECK(mapnik::util::exists(filename + ".index"));
}

for (auto cache_features : {true, false})
{
params["cache_features"] = cache_features;
auto ds = mapnik::datasource_cache::instance().create(params);
CHECK(ds->get_geometry_type() == mapnik::datasource_geometry_t::Point);
REQUIRE(bool(ds));
auto fields = ds->get_descriptor().get_descriptors();
mapnik::query query(ds->envelope());
for (auto const& field : fields)
{
query.add_property_name(field.get_name());
}
auto features = ds->features(query);
auto feature1 = features->next();
REQUIRE(feature1 != nullptr);
REQUIRE(feature1->envelope() == mapnik::box2d<double>(-122.0,48.0,-122.0,48.0));
auto feature2 = features->next();
REQUIRE(feature2 != nullptr);
REQUIRE(feature2->envelope() == mapnik::box2d<double>(0.0,51.0,0.0,51.0));
REQUIRE(ds->envelope() == mapnik::box2d<double>(-122.0,48.0,0.0,51.0));
}

// cleanup
if (create_index && mapnik::util::exists(filename + ".index"))
{
mapnik::util::remove(filename + ".index");
}
}
}

Expand Down

0 comments on commit d0b40f6

Please sign in to comment.