osrm-backend/test/t/geom/test_ogr_wkb.cpp
Patrick Niklaus 6eb4f090f9 Squashed 'third_party/libosmium/' content from commit ce865381f
git-subtree-dir: third_party/libosmium
git-subtree-split: ce865381fb752323ff1e66181f5a49b7f500ffa3
2017-08-30 09:30:27 +00:00

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