d5ecf4d Release v2.10.2 7c04564 Update embedded protozero to version 1.4.4. e209d81 Write code for 64bit systems, so it compiles on 32bit w/o warning. 640217c Fix buffer overflow. 8b4620f Release v2.10.1 38bf3ab Update protozero to 1.4.3. f81b3c6 Fix IdSet on 32 bit. 5ff4753 Workaround so the test works on 32bit systems. 7542694 Include our endian.hpp before using the endianness test macros. git-subtree-dir: third_party/libosmium git-subtree-split: d5ecf4df90e2995c816886d2a002c3d3de7062ee
102 lines
3.7 KiB
C++
102 lines
3.7 KiB
C++
|
|
#include "catch.hpp"
|
|
|
|
#include <memory>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
#include <osmium/geom/ogr.hpp>
|
|
#include <osmium/geom/wkb.hpp>
|
|
#include <osmium/util/endian.hpp>
|
|
|
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
|
#include "area_helper.hpp"
|
|
#include "wnl_helper.hpp"
|
|
|
|
std::string to_wkb(const OGRGeometry* geometry) {
|
|
std::string buffer;
|
|
buffer.resize(geometry->WkbSize());
|
|
|
|
geometry->exportToWkb(wkbNDR, const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(buffer.data())));
|
|
|
|
return buffer;
|
|
}
|
|
|
|
TEST_CASE("compare WKB point against GDAL/OGR") {
|
|
osmium::geom::WKBFactory<> wkb_factory{osmium::geom::wkb_type::wkb};
|
|
osmium::geom::OGRFactory<> ogr_factory;
|
|
|
|
osmium::Location loc{3.2, 4.2};
|
|
const std::string wkb{wkb_factory.create_point(loc)};
|
|
const std::unique_ptr<OGRPoint> geometry = ogr_factory.create_point(loc);
|
|
REQUIRE(to_wkb(geometry.get()) == wkb);
|
|
}
|
|
|
|
TEST_CASE("compare WKB linestring against GDAL/OGR") {
|
|
osmium::geom::WKBFactory<> wkb_factory{osmium::geom::wkb_type::wkb};
|
|
osmium::geom::OGRFactory<> ogr_factory;
|
|
osmium::memory::Buffer buffer{10000};
|
|
|
|
const auto& wnl = create_test_wnl_okay(buffer);
|
|
|
|
SECTION("linestring") {
|
|
const std::string wkb{wkb_factory.create_linestring(wnl)};
|
|
const std::unique_ptr<OGRLineString> geometry = ogr_factory.create_linestring(wnl);
|
|
REQUIRE(to_wkb(geometry.get()) == wkb);
|
|
}
|
|
|
|
SECTION("linestring, unique nodes, backwards") {
|
|
const std::string wkb{wkb_factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
|
|
const std::unique_ptr<OGRLineString> geometry = ogr_factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward);
|
|
REQUIRE(to_wkb(geometry.get()) == wkb);
|
|
}
|
|
|
|
SECTION("linestring, all nodes, forwards") {
|
|
const std::string wkb{wkb_factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
|
|
const std::unique_ptr<OGRLineString> geometry = ogr_factory.create_linestring(wnl, osmium::geom::use_nodes::all);
|
|
REQUIRE(to_wkb(geometry.get()) == wkb);
|
|
}
|
|
|
|
SECTION("linestring, all nodes, backwards") {
|
|
const std::string wkb{wkb_factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
|
|
const std::unique_ptr<OGRLineString> geometry = ogr_factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward);
|
|
REQUIRE(to_wkb(geometry.get()) == wkb);
|
|
}
|
|
|
|
}
|
|
|
|
TEST_CASE("compare WKB area against GDAL/OGR") {
|
|
osmium::geom::WKBFactory<> wkb_factory{osmium::geom::wkb_type::wkb};
|
|
osmium::geom::OGRFactory<> ogr_factory;
|
|
osmium::memory::Buffer buffer{10000};
|
|
|
|
SECTION("area_1outer_0inner") {
|
|
const osmium::Area& area = create_test_area_1outer_0inner(buffer);
|
|
|
|
const std::string wkb{wkb_factory.create_multipolygon(area)};
|
|
const std::unique_ptr<OGRMultiPolygon> geometry = ogr_factory.create_multipolygon(area);
|
|
REQUIRE(to_wkb(geometry.get()) == wkb);
|
|
}
|
|
|
|
SECTION("area_1outer_1inner") {
|
|
const osmium::Area& area = create_test_area_1outer_1inner(buffer);
|
|
|
|
const std::string wkb{wkb_factory.create_multipolygon(area)};
|
|
const std::unique_ptr<OGRMultiPolygon> geometry = ogr_factory.create_multipolygon(area);
|
|
REQUIRE(to_wkb(geometry.get()) == wkb);
|
|
}
|
|
|
|
SECTION("area_2outer_2inner") {
|
|
const osmium::Area& area = create_test_area_2outer_2inner(buffer);
|
|
|
|
const std::string wkb{wkb_factory.create_multipolygon(area)};
|
|
const std::unique_ptr<OGRMultiPolygon> geometry = ogr_factory.create_multipolygon(area);
|
|
REQUIRE(to_wkb(geometry.get()) == wkb);
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|