2015-07-10 09:05:48 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2021-01-05 14:39:07 +00:00
|
|
|
* Copyright (C) 2021 Artem Pavlenko
|
2015-07-10 09:05:48 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "catch.hpp"
|
2016-01-15 16:37:30 +00:00
|
|
|
#include "ds_test_util.hpp"
|
2015-07-10 09:05:48 +00:00
|
|
|
|
2016-05-24 10:16:48 +00:00
|
|
|
#include <mapnik/unicode.hpp>
|
2015-07-10 09:05:48 +00:00
|
|
|
#include <mapnik/datasource.hpp>
|
|
|
|
#include <mapnik/datasource_cache.hpp>
|
|
|
|
#include <mapnik/geometry.hpp>
|
2017-03-27 15:14:51 +00:00
|
|
|
#include <mapnik/geometry/geometry_type.hpp>
|
2024-02-26 14:45:59 +00:00
|
|
|
#include <mapnik/geometry/is_empty.hpp>
|
2017-03-27 15:14:51 +00:00
|
|
|
#include <mapnik/json/geometry_parser.hpp>
|
|
|
|
#include <mapnik/util/geometry_to_geojson.hpp>
|
2015-07-10 19:34:18 +00:00
|
|
|
#include <mapnik/util/fs.hpp>
|
2015-10-19 15:58:32 +00:00
|
|
|
#include <cstdlib>
|
2017-03-27 15:14:51 +00:00
|
|
|
#include <algorithm>
|
2017-07-06 14:02:17 +00:00
|
|
|
#include <cctype>
|
|
|
|
#include <locale>
|
2015-10-21 06:17:44 +00:00
|
|
|
#include <boost/optional/optional_io.hpp>
|
2015-10-21 05:56:03 +00:00
|
|
|
|
2015-10-29 15:01:36 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
Compile and run just this test:
|
|
|
|
|
|
|
|
clang++ -o test-geojson -g -I./test/ test/unit/run.cpp test/unit/datasource/geojson.cpp `mapnik-config --all-flags`
|
|
|
|
./test-geojson -d yes
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2015-10-23 12:09:21 +00:00
|
|
|
namespace {
|
2015-10-19 11:23:43 +00:00
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
std::pair<mapnik::datasource_ptr, mapnik::feature_ptr> fetch_first_feature(std::string const& filename,
|
|
|
|
bool cache_features)
|
2015-10-19 11:23:43 +00:00
|
|
|
{
|
|
|
|
mapnik::parameters params;
|
|
|
|
params["type"] = "geojson";
|
|
|
|
params["file"] = filename;
|
2015-10-22 14:53:23 +00:00
|
|
|
params["cache_features"] = cache_features;
|
2015-10-19 11:23:43 +00:00
|
|
|
auto ds = mapnik::datasource_cache::instance().create(params);
|
2015-10-21 16:15:07 +00:00
|
|
|
CHECK(ds->type() == mapnik::datasource::datasource_t::Vector);
|
2015-10-19 11:23:43 +00:00
|
|
|
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 feature = features->next();
|
2022-01-26 22:25:53 +00:00
|
|
|
return std::make_pair(ds, feature);
|
2015-10-19 11:23:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-10 14:34:52 +00:00
|
|
|
void iterate_over_features(mapnik::featureset_ptr features)
|
|
|
|
{
|
|
|
|
auto feature = features->next();
|
|
|
|
while (feature != nullptr)
|
|
|
|
{
|
|
|
|
feature = features->next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
} // namespace
|
2015-07-10 09:05:48 +00:00
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
TEST_CASE("geojson")
|
|
|
|
{
|
2022-02-14 09:15:09 +00:00
|
|
|
const bool have_geojson_plugin = mapnik::datasource_cache::instance().plugin_registered("geojson");
|
|
|
|
if (have_geojson_plugin)
|
2015-07-10 09:05:48 +00:00
|
|
|
{
|
2015-10-23 13:11:17 +00:00
|
|
|
SECTION("GeoJSON I/O errors")
|
|
|
|
{
|
|
|
|
std::string filename = "does_not_exist.geojson";
|
2022-01-26 22:25:53 +00:00
|
|
|
for (auto create_index : {true, false})
|
2015-10-23 13:11:17 +00:00
|
|
|
{
|
|
|
|
if (create_index)
|
|
|
|
{
|
|
|
|
int ret = create_disk_index(filename);
|
|
|
|
int ret_posix = (ret >> 8) & 0x000000ff;
|
|
|
|
INFO(ret);
|
|
|
|
INFO(ret_posix);
|
|
|
|
// index wont be created
|
|
|
|
CHECK(!mapnik::util::exists(filename + ".index"));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto cache_features : {true, false})
|
|
|
|
{
|
|
|
|
mapnik::parameters params;
|
|
|
|
params["type"] = "geojson";
|
|
|
|
params["file"] = filename;
|
|
|
|
params["cache_features"] = cache_features;
|
|
|
|
REQUIRE_THROWS(mapnik::datasource_cache::instance().create(params));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-23 13:17:41 +00:00
|
|
|
|
2016-08-15 09:44:54 +00:00
|
|
|
SECTION("GeoJSON an empty FeatureCollection")
|
|
|
|
{
|
|
|
|
for (auto cache_features : {true, false})
|
|
|
|
{
|
|
|
|
mapnik::parameters params;
|
|
|
|
params["type"] = "geojson";
|
|
|
|
params["file"] = "./test/data/json/empty_featurecollection.json";
|
|
|
|
params["cache_features"] = cache_features;
|
2017-09-11 16:54:54 +00:00
|
|
|
REQUIRE_THROWS(mapnik::datasource_cache::instance().create(params));
|
2016-08-15 09:44:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-27 15:14:51 +00:00
|
|
|
SECTION("GeoJSON empty Geometries handling")
|
|
|
|
{
|
2022-01-26 22:25:53 +00:00
|
|
|
auto valid_empty_geometries = {"null", // Point can't be empty
|
2024-02-26 14:01:09 +00:00
|
|
|
"{ \"type\": \"LineString\", \"coordinates\":[]}",
|
|
|
|
"{ \"type\": \"Polygon\", \"coordinates\":[]} ",
|
|
|
|
"{ \"type\": \"Polygon\", \"coordinates\":[[]]} ",
|
|
|
|
"{ \"type\": \"MultiPoint\", \"coordinates\":[]}",
|
|
|
|
"{ \"type\": \"MultiLineString\", \"coordinates\":[]}",
|
|
|
|
"{ \"type\": \"MultiLineString\", \"coordinates\":[[]]}",
|
|
|
|
"{ \"type\": \"MultiPolygon\", \"coordinates\":[]}",
|
|
|
|
"{ \"type\": \"MultiPolygon\", \"coordinates\":[[]]}",
|
|
|
|
"{ \"type\": \"MultiPolygon\", \"coordinates\": [[[]]] }"};
|
2017-03-27 15:14:51 +00:00
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
for (auto const& in : valid_empty_geometries)
|
2017-03-27 15:14:51 +00:00
|
|
|
{
|
|
|
|
std::string json(in);
|
|
|
|
mapnik::geometry::geometry<double> geom;
|
|
|
|
CHECK(mapnik::json::from_geojson(json, geom));
|
2024-02-26 16:25:40 +00:00
|
|
|
REQUIRE(mapnik::geometry::is_empty(geom));
|
2024-02-26 14:48:49 +00:00
|
|
|
// round trip
|
2017-03-27 15:14:51 +00:00
|
|
|
std::string json_out;
|
|
|
|
CHECK(mapnik::util::to_geojson(json_out, geom));
|
2022-01-26 22:25:53 +00:00
|
|
|
json.erase(std::remove_if(std::begin(json),
|
|
|
|
std::end(json),
|
|
|
|
[l = std::locale{}](auto ch) { return std::isspace(ch, l); }),
|
|
|
|
std::end(json));
|
2017-03-27 15:14:51 +00:00
|
|
|
REQUIRE(json == json_out);
|
|
|
|
}
|
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
auto invalid_empty_geometries = {"{ \"type\": \"Point\", \"coordinates\": [] }",
|
|
|
|
"{ \"type\": \"LineString\", \"coordinates\": [[]] }"
|
|
|
|
"{ \"type\": \"Polygon\", \"coordinates\": [[[]]] }",
|
|
|
|
"{ \"type\": \"MultiPoint\", \"coordinates\": [[]] }",
|
|
|
|
"{ \"type\": \"MultiLineString\", \"coordinates\": [[[]]] }",
|
|
|
|
"{ \"type\": \"MultiPolygon\", \"coordinates\": [[[[]]]] }"};
|
2017-03-27 15:14:51 +00:00
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
for (auto const& json : invalid_empty_geometries)
|
2017-03-27 15:14:51 +00:00
|
|
|
{
|
|
|
|
mapnik::geometry::geometry<double> geom;
|
|
|
|
CHECK(!mapnik::json::from_geojson(json, geom));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-23 09:55:38 +00:00
|
|
|
SECTION("GeoJSON num_features_to_query")
|
|
|
|
{
|
|
|
|
std::string filename = "./test/data/json/featurecollection-multipleprops.geojson";
|
2022-01-26 22:25:53 +00:00
|
|
|
for (mapnik::value_integer num_features_to_query : {mapnik::value_integer(-1),
|
|
|
|
mapnik::value_integer(0),
|
|
|
|
mapnik::value_integer(1),
|
|
|
|
mapnik::value_integer(2),
|
|
|
|
mapnik::value_integer(3),
|
|
|
|
std::numeric_limits<mapnik::value_integer>::max()})
|
2016-09-23 09:55:38 +00:00
|
|
|
{
|
2022-01-26 22:25:53 +00:00
|
|
|
for (auto create_index : {true, false})
|
2016-09-23 09:55:38 +00:00
|
|
|
{
|
|
|
|
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})
|
|
|
|
{
|
|
|
|
mapnik::parameters params;
|
|
|
|
params["type"] = "geojson";
|
|
|
|
params["file"] = filename;
|
|
|
|
params["cache_features"] = cache_features;
|
|
|
|
params["num_features_to_query"] = num_features_to_query;
|
|
|
|
auto ds = mapnik::datasource_cache::instance().create(params);
|
|
|
|
CHECK(ds != nullptr);
|
|
|
|
auto fields = ds->get_descriptor().get_descriptors();
|
|
|
|
if (!create_index && cache_features)
|
|
|
|
{
|
|
|
|
// when there's no index and caching is enabled descriptor is always fully initialised
|
|
|
|
REQUIRE(fields.size() == 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// at least 1 feature should be queried
|
|
|
|
REQUIRE(fields.size() == std::min(std::max(mapnik::value_integer(1), num_features_to_query),
|
|
|
|
mapnik::value_integer(2)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// cleanup
|
|
|
|
if (create_index && mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
|
|
|
mapnik::util::remove(filename + ".index");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-16 14:45:12 +00:00
|
|
|
SECTION("GeoJSON attribute descriptors are alphabetically ordered")
|
|
|
|
{
|
|
|
|
for (auto cache_features : {true, false})
|
|
|
|
{
|
|
|
|
mapnik::parameters params;
|
|
|
|
params["type"] = "geojson";
|
|
|
|
params["file"] = "./test/data/json/properties.json";
|
|
|
|
params["cache_features"] = cache_features;
|
|
|
|
auto ds = mapnik::datasource_cache::instance().create(params);
|
|
|
|
CHECK(ds != nullptr);
|
|
|
|
std::vector<std::string> expected_names = {"a", "b", "c", "d", "e"};
|
|
|
|
auto fields = ds->get_descriptor().get_descriptors();
|
|
|
|
std::size_t index = 0;
|
|
|
|
for (auto const& field : fields)
|
|
|
|
{
|
|
|
|
REQUIRE(field.get_name() == expected_names[index++]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-23 13:17:41 +00:00
|
|
|
SECTION("GeoJSON invalid Point")
|
|
|
|
{
|
|
|
|
for (auto cache_features : {true, false})
|
|
|
|
{
|
|
|
|
mapnik::parameters params;
|
|
|
|
params["type"] = "geojson";
|
|
|
|
params["file"] = "./test/data/json/point-invalid.json";
|
|
|
|
params["cache_features"] = cache_features;
|
|
|
|
REQUIRE_THROWS(mapnik::datasource_cache::instance().create(params));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-06 11:48:32 +00:00
|
|
|
SECTION("GeoJSON Point")
|
2015-10-19 11:23:43 +00:00
|
|
|
{
|
2015-10-20 10:22:42 +00:00
|
|
|
for (auto cache_features : {true, false})
|
2015-10-19 11:23:43 +00:00
|
|
|
{
|
2015-10-23 12:09:21 +00:00
|
|
|
auto result = fetch_first_feature("./test/data/json/point.json", cache_features);
|
2015-10-21 06:17:44 +00:00
|
|
|
auto feature = result.second;
|
|
|
|
auto ds = result.first;
|
|
|
|
CHECK(ds->get_geometry_type() == mapnik::datasource_geometry_t::Point);
|
2015-10-19 11:23:43 +00:00
|
|
|
auto const& geometry = feature->get_geometry();
|
|
|
|
REQUIRE(mapnik::geometry::geometry_type(geometry) == mapnik::geometry::Point);
|
2022-01-26 22:25:53 +00:00
|
|
|
auto const& pt = mapnik::util::get<mapnik::geometry::point<double>>(geometry);
|
2015-10-19 11:23:43 +00:00
|
|
|
REQUIRE(pt.x == 100);
|
|
|
|
REQUIRE(pt.y == 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("GeoJSON LineString")
|
|
|
|
{
|
2015-10-20 10:22:42 +00:00
|
|
|
for (auto cache_features : {true, false})
|
2015-10-19 11:23:43 +00:00
|
|
|
{
|
2015-10-23 12:09:21 +00:00
|
|
|
auto result = fetch_first_feature("./test/data/json/linestring.json", cache_features);
|
2015-10-21 06:17:44 +00:00
|
|
|
auto feature = result.second;
|
|
|
|
auto ds = result.first;
|
|
|
|
CHECK(ds->get_geometry_type() == mapnik::datasource_geometry_t::LineString);
|
2015-10-19 11:23:43 +00:00
|
|
|
auto const& geometry = feature->get_geometry();
|
|
|
|
REQUIRE(mapnik::geometry::geometry_type(geometry) == mapnik::geometry::LineString);
|
2022-01-26 22:25:53 +00:00
|
|
|
auto const& line = mapnik::util::get<mapnik::geometry::line_string<double>>(geometry);
|
2015-10-19 11:23:43 +00:00
|
|
|
REQUIRE(line.size() == 2);
|
2022-01-26 22:25:53 +00:00
|
|
|
REQUIRE(mapnik::geometry::envelope(line) == mapnik::box2d<double>(100, 0, 101, 1));
|
2015-10-19 11:23:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("GeoJSON Polygon")
|
|
|
|
{
|
2015-10-20 10:22:42 +00:00
|
|
|
for (auto cache_features : {true, false})
|
2015-10-19 11:23:43 +00:00
|
|
|
{
|
2015-10-23 12:09:21 +00:00
|
|
|
auto result = fetch_first_feature("./test/data/json/polygon.json", cache_features);
|
2015-10-21 06:17:44 +00:00
|
|
|
auto feature = result.second;
|
|
|
|
auto ds = result.first;
|
|
|
|
CHECK(ds->get_geometry_type() == mapnik::datasource_geometry_t::Polygon);
|
2015-10-19 11:23:43 +00:00
|
|
|
auto const& geometry = feature->get_geometry();
|
|
|
|
REQUIRE(mapnik::geometry::geometry_type(geometry) == mapnik::geometry::Polygon);
|
2022-01-26 22:25:53 +00:00
|
|
|
auto const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geometry);
|
2016-06-29 11:37:32 +00:00
|
|
|
REQUIRE(poly.size() == 2);
|
|
|
|
REQUIRE(poly[0].size() == 5);
|
|
|
|
REQUIRE(poly[1].size() == 5);
|
2022-01-26 22:25:53 +00:00
|
|
|
REQUIRE(mapnik::geometry::envelope(poly) == mapnik::box2d<double>(100, 0, 101, 1));
|
2015-10-19 11:23:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("GeoJSON MultiPoint")
|
|
|
|
{
|
2015-10-20 10:22:42 +00:00
|
|
|
for (auto cache_features : {true, false})
|
2015-10-19 11:23:43 +00:00
|
|
|
{
|
2015-10-23 12:09:21 +00:00
|
|
|
auto result = fetch_first_feature("./test/data/json/multipoint.json", cache_features);
|
2015-10-21 06:17:44 +00:00
|
|
|
auto feature = result.second;
|
|
|
|
auto ds = result.first;
|
|
|
|
CHECK(ds->get_geometry_type() == mapnik::datasource_geometry_t::Point);
|
2015-10-19 11:23:43 +00:00
|
|
|
auto const& geometry = feature->get_geometry();
|
|
|
|
REQUIRE(mapnik::geometry::geometry_type(geometry) == mapnik::geometry::MultiPoint);
|
2022-01-26 22:25:53 +00:00
|
|
|
auto const& multi_pt = mapnik::util::get<mapnik::geometry::multi_point<double>>(geometry);
|
2015-10-19 11:23:43 +00:00
|
|
|
REQUIRE(multi_pt.size() == 2);
|
2022-01-26 22:25:53 +00:00
|
|
|
REQUIRE(mapnik::geometry::envelope(multi_pt) == mapnik::box2d<double>(100, 0, 101, 1));
|
2015-10-19 11:23:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("GeoJSON MultiLineString")
|
|
|
|
{
|
2015-10-20 10:22:42 +00:00
|
|
|
for (auto cache_features : {true, false})
|
2015-10-19 11:23:43 +00:00
|
|
|
{
|
2015-10-23 12:09:21 +00:00
|
|
|
auto result = fetch_first_feature("./test/data/json/multilinestring.json", cache_features);
|
2015-10-21 06:17:44 +00:00
|
|
|
auto feature = result.second;
|
|
|
|
auto ds = result.first;
|
|
|
|
CHECK(ds->get_geometry_type() == mapnik::datasource_geometry_t::LineString);
|
2015-10-19 11:23:43 +00:00
|
|
|
auto const& geometry = feature->get_geometry();
|
|
|
|
REQUIRE(mapnik::geometry::geometry_type(geometry) == mapnik::geometry::MultiLineString);
|
2022-01-26 22:25:53 +00:00
|
|
|
auto const& multi_line = mapnik::util::get<mapnik::geometry::multi_line_string<double>>(geometry);
|
2015-10-19 11:23:43 +00:00
|
|
|
REQUIRE(multi_line.size() == 2);
|
|
|
|
REQUIRE(multi_line[0].size() == 2);
|
|
|
|
REQUIRE(multi_line[1].size() == 2);
|
2022-01-26 22:25:53 +00:00
|
|
|
REQUIRE(mapnik::geometry::envelope(multi_line) == mapnik::box2d<double>(100, 0, 103, 3));
|
2015-10-19 11:23:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("GeoJSON MultiPolygon")
|
|
|
|
{
|
2015-10-20 10:22:42 +00:00
|
|
|
for (auto cache_features : {true, false})
|
2015-10-19 11:23:43 +00:00
|
|
|
{
|
2015-10-23 12:09:21 +00:00
|
|
|
auto result = fetch_first_feature("./test/data/json/multipolygon.json", cache_features);
|
2015-10-21 06:17:44 +00:00
|
|
|
auto feature = result.second;
|
|
|
|
auto ds = result.first;
|
|
|
|
CHECK(ds->get_geometry_type() == mapnik::datasource_geometry_t::Polygon);
|
2015-10-19 11:23:43 +00:00
|
|
|
// test
|
|
|
|
auto const& geometry = feature->get_geometry();
|
|
|
|
REQUIRE(mapnik::geometry::geometry_type(geometry) == mapnik::geometry::MultiPolygon);
|
2022-01-26 22:25:53 +00:00
|
|
|
auto const& multi_poly = mapnik::util::get<mapnik::geometry::multi_polygon<double>>(geometry);
|
2015-10-19 11:23:43 +00:00
|
|
|
REQUIRE(multi_poly.size() == 2);
|
2016-06-29 11:37:32 +00:00
|
|
|
REQUIRE(multi_poly[0].size() == 1);
|
|
|
|
REQUIRE(multi_poly[1].size() == 2);
|
2022-01-26 22:25:53 +00:00
|
|
|
REQUIRE(mapnik::geometry::envelope(multi_poly) == mapnik::box2d<double>(100, 0, 103, 3));
|
2015-10-19 11:23:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("GeoJSON GeometryCollection")
|
|
|
|
{
|
2015-10-21 05:56:03 +00:00
|
|
|
std::string filename("./test/data/json/geometrycollection.json");
|
2022-01-26 22:25:53 +00:00
|
|
|
for (auto create_index : {true, false})
|
2015-10-19 11:23:43 +00:00
|
|
|
{
|
2015-10-21 05:56:03 +00:00
|
|
|
if (create_index)
|
|
|
|
{
|
2015-10-23 12:09:21 +00:00
|
|
|
int ret = create_disk_index(filename);
|
2015-10-21 05:56:03 +00:00
|
|
|
int ret_posix = (ret >> 8) & 0x000000ff;
|
|
|
|
INFO(ret);
|
|
|
|
INFO(ret_posix);
|
|
|
|
// index will not exist because this is not a featurecollection
|
|
|
|
CHECK(!mapnik::util::exists(filename + ".index"));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto cache_features : {true, false})
|
|
|
|
{
|
2015-10-23 12:09:21 +00:00
|
|
|
auto result = fetch_first_feature(filename, cache_features);
|
2015-10-21 06:17:44 +00:00
|
|
|
auto feature = result.second;
|
|
|
|
auto ds = result.first;
|
|
|
|
CHECK(ds->get_geometry_type() == mapnik::datasource_geometry_t::Collection);
|
2015-10-21 05:56:03 +00:00
|
|
|
// test
|
|
|
|
auto const& geometry = feature->get_geometry();
|
|
|
|
REQUIRE(mapnik::geometry::geometry_type(geometry) == mapnik::geometry::GeometryCollection);
|
2022-01-26 22:25:53 +00:00
|
|
|
auto const& collection = mapnik::util::get<mapnik::geometry::geometry_collection<double>>(geometry);
|
2015-10-21 05:56:03 +00:00
|
|
|
REQUIRE(collection.size() == 2);
|
|
|
|
REQUIRE(mapnik::geometry::geometry_type(collection[0]) == mapnik::geometry::Point);
|
|
|
|
REQUIRE(mapnik::geometry::geometry_type(collection[1]) == mapnik::geometry::LineString);
|
2022-01-26 22:25:53 +00:00
|
|
|
REQUIRE(mapnik::geometry::envelope(collection) == mapnik::box2d<double>(100, 0, 102, 1));
|
2015-10-21 05:56:03 +00:00
|
|
|
}
|
2015-10-19 11:23:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-20 11:04:32 +00:00
|
|
|
SECTION("GeoJSON Feature")
|
|
|
|
{
|
|
|
|
// Create datasource
|
|
|
|
mapnik::parameters params;
|
|
|
|
params["type"] = "geojson";
|
2015-10-22 15:45:34 +00:00
|
|
|
std::string base("./test/data/json/");
|
|
|
|
std::string file("feature.json");
|
|
|
|
params["base"] = base;
|
|
|
|
params["file"] = file;
|
|
|
|
std::string filename = base + file;
|
2022-01-26 22:25:53 +00:00
|
|
|
for (auto create_index : {true, false})
|
2015-10-20 11:04:32 +00:00
|
|
|
{
|
2015-10-21 05:56:03 +00:00
|
|
|
if (create_index)
|
|
|
|
{
|
2015-10-23 12:09:21 +00:00
|
|
|
int ret = create_disk_index(filename);
|
2015-10-21 05:56:03 +00:00
|
|
|
int ret_posix = (ret >> 8) & 0x000000ff;
|
|
|
|
INFO(ret);
|
|
|
|
INFO(ret_posix);
|
|
|
|
// index will not exist because this is not a featurecollection
|
|
|
|
CHECK(!mapnik::util::exists(filename + ".index"));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto cache_features : {true, false})
|
2015-10-20 11:04:32 +00:00
|
|
|
{
|
2015-10-22 15:13:08 +00:00
|
|
|
params["cache_features"] = cache_features;
|
2015-10-21 05:56:03 +00:00
|
|
|
auto ds = mapnik::datasource_cache::instance().create(params);
|
|
|
|
REQUIRE(bool(ds));
|
2015-10-21 16:15:07 +00:00
|
|
|
CHECK(ds->get_geometry_type() == mapnik::datasource_geometry_t::Point);
|
2015-10-21 05:56:03 +00:00
|
|
|
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);
|
2022-01-26 22:25:53 +00:00
|
|
|
auto features2 = ds->features_at_point(ds->envelope().center(), 0);
|
2015-10-21 05:56:03 +00:00
|
|
|
auto feature = features->next();
|
2015-10-21 19:37:30 +00:00
|
|
|
auto feature2 = features2->next();
|
2015-10-21 05:56:03 +00:00
|
|
|
REQUIRE(feature != nullptr);
|
2015-10-21 19:37:30 +00:00
|
|
|
REQUIRE(feature2 != nullptr);
|
|
|
|
CHECK(feature->id() == 1);
|
|
|
|
CHECK(feature2->id() == 1);
|
|
|
|
mapnik::value val = feature->get("name");
|
|
|
|
CHECK(val.to_string() == "Dinagat Islands");
|
|
|
|
mapnik::value val2 = feature2->get("name");
|
|
|
|
CHECK(val2.to_string() == "Dinagat Islands");
|
|
|
|
REQUIRE(features->next() == nullptr);
|
|
|
|
REQUIRE(features2->next() == nullptr);
|
2015-10-20 11:04:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-09 09:03:00 +00:00
|
|
|
SECTION("GeoJSON ensure empty and null properties are handled")
|
|
|
|
{
|
|
|
|
mapnik::parameters params;
|
|
|
|
params["type"] = "geojson";
|
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
for (auto const& c_str :
|
|
|
|
{"./test/data/json/feature-null-properties.json", "./test/data/json/feature-empty-properties.json"})
|
2020-10-09 09:03:00 +00:00
|
|
|
{
|
|
|
|
std::string filename(c_str);
|
|
|
|
params["file"] = filename;
|
|
|
|
|
|
|
|
// cleanup in the case of a failed previous run
|
|
|
|
if (mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
|
|
|
mapnik::util::remove(filename + ".index");
|
|
|
|
}
|
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
for (auto create_index : {true, false})
|
2020-10-09 09:03:00 +00:00
|
|
|
{
|
|
|
|
if (create_index)
|
|
|
|
{
|
|
|
|
CHECK(!mapnik::util::exists(filename + ".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);
|
|
|
|
REQUIRE(bool(ds));
|
|
|
|
CHECK(ds->get_geometry_type() == mapnik::datasource_geometry_t::Point);
|
|
|
|
auto fields = ds->get_descriptor().get_descriptors();
|
|
|
|
CHECK(fields.size() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
if (create_index && mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
|
|
|
mapnik::util::remove(filename + ".index");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-20 10:46:39 +00:00
|
|
|
SECTION("GeoJSON FeatureCollection")
|
2015-10-19 15:58:32 +00:00
|
|
|
{
|
|
|
|
std::string filename("./test/data/json/featurecollection.json");
|
2015-10-20 10:46:39 +00:00
|
|
|
|
2015-10-21 05:56:03 +00:00
|
|
|
// cleanup in the case of a failed previous run
|
|
|
|
if (mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
2015-10-23 17:39:55 +00:00
|
|
|
mapnik::util::remove(filename + ".index");
|
2015-10-21 05:56:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
for (auto create_index : {true, false})
|
2015-10-19 15:58:32 +00:00
|
|
|
{
|
2015-10-20 10:46:39 +00:00
|
|
|
if (create_index)
|
|
|
|
{
|
2015-10-23 12:09:21 +00:00
|
|
|
int ret = create_disk_index(filename);
|
2015-10-20 22:18:12 +00:00
|
|
|
int ret_posix = (ret >> 8) & 0x000000ff;
|
2015-10-20 19:23:05 +00:00
|
|
|
INFO(ret);
|
2015-10-20 22:18:12 +00:00
|
|
|
INFO(ret_posix);
|
2015-10-20 19:19:06 +00:00
|
|
|
CHECK(mapnik::util::exists(filename + ".index"));
|
2015-10-20 10:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mapnik::parameters params;
|
|
|
|
params["type"] = "geojson";
|
|
|
|
params["file"] = filename;
|
|
|
|
|
|
|
|
for (auto cache_features : {true, false})
|
2015-10-19 15:58:32 +00:00
|
|
|
{
|
2015-10-20 10:46:39 +00:00
|
|
|
params["cache_features"] = cache_features;
|
|
|
|
|
2015-10-19 15:58:32 +00:00
|
|
|
auto ds = mapnik::datasource_cache::instance().create(params);
|
2015-10-21 16:15:07 +00:00
|
|
|
CHECK(ds->get_geometry_type() == mapnik::datasource_geometry_t::Collection);
|
2015-10-19 15:58:32 +00:00
|
|
|
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);
|
2022-01-26 22:25:53 +00:00
|
|
|
auto features2 = ds->features_at_point(ds->envelope().center(), 10);
|
2015-10-19 15:58:32 +00:00
|
|
|
auto bounding_box = ds->envelope();
|
|
|
|
mapnik::box2d<double> bbox;
|
2015-10-20 10:46:39 +00:00
|
|
|
mapnik::value_integer count = 0;
|
2015-10-19 15:58:32 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
auto feature = features->next();
|
2015-10-21 19:37:30 +00:00
|
|
|
auto feature2 = features2->next();
|
2022-01-26 22:25:53 +00:00
|
|
|
if (!feature || !feature2)
|
|
|
|
break;
|
|
|
|
if (!bbox.valid())
|
|
|
|
bbox = feature->envelope();
|
|
|
|
else
|
|
|
|
bbox.expand_to_include(feature->envelope());
|
2015-10-19 15:58:32 +00:00
|
|
|
++count;
|
2015-10-20 10:46:39 +00:00
|
|
|
REQUIRE(feature->id() == count);
|
2015-10-21 19:37:30 +00:00
|
|
|
REQUIRE(feature2->id() == count);
|
2015-10-19 15:58:32 +00:00
|
|
|
}
|
|
|
|
REQUIRE(count == 3);
|
|
|
|
REQUIRE(bounding_box == bbox);
|
2015-10-20 10:46:39 +00:00
|
|
|
}
|
|
|
|
if (mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
2015-10-19 15:58:32 +00:00
|
|
|
CHECK(mapnik::util::remove(filename + ".index"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-20 11:04:32 +00:00
|
|
|
SECTION("GeoJSON extra properties")
|
2015-07-17 15:43:04 +00:00
|
|
|
{
|
|
|
|
// Create datasource
|
|
|
|
mapnik::parameters params;
|
|
|
|
params["type"] = "geojson";
|
2015-10-21 05:56:03 +00:00
|
|
|
std::string filename("./test/data/json/feature_collection_extra_properties.json");
|
|
|
|
params["file"] = filename;
|
|
|
|
|
|
|
|
// cleanup in the case of a failed previous run
|
|
|
|
if (mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
2015-10-23 17:39:55 +00:00
|
|
|
mapnik::util::remove(filename + ".index");
|
2015-10-21 05:56:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
for (auto create_index : {true, false})
|
2015-07-17 15:43:04 +00:00
|
|
|
{
|
2015-10-21 05:56:03 +00:00
|
|
|
if (create_index)
|
|
|
|
{
|
2015-10-23 12:09:21 +00:00
|
|
|
int ret = create_disk_index(filename);
|
2015-10-21 05:56:03 +00:00
|
|
|
int ret_posix = (ret >> 8) & 0x000000ff;
|
|
|
|
INFO(ret);
|
|
|
|
INFO(ret_posix);
|
|
|
|
CHECK(mapnik::util::exists(filename + ".index"));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto cache_features : {true, false})
|
|
|
|
{
|
2015-10-22 15:13:08 +00:00
|
|
|
params["cache_features"] = cache_features;
|
2015-10-21 05:56:03 +00:00
|
|
|
auto ds = mapnik::datasource_cache::instance().create(params);
|
2015-10-21 16:15:07 +00:00
|
|
|
CHECK(ds->get_geometry_type() == mapnik::datasource_geometry_t::Point);
|
2015-10-21 05:56:03 +00:00
|
|
|
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 feature = features->next();
|
|
|
|
REQUIRE(feature != nullptr);
|
2022-01-26 22:25:53 +00:00
|
|
|
REQUIRE(feature->envelope() == mapnik::box2d<double>(123, 456, 123, 456));
|
2015-10-21 05:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
if (create_index && mapnik::util::exists(filename + ".index"))
|
2015-10-20 11:04:32 +00:00
|
|
|
{
|
2015-10-23 17:39:55 +00:00
|
|
|
mapnik::util::remove(filename + ".index");
|
2015-10-20 11:04:32 +00:00
|
|
|
}
|
2020-05-07 10:35:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
for (auto create_index : {true, false})
|
2020-05-07 10:35:53 +00:00
|
|
|
{
|
|
|
|
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"));
|
|
|
|
}
|
2015-10-21 05:56:03 +00:00
|
|
|
|
2020-05-07 10:35:53 +00:00
|
|
|
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);
|
2022-01-26 22:25:53 +00:00
|
|
|
REQUIRE(feature1->envelope() == mapnik::box2d<double>(-122.0, 48.0, -122.0, 48.0));
|
2020-05-07 10:35:53 +00:00
|
|
|
auto feature2 = features->next();
|
|
|
|
REQUIRE(feature2 != nullptr);
|
2022-01-26 22:25:53 +00:00
|
|
|
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));
|
2020-05-07 10:35:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
if (create_index && mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
|
|
|
mapnik::util::remove(filename + ".index");
|
|
|
|
}
|
2015-07-17 15:43:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-06 11:48:32 +00:00
|
|
|
SECTION("GeoJSON ensure mapnik::datasource_cache::instance().create() throws on malformed input")
|
|
|
|
{
|
|
|
|
mapnik::parameters params;
|
|
|
|
params["type"] = "geojson";
|
|
|
|
|
|
|
|
for (auto const& c_str : {"./test/data/json/feature-malformed-1.geojson",
|
2022-01-26 22:25:53 +00:00
|
|
|
"./test/data/json/feature-malformed-2.geojson",
|
|
|
|
"./test/data/json/feature-malformed-3.geojson"})
|
2015-11-06 11:48:32 +00:00
|
|
|
{
|
|
|
|
std::string filename(c_str);
|
2015-11-10 11:37:48 +00:00
|
|
|
params["file"] = filename;
|
2015-11-06 11:48:32 +00:00
|
|
|
|
|
|
|
// cleanup in the case of a failed previous run
|
|
|
|
if (mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
|
|
|
mapnik::util::remove(filename + ".index");
|
|
|
|
}
|
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
for (auto create_index : {true, false})
|
2015-11-06 11:48:32 +00:00
|
|
|
{
|
|
|
|
if (create_index)
|
|
|
|
{
|
|
|
|
CHECK(!mapnik::util::exists(filename + ".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})
|
|
|
|
{
|
2015-11-10 11:37:48 +00:00
|
|
|
params["cache_features"] = cache_features;
|
2015-11-06 11:48:32 +00:00
|
|
|
CHECK_THROWS(mapnik::datasource_cache::instance().create(params));
|
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
if (create_index && mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
|
|
|
mapnik::util::remove(filename + ".index");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-10 11:37:48 +00:00
|
|
|
SECTION("GeoJSON ensure mapnik::featureset::next() throws on malformed input")
|
|
|
|
{
|
|
|
|
std::string filename{"./test/data/json/featurecollection-malformed.json"};
|
|
|
|
mapnik::parameters params;
|
|
|
|
params["type"] = "geojson";
|
|
|
|
params["file"] = filename;
|
|
|
|
|
|
|
|
// cleanup in the case of a failed previous run
|
|
|
|
if (mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
|
|
|
mapnik::util::remove(filename + ".index");
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(!mapnik::util::exists(filename + ".index"));
|
|
|
|
int ret = create_disk_index(filename);
|
|
|
|
int ret_posix = (ret >> 8) & 0x000000ff;
|
|
|
|
INFO(ret);
|
|
|
|
INFO(ret_posix);
|
|
|
|
CHECK(mapnik::util::exists(filename + ".index"));
|
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
for (auto cache_features : {true, false})
|
2015-11-10 11:37:48 +00:00
|
|
|
{
|
2015-11-25 12:46:21 +00:00
|
|
|
params["cache_features"] = cache_features;
|
2015-11-10 11:37:48 +00:00
|
|
|
auto ds = mapnik::datasource_cache::instance().create(params);
|
|
|
|
auto fields = ds->get_descriptor().get_descriptors();
|
|
|
|
mapnik::query query(ds->envelope());
|
|
|
|
auto features = ds->features(query);
|
2020-09-10 14:34:52 +00:00
|
|
|
REQUIRE_THROWS(iterate_over_features(features));
|
2015-11-10 11:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
if (mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
|
|
|
mapnik::util::remove(filename + ".index");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-20 11:04:32 +00:00
|
|
|
SECTION("GeoJSON ensure input fully consumed and throw exception otherwise")
|
2015-07-17 15:43:04 +00:00
|
|
|
{
|
|
|
|
mapnik::parameters params;
|
|
|
|
params["type"] = "geojson";
|
2015-11-06 11:48:32 +00:00
|
|
|
|
2015-10-21 05:56:03 +00:00
|
|
|
std::string filename("./test/data/json/points-malformed.geojson");
|
|
|
|
params["file"] = filename; // mismatched parentheses
|
|
|
|
|
|
|
|
// cleanup in the case of a failed previous run
|
|
|
|
if (mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
2015-10-23 17:39:55 +00:00
|
|
|
mapnik::util::remove(filename + ".index");
|
2015-10-21 05:56:03 +00:00
|
|
|
}
|
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
for (auto create_index : {true, false})
|
2015-07-17 15:43:04 +00:00
|
|
|
{
|
2015-10-21 05:56:03 +00:00
|
|
|
if (create_index)
|
|
|
|
{
|
|
|
|
CHECK(!mapnik::util::exists(filename + ".index"));
|
2015-10-23 12:09:21 +00:00
|
|
|
int ret = create_disk_index(filename);
|
2015-10-21 05:56:03 +00:00
|
|
|
int ret_posix = (ret >> 8) & 0x000000ff;
|
|
|
|
INFO(ret);
|
|
|
|
INFO(ret_posix);
|
|
|
|
CHECK(mapnik::util::exists(filename + ".index"));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto cache_features : {true, false})
|
|
|
|
{
|
2015-10-22 17:28:31 +00:00
|
|
|
// unfortunately when using an index or not
|
|
|
|
// caching features we use the bbox grammar
|
|
|
|
// which is not strict (and would be a perf hit if it were strict).
|
|
|
|
// So this is one known hole where invalid data may silently parse okay
|
|
|
|
// refs https://github.com/mapnik/mapnik/issues/3125
|
|
|
|
if (!create_index && cache_features == true)
|
2015-10-22 15:19:39 +00:00
|
|
|
{
|
|
|
|
std::stringstream msg;
|
|
|
|
msg << "testcase: create index " << create_index << " cache_features " << cache_features;
|
|
|
|
params["cache_features"] = cache_features;
|
|
|
|
INFO(msg.str());
|
|
|
|
CHECK_THROWS(mapnik::datasource_cache::instance().create(params));
|
|
|
|
}
|
2015-10-21 05:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
if (create_index && mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
2015-10-23 17:39:55 +00:00
|
|
|
mapnik::util::remove(filename + ".index");
|
2015-10-21 05:56:03 +00:00
|
|
|
}
|
2015-07-17 15:43:04 +00:00
|
|
|
}
|
2015-10-14 10:41:14 +00:00
|
|
|
}
|
2015-11-25 12:46:21 +00:00
|
|
|
|
|
|
|
SECTION("GeoJSON ensure original feature ordering is preserved")
|
|
|
|
{
|
|
|
|
mapnik::parameters params;
|
|
|
|
params["type"] = "geojson";
|
|
|
|
|
|
|
|
std::string filename("./test/data/json/ordered.json");
|
|
|
|
params["file"] = filename;
|
|
|
|
|
|
|
|
// cleanup in the case of a failed previous run
|
|
|
|
if (mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
|
|
|
mapnik::util::remove(filename + ".index");
|
|
|
|
}
|
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
for (auto create_index : {true, false})
|
2015-11-25 12:46:21 +00:00
|
|
|
{
|
|
|
|
if (create_index)
|
|
|
|
{
|
|
|
|
CHECK(!mapnik::util::exists(filename + ".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);
|
|
|
|
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 feature = features->next();
|
|
|
|
mapnik::value_integer count = 0;
|
|
|
|
while (feature != nullptr)
|
|
|
|
{
|
|
|
|
// ids are in ascending order, starting from 1
|
2022-01-26 22:25:53 +00:00
|
|
|
mapnik::value val = feature->get("id");
|
2015-11-25 12:46:21 +00:00
|
|
|
REQUIRE(val.get<mapnik::value_integer>() == ++count);
|
|
|
|
feature = features->next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// cleanup
|
|
|
|
if (create_index && mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
|
|
|
mapnik::util::remove(filename + ".index");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-15 16:37:30 +00:00
|
|
|
|
|
|
|
SECTION("GeoJSON descriptor returns all field names")
|
|
|
|
{
|
|
|
|
mapnik::parameters params;
|
|
|
|
params["type"] = "geojson";
|
|
|
|
|
|
|
|
std::string filename("./test/data/json/featurecollection-multipleprops.geojson");
|
|
|
|
params["file"] = filename;
|
|
|
|
|
|
|
|
// cleanup in the case of a failed previous run
|
|
|
|
if (mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
|
|
|
mapnik::util::remove(filename + ".index");
|
|
|
|
}
|
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
for (auto create_index : {true, false})
|
2016-01-15 16:37:30 +00:00
|
|
|
{
|
|
|
|
if (create_index)
|
|
|
|
{
|
|
|
|
CHECK(!mapnik::util::exists(filename + ".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);
|
|
|
|
REQUIRE(bool(ds));
|
|
|
|
auto fields = ds->get_descriptor().get_descriptors();
|
2016-02-25 14:30:36 +00:00
|
|
|
std::initializer_list<std::string> names = {"one", "two"};
|
|
|
|
REQUIRE_FIELD_NAMES(fields, names);
|
2016-01-15 16:37:30 +00:00
|
|
|
}
|
|
|
|
// cleanup
|
|
|
|
if (create_index && mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
|
|
|
mapnik::util::remove(filename + ".index");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-05 16:17:08 +00:00
|
|
|
|
|
|
|
SECTION("GeoJSON properties are properly expressed")
|
|
|
|
{
|
2016-05-24 10:16:48 +00:00
|
|
|
mapnik::transcoder tr("utf8");
|
2016-05-05 16:17:08 +00:00
|
|
|
mapnik::parameters params;
|
|
|
|
params["type"] = "geojson";
|
|
|
|
|
|
|
|
std::string filename("./test/data/json/escaped.geojson");
|
|
|
|
params["file"] = filename;
|
|
|
|
|
|
|
|
// cleanup in the case of a failed previous run
|
|
|
|
if (mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
|
|
|
mapnik::util::remove(filename + ".index");
|
|
|
|
}
|
|
|
|
|
2022-01-26 22:25:53 +00:00
|
|
|
for (auto create_index : {true, false})
|
2016-05-05 16:17:08 +00:00
|
|
|
{
|
|
|
|
if (create_index)
|
|
|
|
{
|
|
|
|
CHECK(!mapnik::util::exists(filename + ".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);
|
|
|
|
REQUIRE(bool(ds));
|
|
|
|
auto fields = ds->get_descriptor().get_descriptors();
|
2022-01-26 22:25:53 +00:00
|
|
|
std::initializer_list<std::string> names = {"NOM_FR",
|
|
|
|
"array",
|
|
|
|
"boolean",
|
|
|
|
"description",
|
|
|
|
"double",
|
|
|
|
"empty_array",
|
|
|
|
"empty_object",
|
|
|
|
"int",
|
|
|
|
"name",
|
|
|
|
"object",
|
|
|
|
"spaces"};
|
2016-05-05 16:17:08 +00:00
|
|
|
REQUIRE_FIELD_NAMES(fields, names);
|
2016-05-06 14:44:18 +00:00
|
|
|
|
2016-05-05 16:17:08 +00:00
|
|
|
auto fs = all_features(ds);
|
|
|
|
std::initializer_list<attr> attrs = {
|
2022-01-26 22:25:53 +00:00
|
|
|
attr{"name", tr.transcode("Test")},
|
|
|
|
attr{"NOM_FR", tr.transcode("Québec")},
|
|
|
|
attr{"boolean", mapnik::value_bool(true)},
|
|
|
|
attr{"description", tr.transcode("Test: \u005C")},
|
|
|
|
attr{"double", mapnik::value_double(1.1)},
|
|
|
|
attr{"int", mapnik::value_integer(1)},
|
|
|
|
attr{"object",
|
|
|
|
tr.transcode(
|
|
|
|
"{\"name\":\"waka\",\"spaces\":\"value with "
|
|
|
|
"spaces\",\"int\":1,\"double\":1.1,\"boolean\":false"
|
|
|
|
",\"NOM_FR\":\"Québec\",\"array\":[\"string\",\"value with spaces\",3,1.1,null,true"
|
|
|
|
",\"Québec\"],\"another_object\":{\"name\":\"nested object\"}}")},
|
|
|
|
attr{"spaces", tr.transcode("this has spaces")},
|
|
|
|
attr{"array",
|
|
|
|
tr.transcode("[\"string\",\"value with spaces\",3,1.1,null,true,"
|
|
|
|
"\"Québec\",{\"name\":\"object within an array\"},"
|
|
|
|
"[\"array\",\"within\",\"an\",\"array\"]]")},
|
|
|
|
attr{"empty_array", tr.transcode("[]")},
|
|
|
|
attr{"empty_object", tr.transcode("{}")},
|
2016-05-05 16:17:08 +00:00
|
|
|
};
|
|
|
|
auto feature = fs->next();
|
|
|
|
REQUIRE(bool(feature));
|
|
|
|
REQUIRE_ATTRIBUTES(feature, attrs);
|
|
|
|
}
|
|
|
|
// cleanup
|
|
|
|
if (create_index && mapnik::util::exists(filename + ".index"))
|
|
|
|
{
|
|
|
|
mapnik::util::remove(filename + ".index");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-10 19:34:18 +00:00
|
|
|
}
|
2015-07-10 09:05:48 +00:00
|
|
|
}
|