Merge commit '73efcc6b0ccedf8c1b6d95abdba8340cc9adf100' as 'third_party/libosmium'

This commit is contained in:
Dennis Luxen
2015-01-13 16:54:25 +01:00
235 changed files with 53733 additions and 0 deletions
+123
View File
@@ -0,0 +1,123 @@
message(STATUS "Configuring unit tests...")
set(DART_TESTING_TIMEOUT 60)
include(Dart)
include_directories(include)
# In 'Dev' mode: compile with very strict warnings and turn them into errors.
if(CMAKE_BUILD_TYPE STREQUAL "Dev")
add_definitions(-Werror ${OSMIUM_WARNING_OPTIONS} -Wno-unused-variable)
endif()
add_library(testlib STATIC test_main.cpp)
#----------------------------------------------------------------------
set(ALL_TESTS "")
# call with parameters:
# TGROUP - test group (directory)
# TNAME - name of test
# ARGV2 - flag to enable test (optional)
# ARGV3 - libraries to add (optional)
function(add_unit_test TGROUP TNAME)
set(ALL_TESTS "${ALL_TESTS};${TGROUP}/${TNAME}" PARENT_SCOPE)
if((${ARGC} EQUAL 2) OR (${ARGV2}))
if(Osmium_DEBUG)
message("Adding test ${TGROUP}/${TNAME}")
endif()
set(TESTNAME "${TGROUP}_${TNAME}")
add_executable(${TESTNAME} t/${TGROUP}/${TNAME}.cpp)
target_link_libraries(${TESTNAME} testlib)
if((${ARGV2}) AND (DEFINED ARGV3))
if(Osmium_DEBUG)
message(" Adding libs ${ARGV3}")
endif()
target_link_libraries(${TESTNAME} ${ARGV3})
endif()
add_test(NAME ${TESTNAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${TESTNAME}
)
set_tests_properties(${TESTNAME} PROPERTIES LABELS "unit;${TGROUP}")
else()
message("Skipped test ${TGROUP}/${TNAME} because a dependency was not found")
set(OSMIUM_SKIPPED_TESTS
"${OSMIUM_SKIPPED_TESTS} ${TGROUP}/${TNAME}"
CACHE STRING "Tests that were skipped because of missing dependecies")
endif()
endfunction()
#----------------------------------------------------------------------
#
# Add all tests.
#
#----------------------------------------------------------------------
add_unit_test(area test_area_id)
add_unit_test(area test_node_ref_segment)
add_unit_test(basic test_box)
add_unit_test(basic test_changeset)
add_unit_test(basic test_entity_bits)
add_unit_test(basic test_location)
add_unit_test(basic test_node)
add_unit_test(basic test_node_ref)
add_unit_test(basic test_object_comparisons)
add_unit_test(basic test_relation)
add_unit_test(basic test_timestamp)
add_unit_test(basic test_way)
add_unit_test(buffer test_buffer_node)
add_unit_test(buffer test_buffer_purge)
if (GEOS_FOUND AND PROJ_FOUND)
set(GEOS_AND_PROJ_FOUND TRUE)
else()
set(GEOS_AND_PROJ_FOUND FALSE)
endif()
add_unit_test(geom test_factory_with_projection
${GEOS_AND_PROJ_FOUND}
"${GEOS_LIBRARY};${PROJ_LIBRARY}")
add_unit_test(geom test_geojson)
add_unit_test(geom test_geos ${GEOS_FOUND} ${GEOS_LIBRARY})
add_unit_test(geom test_geos_wkb ${GEOS_FOUND} ${GEOS_LIBRARY})
add_unit_test(geom test_mercator)
add_unit_test(geom test_ogr ${GDAL_FOUND} ${GDAL_LIBRARY})
add_unit_test(geom test_projection ${PROJ_FOUND} ${PROJ_LIBRARY})
add_unit_test(geom test_wkb)
add_unit_test(geom test_wkt)
add_unit_test(index test_id_to_location ${SPARSEHASH_FOUND})
add_unit_test(index test_typed_mmap)
add_unit_test(io test_bzip2 ${BZIP2_FOUND} ${BZIP2_LIBRARIES})
add_unit_test(io test_file_formats)
add_unit_test(io test_reader TRUE "${OSMIUM_XML_LIBRARIES}")
add_unit_test(tags test_filter)
add_unit_test(tags test_operators)
add_unit_test(tags test_tag_list)
add_unit_test(util test_double)
add_unit_test(util test_options)
add_unit_test(util test_string)
#----------------------------------------------------------------------
#
# Check that all tests available in test/t/*/test_*.cpp are run.
#
#----------------------------------------------------------------------
file(GLOB TESTS_IN_DIR RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/t" t/*/test_*.cpp)
foreach(file ${TESTS_IN_DIR})
string(REPLACE ".cpp" "" out1 ${file})
string(REPLACE "//" "/" tname ${out1})
list(FIND ALL_TESTS ${tname} found)
if(${found} EQUAL -1)
message(WARNING "Test '${tname}' not found in cmake config. It will not be run!")
endif()
endforeach()
+12
View File
@@ -0,0 +1,12 @@
Osmium uses Catch (https://github.com/philsquared/Catch/) for its unit tests.
Only one header file is needed (catch.hpp) which can be downloaded from
http://builds.catch-lib.net/ and put into the include directory.
Osmium needs a few changes to catch.hpp, they were patched in. To be able to
compare with the original version, it is stored in include/catch_orig.hpp.
Changes are:
* CATCH_CONFIG_CPP11_NULLPTR must be set for MSVC
* Problem with test running in loop: https://github.com/philsquared/Catch/issues/271
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+42
View File
@@ -0,0 +1,42 @@
/*
* mkstemp.c
*
* Provides a trivial replacement for the POSIX `mkstemp()' function,
* suitable for use in MinGW (Win32) applications.
*
* This file is part of the MinGW32 package set.
*
* Contributed by Keith Marshall <keithmarshall@users.sourceforge.net>
* Patched to VS2013 by alex85k
* THIS SOFTWARE IS NOT COPYRIGHTED
*
* This source code is offered for use in the public domain. You may
* use, modify or distribute it freely.
*
* This code is distributed in the hope that it will be useful but
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
* DISCLAIMED. This includes but is not limited to warranties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef WIN_MKSTEMP_H
#define WIN_MKSTEMP_H
#include <stdio.h>
#include <fcntl.h>
#include <share.h>
inline int mkstemp( char *templ )
{
int maxtry = 26, rtn = -1;
while( maxtry-- && (rtn < 0) )
{
char *r = _mktemp( templ );
if( r == NULL )
return -1;
rtn = sopen( r, O_RDWR | O_CREAT | O_EXCL | O_BINARY, SH_DENYRW, 0600 );
}
return rtn;
}
#endif
@@ -0,0 +1 @@
multipolygon.qgs~
+87
View File
@@ -0,0 +1,87 @@
message(STATUS "Configuring osm-testdata tests...")
if(NOT GDAL_FOUND OR
NOT EXPAT_FOUND)
message("Sorry, building osm-testdata tests needs GDAL and Expat")
return()
endif()
set(DART_TESTING_TIMEOUT 300)
include(Dart)
include_directories("include")
include_directories("../include")
# In 'Dev' mode: compile with very strict warnings and turn them into errors.
if(CMAKE_BUILD_TYPE STREQUAL "Dev")
add_definitions(-Werror ${OSMIUM_WARNING_OPTIONS} -Wno-unused-variable)
endif()
get_filename_component(TESTDATA_DIR ../../../osm-testdata ABSOLUTE)
if(NOT EXISTS ${TESTDATA_DIR})
execute_process(COMMAND git clone https://github.com/osmcode/osm-testdata.git ${TESTDATA_DIR})
endif()
#----------------------------------------------------------------------
file(GLOB TESTCASE_CPPS testcases/*.cpp)
add_executable(testdata-testcases testdata-testcases.cpp ${TESTCASE_CPPS})
target_link_libraries(testdata-testcases
${OSMIUM_XML_LIBRARIES}
)
add_test(NAME testdata-testcases
COMMAND testdata-testcases
)
set_tests_properties(testdata-testcases
PROPERTIES ENVIRONMENT "TESTCASES_DIR=${TESTDATA_DIR}/grid/data")
#----------------------------------------------------------------------
add_executable(testdata-overview testdata-overview.cpp)
target_link_libraries(testdata-overview
${OSMIUM_XML_LIBRARIES}
${GDAL_LIBRARIES}
)
add_test(NAME testdata-overview
COMMAND testdata-overview ${TESTDATA_DIR}/grid/data/all.osm
)
#----------------------------------------------------------------------
add_executable(testdata-xml testdata-xml.cpp)
target_link_libraries(testdata-xml
${OSMIUM_XML_LIBRARIES}
)
add_test(NAME testdata-xml
COMMAND testdata-xml
)
set_tests_properties(testdata-xml
PROPERTIES ENVIRONMENT "TESTDIR=${TESTDATA_DIR}/xml/data")
#----------------------------------------------------------------------
add_executable(testdata-multipolygon testdata-multipolygon.cpp)
target_link_libraries(testdata-multipolygon
${OSMIUM_XML_LIBRARIES}
${GDAL_LIBRARIES}
)
if(WIN32)
set(MULTIPOLYGON_TEST_SCRIPT "run-testdata-multipolygon.bat")
else()
set(MULTIPOLYGON_TEST_SCRIPT "run-testdata-multipolygon.sh")
endif()
if(MSVC)
set(EXE_DIR ${CMAKE_BUILD_TYPE})
else()
set(EXE_DIR .)
endif()
add_test(NAME testdata-multipolygon
COMMAND ${CMAKE_SOURCE_DIR}/test/osm-testdata/${MULTIPOLYGON_TEST_SCRIPT}
${TESTDATA_DIR}
${EXE_DIR}
)
#----------------------------------------------------------------------
+23
View File
@@ -0,0 +1,23 @@
# OSM Testdata
This directory contains software that can be used with the osm-testdata
repository at https://github.com/osmcode/osm-testdata . To use it, clone
the `osm-testdata` repository in the same directory where you cloned the
`libosmium` repository.
## Overview
The `testdata-overview` program can be used to create a Spatialite file
containing all the nodes and ways from the test data files.
Compile it by running `make testdata-overview`, run it my calling
`make overview`.
## Running the Tests
Actual tests are in `testcases` subdirectory, one per test from the
osm-testdata repository.
To compile the tests, call `make runtests`, to run them call
`make test`.
@@ -0,0 +1,92 @@
#ifndef CHECK_BASICS_HANDLER_HPP
#define CHECK_BASICS_HANDLER_HPP
#include <iostream>
#include <unordered_set>
#include <osmium/handler.hpp>
#include <osmium/osm.hpp>
/**
* Check some basics of the input data:
*
* 1. Correct number of nodes, ways, and relations
* 2. Correct ID space used by nodes, ways, and relations
* 3. No ID used more than once
*/
class CheckBasicsHandler : public osmium::handler::Handler {
// Lower bound for the id range allowed in this test.
int m_id_range;
// In the beginning these contains the number of nodes, ways, and relations
// supposedly in the data.osm file. They will be decremented on each object
// and have to be 0 at the end.
int m_num_nodes;
int m_num_ways;
int m_num_relations;
// All IDs encountered in the data.osm file will be stored in this set and
// checked for duplicates.
std::unordered_set<osmium::object_id_type> m_ids;
// Check id is in range [min, max] and that it isn't more than once in input.
void id_check(osmium::object_id_type id, osmium::object_id_type min, osmium::object_id_type max) {
if (id < m_id_range + min || id > m_id_range + max) {
std::cerr << " id " << id << " out of range for this test case\n";
exit(1);
}
auto r = m_ids.insert(id);
if (!r.second) {
std::cerr << " id " << id << " contained twice in data.osm\n";
exit(1);
}
}
public:
static const int ids_per_testcase = 1000;
CheckBasicsHandler(int testcase, int nodes, int ways, int relations) :
osmium::handler::Handler(),
m_id_range(testcase * ids_per_testcase),
m_num_nodes(nodes),
m_num_ways(ways),
m_num_relations(relations) {
}
~CheckBasicsHandler() {
if (m_num_nodes != 0) {
std::cerr << " wrong number of nodes in data.osm\n";
exit(1);
}
if (m_num_ways != 0) {
std::cerr << " wrong number of ways in data.osm\n";
exit(1);
}
if (m_num_relations != 0) {
std::cerr << " wrong number of relations in data.osm\n";
exit(1);
}
}
void node(const osmium::Node& node) {
id_check(node.id(), 0, 799);
--m_num_nodes;
}
void way(const osmium::Way& way) {
id_check(way.id(), 800, 899);
--m_num_ways;
}
void relations(const osmium::Relation& relation) {
id_check(relation.id(), 900, 999);
--m_num_relations;
}
}; // CheckBasicsHandler
#endif // CHECK_BASICS_HANDLER_HPP
@@ -0,0 +1,86 @@
#ifndef CHECK_WKT_HANDLER_HPP
#define CHECK_WKT_HANDLER_HPP
#include <cassert>
#include <fstream>
#include <map>
#include <sstream>
#include <string>
#include <osmium/handler.hpp>
#include <osmium/osm.hpp>
#include <osmium/osm/types.hpp>
class CheckWKTHandler : public osmium::handler::Handler {
std::map<osmium::object_id_type, std::string> m_geometries;
osmium::geom::WKTFactory<> m_factory;
void read_wkt_file(const std::string& filename) {
std::ifstream in(filename, std::ifstream::in);
if (in) {
osmium::object_id_type id;
std::string line;
while (std::getline(in, line)) {
size_t pos = line.find_first_of(' ');
if (pos == std::string::npos) {
std::cerr << filename << " not formatted correctly\n";
exit(1);
}
std::string id_str = line.substr(0, pos);
std::istringstream iss(id_str);
iss >> id;
if (m_geometries.find(id) != m_geometries.end()) {
std::cerr << filename + " contains id " << id << "twice\n";
exit(1);
}
m_geometries[id] = line.substr(pos+1);
}
}
}
public:
CheckWKTHandler(const std::string& dirname, int test_id) :
osmium::handler::Handler() {
std::string filename = dirname + "/" + std::to_string(test_id / 100) + "/" + std::to_string(test_id) + "/";
read_wkt_file(filename + "nodes.wkt");
read_wkt_file(filename + "ways.wkt");
}
~CheckWKTHandler() {
if (!m_geometries.empty()) {
for (const auto& geom : m_geometries) {
std::cerr << "geometry id " << geom.first << " not in data.osm.\n";
}
exit(1);
}
}
void node(const osmium::Node& node) {
const std::string wkt = m_geometries[node.id()];
assert(wkt != "" && "Missing geometry for node in nodes.wkt");
std::string this_wkt = m_factory.create_point(node.location());
assert(wkt == this_wkt && "wkt geometries don't match");
m_geometries.erase(node.id());
}
void way(const osmium::Way& way) {
const std::string wkt = m_geometries[way.id()];
assert(wkt != "" && "Missing geometry for way in ways.wkt");
std::string this_wkt = m_factory.create_linestring(way);
assert(wkt == this_wkt && "wkt geometries don't match");
m_geometries.erase(way.id());
}
}; // CheckWKTHandler
#endif // CHECK_WKT_HANDLER_HPP
@@ -0,0 +1,21 @@
#ifndef COMMON_HPP
#define COMMON_HPP
#include <osmium/geom/wkt.hpp>
#include <osmium/handler.hpp>
#include <osmium/handler/node_locations_for_ways.hpp>
#include <osmium/index/map/dummy.hpp>
#include <osmium/index/map/stl_vector.hpp>
#include <osmium/io/xml_input.hpp>
#include <osmium/visitor.hpp>
typedef osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location> index_neg_type;
typedef osmium::index::map::SparseMapMem<osmium::unsigned_object_id_type, osmium::Location> index_pos_type;
typedef osmium::handler::NodeLocationsForWays<index_pos_type, index_neg_type> location_handler_type;
#include "check_basics_handler.hpp"
#include "check_wkt_handler.hpp"
#include "testdata-testcases.hpp"
#endif // COMMON_HPP
@@ -0,0 +1,10 @@
#ifndef TESTDATA_TESTCASES_HPP
#define TESTDATA_TESTCASES_HPP
#include <catch.hpp>
#include <string>
extern std::string dirname;
#endif // TESTDATA_TESTCASES_HPP
+880
View File
@@ -0,0 +1,880 @@
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis projectname="" version="2.2.0-Valmiera">
<title></title>
<relations/>
<mapcanvas>
<units>degrees</units>
<extent>
<xmin>0.77500024999999972</xmin>
<ymin>-0.84791712574962541</ymin>
<xmax>10.22498975000000065</xmax>
<ymax>3.94791712574962572</ymax>
</extent>
<projections>0</projections>
<destinationsrs>
<spatialrefsys>
<proj4>+proj=longlat +datum=WGS84 +no_defs</proj4>
<srsid>3452</srsid>
<srid>4326</srid>
<authid>EPSG:4326</authid>
<description>WGS 84</description>
<projectionacronym>longlat</projectionacronym>
<ellipsoidacronym>WGS84</ellipsoidacronym>
<geographicflag>true</geographicflag>
</spatialrefsys>
</destinationsrs>
<layer_coordinate_transform_info/>
</mapcanvas>
<legend updateDrawingOrder="true">
<legendlayer drawingOrder="-1" open="true" checked="Qt::Checked" name="Error Points" showFeatureCount="0">
<filegroup open="true" hidden="false">
<legendlayerfile isInOverview="0" layerid="perrors20140228163658956" visible="1"/>
</filegroup>
</legendlayer>
<legendlayer drawingOrder="-1" open="true" checked="Qt::Checked" name="Error Lines" showFeatureCount="0">
<filegroup open="true" hidden="false">
<legendlayerfile isInOverview="0" layerid="lerrors20140228172357933" visible="1"/>
</filegroup>
</legendlayer>
<legendlayer drawingOrder="-1" open="true" checked="Qt::Checked" name="multipolygons" showFeatureCount="0">
<filegroup open="true" hidden="false">
<legendlayerfile isInOverview="0" layerid="multipolygons20140221151811742" visible="1"/>
</filegroup>
</legendlayer>
<legendgroup embedded="1" drawingOrder="-1" open="true" checked="Qt::Checked" name="Overview" project="../../../osm-testdata/grid/tests.qgs"/>
<legendgroup embedded="1" drawingOrder="-1" open="true" checked="Qt::Checked" name="Test Framework" project="../../../osm-testdata/grid/tests.qgs"/>
</legend>
<projectlayers layercount="9">
<maplayer minimumScale="-4.65661e-10" maximumScale="1e+08" simplifyDrawingHints="1" minLabelScale="0" maxLabelScale="1e+08" simplifyDrawingTol="1" geometry="Line" simplifyMaxScale="1" type="vector" hasScaleBasedVisibilityFlag="0" simplifyLocal="1" scaleBasedLabelVisibilityFlag="0">
<id>lerrors20140228172357933</id>
<datasource>dbname='./multipolygon.db' table="lerrors" (GEOMETRY) sql=</datasource>
<title></title>
<abstract></abstract>
<keywordList>
<value></value>
</keywordList>
<layername>Error Lines</layername>
<srs>
<spatialrefsys>
<proj4>+proj=longlat +datum=WGS84 +no_defs</proj4>
<srsid>3452</srsid>
<srid>4326</srid>
<authid>EPSG:4326</authid>
<description>WGS 84</description>
<projectionacronym>longlat</projectionacronym>
<ellipsoidacronym>WGS84</ellipsoidacronym>
<geographicflag>true</geographicflag>
</spatialrefsys>
</srs>
<provider encoding="System">spatialite</provider>
<previewExpression>COALESCE( "OGC_FID", '&lt;NULL>' )</previewExpression>
<vectorjoins/>
<renderer-v2 attr="problem_type" symbollevels="0" type="categorizedSymbol">
<categories>
<category symbol="0" value="intersection" label="intersection"/>
<category symbol="1" value="role_should_be_outer" label="role_should_be_outer"/>
<category symbol="2" value="role_should_be_inner" label="role_should_be_inner"/>
<category symbol="3" value="" label=""/>
</categories>
<symbols>
<symbol alpha="1" type="line" name="0">
<layer pass="0" class="SimpleLine" locked="0">
<prop k="capstyle" v="square"/>
<prop k="color" v="255,0,0,255"/>
<prop k="customdash" v="5;2"/>
<prop k="customdash_unit" v="MM"/>
<prop k="draw_inside_polygon" v="0"/>
<prop k="joinstyle" v="bevel"/>
<prop k="offset" v="0"/>
<prop k="offset_unit" v="MM"/>
<prop k="penstyle" v="solid"/>
<prop k="use_custom_dash" v="0"/>
<prop k="width" v="0.5"/>
<prop k="width_unit" v="MM"/>
</layer>
</symbol>
<symbol alpha="1" type="line" name="1">
<layer pass="0" class="SimpleLine" locked="0">
<prop k="capstyle" v="square"/>
<prop k="color" v="255,122,33,255"/>
<prop k="customdash" v="5;2"/>
<prop k="customdash_unit" v="MM"/>
<prop k="draw_inside_polygon" v="0"/>
<prop k="joinstyle" v="bevel"/>
<prop k="offset" v="0"/>
<prop k="offset_unit" v="MM"/>
<prop k="penstyle" v="solid"/>
<prop k="use_custom_dash" v="0"/>
<prop k="width" v="0.5"/>
<prop k="width_unit" v="MM"/>
</layer>
</symbol>
<symbol alpha="1" type="line" name="2">
<layer pass="0" class="SimpleLine" locked="0">
<prop k="capstyle" v="square"/>
<prop k="color" v="255,122,33,255"/>
<prop k="customdash" v="5;2"/>
<prop k="customdash_unit" v="MM"/>
<prop k="draw_inside_polygon" v="0"/>
<prop k="joinstyle" v="bevel"/>
<prop k="offset" v="0"/>
<prop k="offset_unit" v="MM"/>
<prop k="penstyle" v="dash"/>
<prop k="use_custom_dash" v="0"/>
<prop k="width" v="0.5"/>
<prop k="width_unit" v="MM"/>
</layer>
</symbol>
<symbol alpha="1" type="line" name="3">
<layer pass="0" class="SimpleLine" locked="0">
<prop k="capstyle" v="square"/>
<prop k="color" v="255,0,0,255"/>
<prop k="customdash" v="5;2"/>
<prop k="customdash_unit" v="MM"/>
<prop k="draw_inside_polygon" v="0"/>
<prop k="joinstyle" v="bevel"/>
<prop k="offset" v="0"/>
<prop k="offset_unit" v="MM"/>
<prop k="penstyle" v="solid"/>
<prop k="use_custom_dash" v="0"/>
<prop k="width" v="0.5"/>
<prop k="width_unit" v="MM"/>
</layer>
</symbol>
</symbols>
<source-symbol>
<symbol alpha="1" type="line" name="0">
<layer pass="0" class="SimpleLine" locked="0">
<prop k="capstyle" v="square"/>
<prop k="color" v="77,243,51,255"/>
<prop k="customdash" v="5;2"/>
<prop k="customdash_unit" v="MM"/>
<prop k="draw_inside_polygon" v="0"/>
<prop k="joinstyle" v="bevel"/>
<prop k="offset" v="0"/>
<prop k="offset_unit" v="MM"/>
<prop k="penstyle" v="solid"/>
<prop k="use_custom_dash" v="0"/>
<prop k="width" v="0.26"/>
<prop k="width_unit" v="MM"/>
</layer>
</symbol>
</source-symbol>
<rotation/>
<sizescale scalemethod="area"/>
</renderer-v2>
<customproperties>
<property key="labeling" value="pal"/>
<property key="labeling/addDirectionSymbol" value="false"/>
<property key="labeling/angleOffset" value="0"/>
<property key="labeling/blendMode" value="0"/>
<property key="labeling/bufferBlendMode" value="0"/>
<property key="labeling/bufferColorA" value="255"/>
<property key="labeling/bufferColorB" value="255"/>
<property key="labeling/bufferColorG" value="255"/>
<property key="labeling/bufferColorR" value="255"/>
<property key="labeling/bufferDraw" value="false"/>
<property key="labeling/bufferJoinStyle" value="64"/>
<property key="labeling/bufferNoFill" value="false"/>
<property key="labeling/bufferSize" value="1"/>
<property key="labeling/bufferSizeInMapUnits" value="false"/>
<property key="labeling/bufferTransp" value="0"/>
<property key="labeling/centroidWhole" value="false"/>
<property key="labeling/decimals" value="3"/>
<property key="labeling/displayAll" value="false"/>
<property key="labeling/dist" value="0"/>
<property key="labeling/distInMapUnits" value="false"/>
<property key="labeling/enabled" value="false"/>
<property key="labeling/fieldName" value=""/>
<property key="labeling/fontBold" value="false"/>
<property key="labeling/fontCapitals" value="0"/>
<property key="labeling/fontFamily" value="Sans"/>
<property key="labeling/fontItalic" value="false"/>
<property key="labeling/fontLetterSpacing" value="0"/>
<property key="labeling/fontLimitPixelSize" value="false"/>
<property key="labeling/fontMaxPixelSize" value="10000"/>
<property key="labeling/fontMinPixelSize" value="3"/>
<property key="labeling/fontSize" value="10"/>
<property key="labeling/fontSizeInMapUnits" value="false"/>
<property key="labeling/fontStrikeout" value="false"/>
<property key="labeling/fontUnderline" value="false"/>
<property key="labeling/fontWeight" value="50"/>
<property key="labeling/fontWordSpacing" value="0"/>
<property key="labeling/formatNumbers" value="false"/>
<property key="labeling/isExpression" value="false"/>
<property key="labeling/labelOffsetInMapUnits" value="true"/>
<property key="labeling/labelPerPart" value="false"/>
<property key="labeling/leftDirectionSymbol" value="&lt;"/>
<property key="labeling/limitNumLabels" value="false"/>
<property key="labeling/maxCurvedCharAngleIn" value="20"/>
<property key="labeling/maxCurvedCharAngleOut" value="-20"/>
<property key="labeling/maxNumLabels" value="2000"/>
<property key="labeling/mergeLines" value="false"/>
<property key="labeling/minFeatureSize" value="0"/>
<property key="labeling/multilineAlign" value="0"/>
<property key="labeling/multilineHeight" value="1"/>
<property key="labeling/namedStyle" value=""/>
<property key="labeling/obstacle" value="true"/>
<property key="labeling/placeDirectionSymbol" value="0"/>
<property key="labeling/placement" value="2"/>
<property key="labeling/placementFlags" value="10"/>
<property key="labeling/plussign" value="false"/>
<property key="labeling/preserveRotation" value="true"/>
<property key="labeling/previewBkgrdColor" value="#ffffff"/>
<property key="labeling/priority" value="5"/>
<property key="labeling/quadOffset" value="4"/>
<property key="labeling/reverseDirectionSymbol" value="false"/>
<property key="labeling/rightDirectionSymbol" value=">"/>
<property key="labeling/scaleMax" value="10000000"/>
<property key="labeling/scaleMin" value="1"/>
<property key="labeling/scaleVisibility" value="false"/>
<property key="labeling/shadowBlendMode" value="6"/>
<property key="labeling/shadowColorB" value="0"/>
<property key="labeling/shadowColorG" value="0"/>
<property key="labeling/shadowColorR" value="0"/>
<property key="labeling/shadowDraw" value="false"/>
<property key="labeling/shadowOffsetAngle" value="135"/>
<property key="labeling/shadowOffsetDist" value="1"/>
<property key="labeling/shadowOffsetGlobal" value="true"/>
<property key="labeling/shadowOffsetUnits" value="1"/>
<property key="labeling/shadowRadius" value="1.5"/>
<property key="labeling/shadowRadiusAlphaOnly" value="false"/>
<property key="labeling/shadowRadiusUnits" value="1"/>
<property key="labeling/shadowScale" value="100"/>
<property key="labeling/shadowTransparency" value="30"/>
<property key="labeling/shadowUnder" value="0"/>
<property key="labeling/shapeBlendMode" value="0"/>
<property key="labeling/shapeBorderColorA" value="255"/>
<property key="labeling/shapeBorderColorB" value="128"/>
<property key="labeling/shapeBorderColorG" value="128"/>
<property key="labeling/shapeBorderColorR" value="128"/>
<property key="labeling/shapeBorderWidth" value="0"/>
<property key="labeling/shapeBorderWidthUnits" value="1"/>
<property key="labeling/shapeDraw" value="false"/>
<property key="labeling/shapeFillColorA" value="255"/>
<property key="labeling/shapeFillColorB" value="255"/>
<property key="labeling/shapeFillColorG" value="255"/>
<property key="labeling/shapeFillColorR" value="255"/>
<property key="labeling/shapeJoinStyle" value="64"/>
<property key="labeling/shapeOffsetUnits" value="1"/>
<property key="labeling/shapeOffsetX" value="0"/>
<property key="labeling/shapeOffsetY" value="0"/>
<property key="labeling/shapeRadiiUnits" value="1"/>
<property key="labeling/shapeRadiiX" value="0"/>
<property key="labeling/shapeRadiiY" value="0"/>
<property key="labeling/shapeRotation" value="0"/>
<property key="labeling/shapeRotationType" value="0"/>
<property key="labeling/shapeSVGFile" value=""/>
<property key="labeling/shapeSizeType" value="0"/>
<property key="labeling/shapeSizeUnits" value="1"/>
<property key="labeling/shapeSizeX" value="0"/>
<property key="labeling/shapeSizeY" value="0"/>
<property key="labeling/shapeTransparency" value="0"/>
<property key="labeling/shapeType" value="0"/>
<property key="labeling/textColorA" value="255"/>
<property key="labeling/textColorB" value="0"/>
<property key="labeling/textColorG" value="0"/>
<property key="labeling/textColorR" value="0"/>
<property key="labeling/textTransp" value="0"/>
<property key="labeling/upsidedownLabels" value="0"/>
<property key="labeling/wrapChar" value=""/>
<property key="labeling/xOffset" value="0"/>
<property key="labeling/yOffset" value="0"/>
</customproperties>
<blendMode>0</blendMode>
<featureBlendMode>0</featureBlendMode>
<layerTransparency>0</layerTransparency>
<displayfield>OGC_FID</displayfield>
<label>0</label>
<labelattributes>
<label fieldname="" text="Label"/>
<family fieldname="" name="Sans"/>
<size fieldname="" units="pt" value="12"/>
<bold fieldname="" on="0"/>
<italic fieldname="" on="0"/>
<underline fieldname="" on="0"/>
<strikeout fieldname="" on="0"/>
<color fieldname="" red="0" blue="0" green="0"/>
<x fieldname=""/>
<y fieldname=""/>
<offset x="0" y="0" units="pt" yfieldname="" xfieldname=""/>
<angle fieldname="" value="0" auto="0"/>
<alignment fieldname="" value="center"/>
<buffercolor fieldname="" red="255" blue="255" green="255"/>
<buffersize fieldname="" units="pt" value="1"/>
<bufferenabled fieldname="" on=""/>
<multilineenabled fieldname="" on=""/>
<selectedonly on=""/>
</labelattributes>
<edittypes>
<edittype labelontop="0" editable="1" type="0" name="OGC_FID"/>
<edittype labelontop="0" editable="1" type="0" name="id"/>
<edittype labelontop="0" editable="1" type="0" name="object_id"/>
<edittype labelontop="0" editable="1" type="0" name="problem_type"/>
<edittype labelontop="0" editable="1" type="0" name="type"/>
<edittype labelontop="0" editable="1" type="0" name="way_id"/>
</edittypes>
<editform>.</editform>
<editforminit></editforminit>
<featformsuppress>0</featformsuppress>
<annotationform>.</annotationform>
<editorlayout>generatedlayout</editorlayout>
<excludeAttributesWMS/>
<excludeAttributesWFS/>
<attributeactions/>
</maplayer>
<maplayer minimumScale="-4.65661e-10" maximumScale="1e+08" simplifyDrawingHints="1" minLabelScale="0" maxLabelScale="1e+08" simplifyDrawingTol="1" geometry="Polygon" simplifyMaxScale="1" type="vector" hasScaleBasedVisibilityFlag="0" simplifyLocal="1" scaleBasedLabelVisibilityFlag="0">
<id>multipolygons20140221151811742</id>
<datasource>dbname='./multipolygon.db' table="multipolygons" (GEOMETRY) sql=</datasource>
<title></title>
<abstract></abstract>
<keywordList>
<value></value>
</keywordList>
<layername>multipolygons</layername>
<srs>
<spatialrefsys>
<proj4>+proj=longlat +datum=WGS84 +no_defs</proj4>
<srsid>3452</srsid>
<srid>4326</srid>
<authid>EPSG:4326</authid>
<description>WGS 84</description>
<projectionacronym>longlat</projectionacronym>
<ellipsoidacronym>WGS84</ellipsoidacronym>
<geographicflag>true</geographicflag>
</spatialrefsys>
</srs>
<provider encoding="System">spatialite</provider>
<previewExpression></previewExpression>
<vectorjoins/>
<renderer-v2 symbollevels="0" type="singleSymbol">
<symbols>
<symbol alpha="0.494118" type="fill" name="0">
<layer pass="0" class="SimpleFill" locked="0">
<prop k="border_width_unit" v="MM"/>
<prop k="color" v="0,170,255,255"/>
<prop k="color_border" v="0,0,0,255"/>
<prop k="offset" v="0,0"/>
<prop k="offset_unit" v="MM"/>
<prop k="style" v="solid"/>
<prop k="style_border" v="solid"/>
<prop k="width_border" v="0.26"/>
</layer>
</symbol>
</symbols>
<rotation/>
<sizescale scalemethod="area"/>
</renderer-v2>
<customproperties>
<property key="labeling" value="pal"/>
<property key="labeling/addDirectionSymbol" value="false"/>
<property key="labeling/angleOffset" value="0"/>
<property key="labeling/blendMode" value="0"/>
<property key="labeling/bufferBlendMode" value="0"/>
<property key="labeling/bufferColorA" value="255"/>
<property key="labeling/bufferColorB" value="255"/>
<property key="labeling/bufferColorG" value="255"/>
<property key="labeling/bufferColorR" value="255"/>
<property key="labeling/bufferDraw" value="false"/>
<property key="labeling/bufferJoinStyle" value="64"/>
<property key="labeling/bufferNoFill" value="false"/>
<property key="labeling/bufferSize" value="1"/>
<property key="labeling/bufferSizeInMapUnits" value="false"/>
<property key="labeling/bufferTransp" value="0"/>
<property key="labeling/centroidWhole" value="false"/>
<property key="labeling/decimals" value="3"/>
<property key="labeling/displayAll" value="false"/>
<property key="labeling/dist" value="0"/>
<property key="labeling/distInMapUnits" value="false"/>
<property key="labeling/enabled" value="false"/>
<property key="labeling/fieldName" value=""/>
<property key="labeling/fontBold" value="false"/>
<property key="labeling/fontCapitals" value="0"/>
<property key="labeling/fontFamily" value="Sans"/>
<property key="labeling/fontItalic" value="false"/>
<property key="labeling/fontLetterSpacing" value="0"/>
<property key="labeling/fontLimitPixelSize" value="false"/>
<property key="labeling/fontMaxPixelSize" value="10000"/>
<property key="labeling/fontMinPixelSize" value="3"/>
<property key="labeling/fontSize" value="10"/>
<property key="labeling/fontSizeInMapUnits" value="false"/>
<property key="labeling/fontStrikeout" value="false"/>
<property key="labeling/fontUnderline" value="false"/>
<property key="labeling/fontWeight" value="50"/>
<property key="labeling/fontWordSpacing" value="0"/>
<property key="labeling/formatNumbers" value="false"/>
<property key="labeling/isExpression" value="false"/>
<property key="labeling/labelOffsetInMapUnits" value="true"/>
<property key="labeling/labelPerPart" value="false"/>
<property key="labeling/leftDirectionSymbol" value="&lt;"/>
<property key="labeling/limitNumLabels" value="false"/>
<property key="labeling/maxCurvedCharAngleIn" value="20"/>
<property key="labeling/maxCurvedCharAngleOut" value="-20"/>
<property key="labeling/maxNumLabels" value="2000"/>
<property key="labeling/mergeLines" value="false"/>
<property key="labeling/minFeatureSize" value="0"/>
<property key="labeling/multilineAlign" value="0"/>
<property key="labeling/multilineHeight" value="1"/>
<property key="labeling/namedStyle" value=""/>
<property key="labeling/obstacle" value="true"/>
<property key="labeling/placeDirectionSymbol" value="0"/>
<property key="labeling/placement" value="0"/>
<property key="labeling/placementFlags" value="0"/>
<property key="labeling/plussign" value="false"/>
<property key="labeling/preserveRotation" value="true"/>
<property key="labeling/previewBkgrdColor" value="#ffffff"/>
<property key="labeling/priority" value="5"/>
<property key="labeling/quadOffset" value="4"/>
<property key="labeling/reverseDirectionSymbol" value="false"/>
<property key="labeling/rightDirectionSymbol" value=">"/>
<property key="labeling/scaleMax" value="10000000"/>
<property key="labeling/scaleMin" value="1"/>
<property key="labeling/scaleVisibility" value="false"/>
<property key="labeling/shadowBlendMode" value="6"/>
<property key="labeling/shadowColorB" value="0"/>
<property key="labeling/shadowColorG" value="0"/>
<property key="labeling/shadowColorR" value="0"/>
<property key="labeling/shadowDraw" value="false"/>
<property key="labeling/shadowOffsetAngle" value="135"/>
<property key="labeling/shadowOffsetDist" value="1"/>
<property key="labeling/shadowOffsetGlobal" value="true"/>
<property key="labeling/shadowOffsetUnits" value="1"/>
<property key="labeling/shadowRadius" value="1.5"/>
<property key="labeling/shadowRadiusAlphaOnly" value="false"/>
<property key="labeling/shadowRadiusUnits" value="1"/>
<property key="labeling/shadowScale" value="100"/>
<property key="labeling/shadowTransparency" value="30"/>
<property key="labeling/shadowUnder" value="0"/>
<property key="labeling/shapeBlendMode" value="0"/>
<property key="labeling/shapeBorderColorA" value="255"/>
<property key="labeling/shapeBorderColorB" value="128"/>
<property key="labeling/shapeBorderColorG" value="128"/>
<property key="labeling/shapeBorderColorR" value="128"/>
<property key="labeling/shapeBorderWidth" value="0"/>
<property key="labeling/shapeBorderWidthUnits" value="1"/>
<property key="labeling/shapeDraw" value="false"/>
<property key="labeling/shapeFillColorA" value="255"/>
<property key="labeling/shapeFillColorB" value="255"/>
<property key="labeling/shapeFillColorG" value="255"/>
<property key="labeling/shapeFillColorR" value="255"/>
<property key="labeling/shapeJoinStyle" value="64"/>
<property key="labeling/shapeOffsetUnits" value="1"/>
<property key="labeling/shapeOffsetX" value="0"/>
<property key="labeling/shapeOffsetY" value="0"/>
<property key="labeling/shapeRadiiUnits" value="1"/>
<property key="labeling/shapeRadiiX" value="0"/>
<property key="labeling/shapeRadiiY" value="0"/>
<property key="labeling/shapeRotation" value="0"/>
<property key="labeling/shapeRotationType" value="0"/>
<property key="labeling/shapeSVGFile" value=""/>
<property key="labeling/shapeSizeType" value="0"/>
<property key="labeling/shapeSizeUnits" value="1"/>
<property key="labeling/shapeSizeX" value="0"/>
<property key="labeling/shapeSizeY" value="0"/>
<property key="labeling/shapeTransparency" value="0"/>
<property key="labeling/shapeType" value="0"/>
<property key="labeling/textColorA" value="255"/>
<property key="labeling/textColorB" value="0"/>
<property key="labeling/textColorG" value="0"/>
<property key="labeling/textColorR" value="0"/>
<property key="labeling/textTransp" value="0"/>
<property key="labeling/upsidedownLabels" value="0"/>
<property key="labeling/wrapChar" value=""/>
<property key="labeling/xOffset" value="0"/>
<property key="labeling/yOffset" value="0"/>
</customproperties>
<blendMode>0</blendMode>
<featureBlendMode>0</featureBlendMode>
<layerTransparency>0</layerTransparency>
<displayfield>OGC_FID</displayfield>
<label>0</label>
<labelattributes>
<label fieldname="" text="Label"/>
<family fieldname="" name="Sans"/>
<size fieldname="" units="pt" value="12"/>
<bold fieldname="" on="0"/>
<italic fieldname="" on="0"/>
<underline fieldname="" on="0"/>
<strikeout fieldname="" on="0"/>
<color fieldname="" red="0" blue="0" green="0"/>
<x fieldname=""/>
<y fieldname=""/>
<offset x="0" y="0" units="pt" yfieldname="" xfieldname=""/>
<angle fieldname="" value="0" auto="0"/>
<alignment fieldname="" value="center"/>
<buffercolor fieldname="" red="255" blue="255" green="255"/>
<buffersize fieldname="" units="pt" value="1"/>
<bufferenabled fieldname="" on=""/>
<multilineenabled fieldname="" on=""/>
<selectedonly on=""/>
</labelattributes>
<edittypes>
<edittype labelontop="0" editable="1" type="0" name="OGC_FID"/>
<edittype labelontop="0" editable="1" type="0" name="id"/>
<edittype labelontop="0" editable="1" type="0" name="type"/>
</edittypes>
<editform>.</editform>
<editforminit></editforminit>
<featformsuppress>0</featformsuppress>
<annotationform>.</annotationform>
<editorlayout>generatedlayout</editorlayout>
<excludeAttributesWMS/>
<excludeAttributesWFS/>
<attributeactions/>
</maplayer>
<maplayer minimumScale="0" maximumScale="1e+08" simplifyDrawingHints="0" minLabelScale="0" maxLabelScale="1e+08" simplifyDrawingTol="1" geometry="Point" simplifyMaxScale="1" type="vector" hasScaleBasedVisibilityFlag="0" simplifyLocal="1" scaleBasedLabelVisibilityFlag="0">
<id>perrors20140228163658956</id>
<datasource>dbname='./multipolygon.db' table="perrors" (GEOMETRY) sql=</datasource>
<title></title>
<abstract></abstract>
<keywordList>
<value></value>
</keywordList>
<layername>Error Points</layername>
<srs>
<spatialrefsys>
<proj4>+proj=longlat +datum=WGS84 +no_defs</proj4>
<srsid>3452</srsid>
<srid>4326</srid>
<authid>EPSG:4326</authid>
<description>WGS 84</description>
<projectionacronym>longlat</projectionacronym>
<ellipsoidacronym>WGS84</ellipsoidacronym>
<geographicflag>true</geographicflag>
</spatialrefsys>
</srs>
<provider encoding="System">spatialite</provider>
<previewExpression>COALESCE( "OGC_FID", '&lt;NULL>' )</previewExpression>
<vectorjoins/>
<renderer-v2 attr="problem_type" symbollevels="0" type="categorizedSymbol">
<categories>
<category symbol="0" value="intersection" label="intersection"/>
<category symbol="1" value="ring_not_closed" label="ring_not_closed"/>
<category symbol="2" value="duplicate_node" label="duplicate_node"/>
</categories>
<symbols>
<symbol alpha="1" type="marker" name="0">
<layer pass="0" class="SimpleMarker" locked="0">
<prop k="angle" v="0"/>
<prop k="color" v="255,0,0,255"/>
<prop k="color_border" v="255,255,255,255"/>
<prop k="horizontal_anchor_point" v="1"/>
<prop k="name" v="diamond"/>
<prop k="offset" v="0,0"/>
<prop k="offset_unit" v="MM"/>
<prop k="outline_style" v="solid"/>
<prop k="outline_width" v="0.4"/>
<prop k="outline_width_unit" v="MM"/>
<prop k="scale_method" v="area"/>
<prop k="size" v="2.8"/>
<prop k="size_unit" v="MM"/>
<prop k="vertical_anchor_point" v="1"/>
</layer>
</symbol>
<symbol alpha="1" type="marker" name="1">
<layer pass="0" class="SimpleMarker" locked="0">
<prop k="angle" v="0"/>
<prop k="color" v="255,0,0,255"/>
<prop k="color_border" v="255,255,255,255"/>
<prop k="horizontal_anchor_point" v="1"/>
<prop k="name" v="triangle"/>
<prop k="offset" v="0,0"/>
<prop k="offset_unit" v="MM"/>
<prop k="outline_style" v="solid"/>
<prop k="outline_width" v="0.4"/>
<prop k="outline_width_unit" v="MM"/>
<prop k="scale_method" v="area"/>
<prop k="size" v="2.8"/>
<prop k="size_unit" v="MM"/>
<prop k="vertical_anchor_point" v="1"/>
</layer>
</symbol>
<symbol alpha="1" type="marker" name="2">
<layer pass="0" class="SimpleMarker" locked="0">
<prop k="angle" v="0"/>
<prop k="color" v="255,255,255,255"/>
<prop k="color_border" v="255,0,0,255"/>
<prop k="horizontal_anchor_point" v="1"/>
<prop k="name" v="circle"/>
<prop k="offset" v="0,0"/>
<prop k="offset_unit" v="MM"/>
<prop k="outline_style" v="solid"/>
<prop k="outline_width" v="0.4"/>
<prop k="outline_width_unit" v="MM"/>
<prop k="scale_method" v="area"/>
<prop k="size" v="2.4"/>
<prop k="size_unit" v="MM"/>
<prop k="vertical_anchor_point" v="1"/>
</layer>
<layer pass="0" class="SimpleMarker" locked="0">
<prop k="angle" v="0"/>
<prop k="color" v="255,0,0,255"/>
<prop k="color_border" v="255,0,0,255"/>
<prop k="horizontal_anchor_point" v="1"/>
<prop k="name" v="circle"/>
<prop k="offset" v="0,0"/>
<prop k="offset_unit" v="MM"/>
<prop k="outline_style" v="solid"/>
<prop k="outline_width" v="0.8"/>
<prop k="outline_width_unit" v="MM"/>
<prop k="scale_method" v="area"/>
<prop k="size" v="0.5"/>
<prop k="size_unit" v="MM"/>
<prop k="vertical_anchor_point" v="1"/>
</layer>
</symbol>
</symbols>
<source-symbol>
<symbol alpha="1" type="marker" name="0">
<layer pass="0" class="SimpleMarker" locked="0">
<prop k="angle" v="0"/>
<prop k="color" v="139,168,110,255"/>
<prop k="color_border" v="0,0,0,255"/>
<prop k="horizontal_anchor_point" v="1"/>
<prop k="name" v="circle"/>
<prop k="offset" v="0,0"/>
<prop k="offset_unit" v="MM"/>
<prop k="outline_style" v="solid"/>
<prop k="outline_width" v="0"/>
<prop k="outline_width_unit" v="MM"/>
<prop k="scale_method" v="area"/>
<prop k="size" v="2"/>
<prop k="size_unit" v="MM"/>
<prop k="vertical_anchor_point" v="1"/>
</layer>
</symbol>
</source-symbol>
<rotation/>
<sizescale scalemethod="area"/>
</renderer-v2>
<customproperties>
<property key="labeling" value="pal"/>
<property key="labeling/addDirectionSymbol" value="false"/>
<property key="labeling/angleOffset" value="0"/>
<property key="labeling/blendMode" value="0"/>
<property key="labeling/bufferBlendMode" value="0"/>
<property key="labeling/bufferColorA" value="255"/>
<property key="labeling/bufferColorB" value="255"/>
<property key="labeling/bufferColorG" value="255"/>
<property key="labeling/bufferColorR" value="255"/>
<property key="labeling/bufferDraw" value="false"/>
<property key="labeling/bufferJoinStyle" value="64"/>
<property key="labeling/bufferNoFill" value="false"/>
<property key="labeling/bufferSize" value="1"/>
<property key="labeling/bufferSizeInMapUnits" value="false"/>
<property key="labeling/bufferTransp" value="0"/>
<property key="labeling/centroidWhole" value="false"/>
<property key="labeling/decimals" value="3"/>
<property key="labeling/displayAll" value="false"/>
<property key="labeling/dist" value="0"/>
<property key="labeling/distInMapUnits" value="false"/>
<property key="labeling/enabled" value="false"/>
<property key="labeling/fieldName" value=""/>
<property key="labeling/fontBold" value="false"/>
<property key="labeling/fontCapitals" value="0"/>
<property key="labeling/fontFamily" value="Sans"/>
<property key="labeling/fontItalic" value="false"/>
<property key="labeling/fontLetterSpacing" value="0"/>
<property key="labeling/fontLimitPixelSize" value="false"/>
<property key="labeling/fontMaxPixelSize" value="10000"/>
<property key="labeling/fontMinPixelSize" value="3"/>
<property key="labeling/fontSize" value="10"/>
<property key="labeling/fontSizeInMapUnits" value="false"/>
<property key="labeling/fontStrikeout" value="false"/>
<property key="labeling/fontUnderline" value="false"/>
<property key="labeling/fontWeight" value="50"/>
<property key="labeling/fontWordSpacing" value="0"/>
<property key="labeling/formatNumbers" value="false"/>
<property key="labeling/isExpression" value="false"/>
<property key="labeling/labelOffsetInMapUnits" value="true"/>
<property key="labeling/labelPerPart" value="false"/>
<property key="labeling/leftDirectionSymbol" value="&lt;"/>
<property key="labeling/limitNumLabels" value="false"/>
<property key="labeling/maxCurvedCharAngleIn" value="20"/>
<property key="labeling/maxCurvedCharAngleOut" value="-20"/>
<property key="labeling/maxNumLabels" value="2000"/>
<property key="labeling/mergeLines" value="false"/>
<property key="labeling/minFeatureSize" value="0"/>
<property key="labeling/multilineAlign" value="0"/>
<property key="labeling/multilineHeight" value="1"/>
<property key="labeling/namedStyle" value=""/>
<property key="labeling/obstacle" value="true"/>
<property key="labeling/placeDirectionSymbol" value="0"/>
<property key="labeling/placement" value="0"/>
<property key="labeling/placementFlags" value="0"/>
<property key="labeling/plussign" value="false"/>
<property key="labeling/preserveRotation" value="true"/>
<property key="labeling/previewBkgrdColor" value="#ffffff"/>
<property key="labeling/priority" value="5"/>
<property key="labeling/quadOffset" value="4"/>
<property key="labeling/reverseDirectionSymbol" value="false"/>
<property key="labeling/rightDirectionSymbol" value=">"/>
<property key="labeling/scaleMax" value="10000000"/>
<property key="labeling/scaleMin" value="1"/>
<property key="labeling/scaleVisibility" value="false"/>
<property key="labeling/shadowBlendMode" value="6"/>
<property key="labeling/shadowColorB" value="0"/>
<property key="labeling/shadowColorG" value="0"/>
<property key="labeling/shadowColorR" value="0"/>
<property key="labeling/shadowDraw" value="false"/>
<property key="labeling/shadowOffsetAngle" value="135"/>
<property key="labeling/shadowOffsetDist" value="1"/>
<property key="labeling/shadowOffsetGlobal" value="true"/>
<property key="labeling/shadowOffsetUnits" value="1"/>
<property key="labeling/shadowRadius" value="1.5"/>
<property key="labeling/shadowRadiusAlphaOnly" value="false"/>
<property key="labeling/shadowRadiusUnits" value="1"/>
<property key="labeling/shadowScale" value="100"/>
<property key="labeling/shadowTransparency" value="30"/>
<property key="labeling/shadowUnder" value="0"/>
<property key="labeling/shapeBlendMode" value="0"/>
<property key="labeling/shapeBorderColorA" value="255"/>
<property key="labeling/shapeBorderColorB" value="128"/>
<property key="labeling/shapeBorderColorG" value="128"/>
<property key="labeling/shapeBorderColorR" value="128"/>
<property key="labeling/shapeBorderWidth" value="0"/>
<property key="labeling/shapeBorderWidthUnits" value="1"/>
<property key="labeling/shapeDraw" value="false"/>
<property key="labeling/shapeFillColorA" value="255"/>
<property key="labeling/shapeFillColorB" value="255"/>
<property key="labeling/shapeFillColorG" value="255"/>
<property key="labeling/shapeFillColorR" value="255"/>
<property key="labeling/shapeJoinStyle" value="64"/>
<property key="labeling/shapeOffsetUnits" value="1"/>
<property key="labeling/shapeOffsetX" value="0"/>
<property key="labeling/shapeOffsetY" value="0"/>
<property key="labeling/shapeRadiiUnits" value="1"/>
<property key="labeling/shapeRadiiX" value="0"/>
<property key="labeling/shapeRadiiY" value="0"/>
<property key="labeling/shapeRotation" value="0"/>
<property key="labeling/shapeRotationType" value="0"/>
<property key="labeling/shapeSVGFile" value=""/>
<property key="labeling/shapeSizeType" value="0"/>
<property key="labeling/shapeSizeUnits" value="1"/>
<property key="labeling/shapeSizeX" value="0"/>
<property key="labeling/shapeSizeY" value="0"/>
<property key="labeling/shapeTransparency" value="0"/>
<property key="labeling/shapeType" value="0"/>
<property key="labeling/textColorA" value="255"/>
<property key="labeling/textColorB" value="0"/>
<property key="labeling/textColorG" value="0"/>
<property key="labeling/textColorR" value="0"/>
<property key="labeling/textTransp" value="0"/>
<property key="labeling/upsidedownLabels" value="0"/>
<property key="labeling/wrapChar" value=""/>
<property key="labeling/xOffset" value="0"/>
<property key="labeling/yOffset" value="0"/>
</customproperties>
<blendMode>0</blendMode>
<featureBlendMode>0</featureBlendMode>
<layerTransparency>0</layerTransparency>
<displayfield>OGC_FID</displayfield>
<label>0</label>
<labelattributes>
<label fieldname="" text="Label"/>
<family fieldname="" name="Sans"/>
<size fieldname="" units="pt" value="12"/>
<bold fieldname="" on="0"/>
<italic fieldname="" on="0"/>
<underline fieldname="" on="0"/>
<strikeout fieldname="" on="0"/>
<color fieldname="" red="0" blue="0" green="0"/>
<x fieldname=""/>
<y fieldname=""/>
<offset x="0" y="0" units="pt" yfieldname="" xfieldname=""/>
<angle fieldname="" value="0" auto="0"/>
<alignment fieldname="" value="center"/>
<buffercolor fieldname="" red="255" blue="255" green="255"/>
<buffersize fieldname="" units="pt" value="1"/>
<bufferenabled fieldname="" on=""/>
<multilineenabled fieldname="" on=""/>
<selectedonly on=""/>
</labelattributes>
<edittypes>
<edittype labelontop="0" editable="1" type="0" name="OGC_FID"/>
<edittype labelontop="0" editable="1" type="0" name="id"/>
<edittype labelontop="0" editable="1" type="0" name="node_id"/>
<edittype labelontop="0" editable="1" type="0" name="object_id"/>
<edittype labelontop="0" editable="1" type="0" name="problem_type"/>
<edittype labelontop="0" editable="1" type="0" name="type"/>
</edittypes>
<editform>.</editform>
<editforminit></editforminit>
<featformsuppress>0</featformsuppress>
<annotationform>.</annotationform>
<editorlayout>generatedlayout</editorlayout>
<excludeAttributesWMS/>
<excludeAttributesWFS/>
<attributeactions/>
</maplayer>
</projectlayers>
<properties>
<WMSContactPerson type="QString"></WMSContactPerson>
<WMSOnlineResource type="QString"></WMSOnlineResource>
<WMSContactOrganization type="QString"></WMSContactOrganization>
<WMSExtent type="QStringList">
<value>0.82500024999999999</value>
<value>-0.35415386986094277</value>
<value>8.17498974999999994</value>
<value>3.45415386986094308</value>
</WMSExtent>
<WMSKeywordList type="QStringList">
<value></value>
</WMSKeywordList>
<WFSUrl type="QString"></WFSUrl>
<Paths>
<Absolute type="bool">false</Absolute>
</Paths>
<WMSServiceTitle type="QString">mp test</WMSServiceTitle>
<WFSLayers type="QStringList"/>
<WMSContactMail type="QString"></WMSContactMail>
<PositionPrecision>
<DecimalPlaces type="int">2</DecimalPlaces>
<Automatic type="bool">true</Automatic>
<DegreeFormat type="QString">D</DegreeFormat>
</PositionPrecision>
<WCSUrl type="QString"></WCSUrl>
<WMSContactPhone type="QString"></WMSContactPhone>
<WMSServiceCapabilities type="bool">true</WMSServiceCapabilities>
<WMSServiceAbstract type="QString"></WMSServiceAbstract>
<WMSAddWktGeometry type="bool">false</WMSAddWktGeometry>
<Measure>
<Ellipsoid type="QString">NONE</Ellipsoid>
</Measure>
<WFSTLayers>
<Insert type="QStringList"/>
<Update type="QStringList"/>
<Delete type="QStringList"/>
</WFSTLayers>
<Gui>
<SelectionColorBluePart type="int">0</SelectionColorBluePart>
<CanvasColorGreenPart type="int">255</CanvasColorGreenPart>
<CanvasColorRedPart type="int">255</CanvasColorRedPart>
<SelectionColorRedPart type="int">255</SelectionColorRedPart>
<SelectionColorAlphaPart type="int">255</SelectionColorAlphaPart>
<SelectionColorGreenPart type="int">255</SelectionColorGreenPart>
<CanvasColorBluePart type="int">255</CanvasColorBluePart>
</Gui>
<Identify>
<disabledLayers type="QStringList"/>
</Identify>
<Macros>
<pythonCode type="QString"></pythonCode>
</Macros>
<WMSAccessConstraints type="QString"></WMSAccessConstraints>
<WCSLayers type="QStringList"/>
<SpatialRefSys>
<ProjectCrs type="QString">EPSG:4326</ProjectCrs>
</SpatialRefSys>
<DefaultStyles>
<Fill type="QString"></Fill>
<Line type="QString"></Line>
<Marker type="QString"></Marker>
<RandomColors type="bool">true</RandomColors>
<AlphaInt type="int">255</AlphaInt>
<ColorRamp type="QString"></ColorRamp>
</DefaultStyles>
<WMSFees type="QString"></WMSFees>
<WMSUrl type="QString"></WMSUrl>
</properties>
</qgis>
@@ -0,0 +1,7 @@
set TESTDATA_DIR=%1
del multipolygon.db multipolygon-tests.json
%2\testdata-multipolygon %TESTDATA_DIR%\grid\data\all.osm >multipolygon.log 2>&1
if ERRORLEVEL 1 (exit /b 1)
ruby %TESTDATA_DIR%\bin\compare-areas.rb %TESTDATA_DIR%\grid\data\tests.json multipolygon-tests.json
if ERRORLEVEL 1 (exit /b 1)
+10
View File
@@ -0,0 +1,10 @@
#!/bin/sh
# helper script needed by cmake to run test
TESTDATA_DIR=$1
rm -f multipolygon.db multipolygon-tests.json
./testdata-multipolygon ${TESTDATA_DIR}/grid/data/all.osm >multipolygon.log 2>&1 &&
${TESTDATA_DIR}/bin/compare-areas.rb ${TESTDATA_DIR}/grid/data/tests.json multipolygon-tests.json
@@ -0,0 +1,41 @@
#include "common.hpp"
class TestHandler100 : public osmium::handler::Handler {
public:
TestHandler100() :
osmium::handler::Handler() {
}
void node(osmium::Node& node) {
if (node.id() == 100000) {
REQUIRE(node.version() == 1);
REQUIRE(node.timestamp() == osmium::Timestamp("2014-01-01T00:00:00Z"));
REQUIRE(node.uid() == 1);
REQUIRE(!strcmp(node.user(), "test"));
REQUIRE(node.changeset() == 1);
REQUIRE(node.location().lon() == 1.02);
REQUIRE(node.location().lat() == 1.02);
} else {
throw std::runtime_error("Unknown ID");
}
}
}; // class TestHandler100
TEST_CASE("100") {
SECTION("test 100") {
osmium::io::Reader reader(dirname + "/1/100/data.osm");
CheckBasicsHandler check_basics_handler(100, 1, 0, 0);
CheckWKTHandler check_wkt_handler(dirname, 100);
TestHandler100 test_handler;
osmium::apply(reader, check_basics_handler, check_wkt_handler, test_handler);
}
}
@@ -0,0 +1,43 @@
#include "common.hpp"
class TestHandler101 : public osmium::handler::Handler {
public:
TestHandler101() :
osmium::handler::Handler() {
}
void node(osmium::Node& node) {
if (node.id() == 101000) {
REQUIRE(node.version() == 1);
REQUIRE(node.location().lon() == 1.12);
REQUIRE(node.location().lat() == 1.02);
} else if (node.id() == 101001) {
REQUIRE(node.version() == 1);
REQUIRE(node.location().lon() == 1.12);
REQUIRE(node.location().lat() == 1.03);
} else if (node.id() == 101002) {
} else if (node.id() == 101003) {
} else {
throw std::runtime_error("Unknown ID");
}
}
}; // class TestHandler101
TEST_CASE("101") {
SECTION("test 101") {
osmium::io::Reader reader(dirname + "/1/101/data.osm");
CheckBasicsHandler check_basics_handler(101, 4, 0, 0);
CheckWKTHandler check_wkt_handler(dirname, 101);
TestHandler101 test_handler;
osmium::apply(reader, check_basics_handler, check_wkt_handler, test_handler);
}
}
@@ -0,0 +1,58 @@
#include "common.hpp"
class TestHandler110 : public osmium::handler::Handler {
public:
TestHandler110() :
osmium::handler::Handler() {
}
void node(const osmium::Node& node) {
if (node.id() == 110000) {
REQUIRE(node.location().lon() == 1.02);
REQUIRE(node.location().lat() == 1.12);
} else if (node.id() == 110001) {
REQUIRE(node.location().lon() == 1.07);
REQUIRE(node.location().lat() == 1.13);
} else {
throw std::runtime_error("Unknown ID");
}
}
void way(const osmium::Way& way) {
if (way.id() == 110800) {
REQUIRE(way.version() == 1);
REQUIRE(way.nodes().size() == 2);
REQUIRE(!way.is_closed());
const char *test_id = way.tags().get_value_by_key("test:id");
REQUIRE(test_id);
REQUIRE(!strcmp(test_id, "110"));
} else {
throw std::runtime_error("Unknown ID");
}
}
}; // class TestHandler110
TEST_CASE("110") {
SECTION("test 110") {
osmium::io::Reader reader(dirname + "/1/110/data.osm");
index_pos_type index_pos;
index_neg_type index_neg;
location_handler_type location_handler(index_pos, index_neg);
location_handler.ignore_errors();
CheckBasicsHandler check_basics_handler(110, 2, 1, 0);
CheckWKTHandler check_wkt_handler(dirname, 110);
TestHandler110 test_handler;
osmium::apply(reader, location_handler, check_basics_handler, check_wkt_handler, test_handler);
}
}
@@ -0,0 +1,305 @@
#include <iostream>
#include <fstream>
#include <map>
#pragma GCC diagnostic push
#ifdef __clang__
# pragma GCC diagnostic ignored "-Wdocumentation-unknown-command"
#endif
#pragma GCC diagnostic ignored "-Wfloat-equal"
#pragma GCC diagnostic ignored "-Wold-style-cast"
#pragma GCC diagnostic ignored "-Wpadded"
#pragma GCC diagnostic ignored "-Wredundant-decls"
#pragma GCC diagnostic ignored "-Wshadow"
# include <ogr_api.h>
# include <ogrsf_frmts.h>
#pragma GCC diagnostic pop
#include <osmium/area/assembler.hpp>
#include <osmium/area/multipolygon_collector.hpp>
#include <osmium/area/problem_reporter_ogr.hpp>
#include <osmium/geom/ogr.hpp>
#include <osmium/geom/wkt.hpp>
#include <osmium/handler.hpp>
#include <osmium/handler/node_locations_for_ways.hpp>
#include <osmium/index/map/dummy.hpp>
#include <osmium/index/map/stl_vector.hpp>
#include <osmium/io/xml_input.hpp>
#include <osmium/visitor.hpp>
typedef osmium::index::map::SparseMapMem<osmium::unsigned_object_id_type, osmium::Location> index_type;
typedef osmium::handler::NodeLocationsForWays<index_type, index_type> location_handler_type;
struct less_charptr {
bool operator()(const char* a, const char* b) const {
return std::strcmp(a, b) < 0;
}
}; // less_charptr
typedef std::map<const char*, const char*, less_charptr> tagmap_type;
inline tagmap_type create_map(const osmium::TagList& taglist) {
tagmap_type map;
for (auto& tag : taglist) {
map[tag.key()] = tag.value();
}
return map;
}
class TestHandler : public osmium::handler::Handler {
OGRDataSource* m_data_source;
OGRLayer* m_layer_point;
OGRLayer* m_layer_linestring;
OGRLayer* m_layer_polygon;
osmium::geom::OGRFactory<> m_ogr_factory;
osmium::geom::WKTFactory<> m_wkt_factory;
std::ofstream m_out;
bool m_first_out {true};
public:
TestHandler(OGRDataSource* data_source) :
m_data_source(data_source),
m_out("multipolygon-tests.json") {
OGRSpatialReference sparef;
sparef.SetWellKnownGeogCS("WGS84");
/**************/
m_layer_point = m_data_source->CreateLayer("points", &sparef, wkbPoint, nullptr);
if (!m_layer_point) {
std::cerr << "Layer creation failed.\n";
exit(1);
}
OGRFieldDefn layer_point_field_id("id", OFTReal);
layer_point_field_id.SetWidth(10);
if (m_layer_point->CreateField(&layer_point_field_id) != OGRERR_NONE) {
std::cerr << "Creating id field failed.\n";
exit(1);
}
OGRFieldDefn layer_point_field_type("type", OFTString);
layer_point_field_type.SetWidth(30);
if (m_layer_point->CreateField(&layer_point_field_type) != OGRERR_NONE) {
std::cerr << "Creating type field failed.\n";
exit(1);
}
/**************/
m_layer_linestring = m_data_source->CreateLayer("lines", &sparef, wkbLineString, nullptr);
if (!m_layer_linestring) {
std::cerr << "Layer creation failed.\n";
exit(1);
}
OGRFieldDefn layer_linestring_field_id("id", OFTReal);
layer_linestring_field_id.SetWidth(10);
if (m_layer_linestring->CreateField(&layer_linestring_field_id) != OGRERR_NONE) {
std::cerr << "Creating id field failed.\n";
exit(1);
}
OGRFieldDefn layer_linestring_field_type("type", OFTString);
layer_linestring_field_type.SetWidth(30);
if (m_layer_linestring->CreateField(&layer_linestring_field_type) != OGRERR_NONE) {
std::cerr << "Creating type field failed.\n";
exit(1);
}
/**************/
m_layer_polygon = m_data_source->CreateLayer("multipolygons", &sparef, wkbMultiPolygon, nullptr);
if (!m_layer_polygon) {
std::cerr << "Layer creation failed.\n";
exit(1);
}
OGRFieldDefn layer_polygon_field_id("id", OFTInteger);
layer_polygon_field_id.SetWidth(10);
if (m_layer_polygon->CreateField(&layer_polygon_field_id) != OGRERR_NONE) {
std::cerr << "Creating id field failed.\n";
exit(1);
}
OGRFieldDefn layer_polygon_field_from_type("from_type", OFTString);
layer_polygon_field_from_type.SetWidth(1);
if (m_layer_polygon->CreateField(&layer_polygon_field_from_type) != OGRERR_NONE) {
std::cerr << "Creating from_type field failed.\n";
exit(1);
}
}
~TestHandler() {
m_out << "\n]\n";
}
void node(const osmium::Node& node) {
OGRFeature* feature = OGRFeature::CreateFeature(m_layer_point->GetLayerDefn());
std::unique_ptr<OGRPoint> ogr_point = m_ogr_factory.create_point(node);
feature->SetGeometry(ogr_point.get());
feature->SetField("id", static_cast<double>(node.id()));
feature->SetField("type", node.tags().get_value_by_key("type"));
if (m_layer_point->CreateFeature(feature) != OGRERR_NONE) {
std::cerr << "Failed to create feature.\n";
exit(1);
}
OGRFeature::DestroyFeature(feature);
}
void way(const osmium::Way& way) {
try {
std::unique_ptr<OGRLineString> ogr_linestring = m_ogr_factory.create_linestring(way);
OGRFeature* feature = OGRFeature::CreateFeature(m_layer_linestring->GetLayerDefn());
feature->SetGeometry(ogr_linestring.get());
feature->SetField("id", static_cast<double>(way.id()));
feature->SetField("type", way.tags().get_value_by_key("type"));
if (m_layer_linestring->CreateFeature(feature) != OGRERR_NONE) {
std::cerr << "Failed to create feature.\n";
exit(1);
}
OGRFeature::DestroyFeature(feature);
} catch (osmium::geometry_error&) {
std::cerr << "Ignoring illegal geometry for way " << way.id() << ".\n";
}
}
void area(const osmium::Area& area) {
if (m_first_out) {
m_out << "[\n";
m_first_out = false;
} else {
m_out << ",\n";
}
m_out << "{\n \"test_id\": " << (area.orig_id() / 1000) << ",\n \"area_id\": " << area.id() << ",\n \"from_id\": " << area.orig_id() << ",\n \"from_type\": \"" << (area.from_way() ? "way" : "relation") << "\",\n \"wkt\": \"";
try {
std::string wkt = m_wkt_factory.create_multipolygon(area);
m_out << wkt << "\",\n \"tags\": {";
auto tagmap = create_map(area.tags());
bool first = true;
for (auto& tag : tagmap) {
if (first) {
first = false;
} else {
m_out << ", ";
}
m_out << '"' << tag.first << "\": \"" << tag.second << '"';
}
m_out << "}\n}";
} catch (osmium::geometry_error&) {
m_out << "INVALID\"\n}";
}
try {
std::unique_ptr<OGRMultiPolygon> ogr_polygon = m_ogr_factory.create_multipolygon(area);
OGRFeature* feature = OGRFeature::CreateFeature(m_layer_polygon->GetLayerDefn());
feature->SetGeometry(ogr_polygon.get());
feature->SetField("id", static_cast<int>(area.orig_id()));
std::string from_type;
if (area.from_way()) {
from_type = "w";
} else {
from_type = "r";
}
feature->SetField("from_type", from_type.c_str());
if (m_layer_polygon->CreateFeature(feature) != OGRERR_NONE) {
std::cerr << "Failed to create feature.\n";
exit(1);
}
OGRFeature::DestroyFeature(feature);
} catch (osmium::geometry_error&) {
std::cerr << "Ignoring illegal geometry for area " << area.id() << " created from " << (area.from_way() ? "way" : "relation") << " with id=" << area.orig_id() << ".\n";
}
}
}; // class TestHandler
/* ================================================== */
OGRDataSource* initialize_database(const std::string& output_format, const std::string& output_filename) {
OGRRegisterAll();
OGRSFDriver* driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(output_format.c_str());
if (!driver) {
std::cerr << output_format << " driver not available.\n";
exit(1);
}
CPLSetConfigOption("OGR_SQLITE_SYNCHRONOUS", "FALSE");
const char* options[] = { "SPATIALITE=TRUE", nullptr };
OGRDataSource* data_source = driver->CreateDataSource(output_filename.c_str(), const_cast<char**>(options));
if (!data_source) {
std::cerr << "Creation of output file failed.\n";
exit(1);
}
return data_source;
}
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " INFILE\n";
exit(1);
}
std::string output_format("SQLite");
std::string input_filename(argv[1]);
std::string output_filename("multipolygon.db");
OGRDataSource* data_source = initialize_database(output_format, output_filename);
osmium::area::ProblemReporterOGR problem_reporter(data_source);
osmium::area::Assembler::config_type assembler_config(&problem_reporter);
assembler_config.enable_debug_output();
osmium::area::MultipolygonCollector<osmium::area::Assembler> collector(assembler_config);
std::cerr << "Pass 1...\n";
osmium::io::Reader reader1(input_filename);
collector.read_relations(reader1);
reader1.close();
std::cerr << "Pass 1 done\n";
index_type index_pos;
index_type index_neg;
location_handler_type location_handler(index_pos, index_neg);
location_handler.ignore_errors();
TestHandler test_handler(data_source);
std::cerr << "Pass 2...\n";
osmium::io::Reader reader2(input_filename);
osmium::apply(reader2, location_handler, test_handler, collector.handler([&test_handler](const osmium::memory::Buffer& area_buffer) {
osmium::apply(area_buffer, test_handler);
}));
reader2.close();
std::cerr << "Pass 2 done\n";
OGRDataSource::DestroyDataSource(data_source);
OGRCleanupAll();
}
@@ -0,0 +1,212 @@
/* The code in this file is released into the Public Domain. */
#include <iostream>
#pragma GCC diagnostic push
#ifdef __clang__
# pragma GCC diagnostic ignored "-Wdocumentation-unknown-command"
#endif
#pragma GCC diagnostic ignored "-Wfloat-equal"
#pragma GCC diagnostic ignored "-Wold-style-cast"
#pragma GCC diagnostic ignored "-Wpadded"
#pragma GCC diagnostic ignored "-Wredundant-decls"
#pragma GCC diagnostic ignored "-Wshadow"
# include <ogr_api.h>
# include <ogrsf_frmts.h>
#pragma GCC diagnostic pop
#include <osmium/geom/ogr.hpp>
#include <osmium/handler.hpp>
#include <osmium/handler/node_locations_for_ways.hpp>
#include <osmium/index/map/dummy.hpp>
#include <osmium/index/map/stl_vector.hpp>
#include <osmium/io/xml_input.hpp>
#include <osmium/visitor.hpp>
typedef osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location> index_neg_type;
typedef osmium::index::map::SparseMapMem<osmium::unsigned_object_id_type, osmium::Location> index_pos_type;
typedef osmium::handler::NodeLocationsForWays<index_pos_type, index_neg_type> location_handler_type;
class TestOverviewHandler : public osmium::handler::Handler {
OGRDataSource* m_data_source;
OGRLayer* m_layer_nodes;
OGRLayer* m_layer_labels;
OGRLayer* m_layer_ways;
osmium::geom::OGRFactory<> m_factory;
public:
TestOverviewHandler(const std::string& driver_name, const std::string& filename) {
OGRRegisterAll();
OGRSFDriver* driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(driver_name.c_str());
if (!driver) {
std::cerr << driver_name << " driver not available.\n";
exit(1);
}
CPLSetConfigOption("OGR_SQLITE_SYNCHRONOUS", "FALSE");
const char* options[] = { "SPATIALITE=TRUE", nullptr };
m_data_source = driver->CreateDataSource(filename.c_str(), const_cast<char**>(options));
if (!m_data_source) {
std::cerr << "Creation of output file failed.\n";
exit(1);
}
OGRSpatialReference sparef;
sparef.SetWellKnownGeogCS("WGS84");
// nodes layer
m_layer_nodes = m_data_source->CreateLayer("nodes", &sparef, wkbPoint, nullptr);
if (!m_layer_nodes) {
std::cerr << "Layer creation failed.\n";
exit(1);
}
OGRFieldDefn layer_nodes_field_id("id", OFTReal);
layer_nodes_field_id.SetWidth(10);
if (m_layer_nodes->CreateField(&layer_nodes_field_id) != OGRERR_NONE) {
std::cerr << "Creating id field failed.\n";
exit(1);
}
// labels layer
m_layer_labels = m_data_source->CreateLayer("labels", &sparef, wkbPoint, nullptr);
if (!m_layer_labels) {
std::cerr << "Layer creation failed.\n";
exit(1);
}
OGRFieldDefn layer_labels_field_id("id", OFTReal);
layer_labels_field_id.SetWidth(10);
if (m_layer_labels->CreateField(&layer_labels_field_id) != OGRERR_NONE) {
std::cerr << "Creating id field failed.\n";
exit(1);
}
OGRFieldDefn layer_labels_field_label("label", OFTString);
layer_labels_field_label.SetWidth(30);
if (m_layer_labels->CreateField(&layer_labels_field_label) != OGRERR_NONE) {
std::cerr << "Creating label field failed.\n";
exit(1);
}
// ways layer
m_layer_ways = m_data_source->CreateLayer("ways", &sparef, wkbLineString, nullptr);
if (!m_layer_ways) {
std::cerr << "Layer creation failed.\n";
exit(1);
}
OGRFieldDefn layer_way_field_id("id", OFTReal);
layer_way_field_id.SetWidth(10);
if (m_layer_ways->CreateField(&layer_way_field_id) != OGRERR_NONE) {
std::cerr << "Creating id field failed.\n";
exit(1);
}
OGRFieldDefn layer_way_field_test("test", OFTInteger);
layer_way_field_test.SetWidth(3);
if (m_layer_ways->CreateField(&layer_way_field_test) != OGRERR_NONE) {
std::cerr << "Creating test field failed.\n";
exit(1);
}
}
~TestOverviewHandler() {
OGRDataSource::DestroyDataSource(m_data_source);
OGRCleanupAll();
}
void node(const osmium::Node& node) {
const char* label = node.tags().get_value_by_key("label");
if (label) {
OGRFeature* feature = OGRFeature::CreateFeature(m_layer_labels->GetLayerDefn());
std::unique_ptr<OGRPoint> ogr_point = m_factory.create_point(node);
feature->SetGeometry(ogr_point.get());
feature->SetField("id", static_cast<double>(node.id()));
feature->SetField("label", label);
if (m_layer_labels->CreateFeature(feature) != OGRERR_NONE) {
std::cerr << "Failed to create feature.\n";
exit(1);
}
OGRFeature::DestroyFeature(feature);
} else {
OGRFeature* feature = OGRFeature::CreateFeature(m_layer_nodes->GetLayerDefn());
std::unique_ptr<OGRPoint> ogr_point = m_factory.create_point(node);
feature->SetGeometry(ogr_point.get());
feature->SetField("id", static_cast<double>(node.id()));
if (m_layer_nodes->CreateFeature(feature) != OGRERR_NONE) {
std::cerr << "Failed to create feature.\n";
exit(1);
}
OGRFeature::DestroyFeature(feature);
}
}
void way(const osmium::Way& way) {
try {
std::unique_ptr<OGRLineString> ogr_linestring = m_factory.create_linestring(way);
OGRFeature* feature = OGRFeature::CreateFeature(m_layer_ways->GetLayerDefn());
feature->SetGeometry(ogr_linestring.get());
feature->SetField("id", static_cast<double>(way.id()));
const char* test = way.tags().get_value_by_key("test");
if (test) {
feature->SetField("test", test);
}
if (m_layer_ways->CreateFeature(feature) != OGRERR_NONE) {
std::cerr << "Failed to create feature.\n";
exit(1);
}
OGRFeature::DestroyFeature(feature);
} catch (osmium::geometry_error&) {
std::cerr << "Ignoring illegal geometry for way " << way.id() << ".\n";
}
}
};
/* ================================================== */
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " INFILE\n";
exit(1);
}
std::string output_format("SQLite");
std::string input_filename(argv[1]);
std::string output_filename("testdata-overview.db");
::unlink(output_filename.c_str());
osmium::io::Reader reader(input_filename);
index_pos_type index_pos;
index_neg_type index_neg;
location_handler_type location_handler(index_pos, index_neg);
location_handler.ignore_errors();
TestOverviewHandler handler(output_format, output_filename);
osmium::apply(reader, location_handler, handler);
reader.close();
}
@@ -0,0 +1,27 @@
#include <iostream>
#include <string>
#define CATCH_CONFIG_RUNNER
#include "testdata-testcases.hpp"
#include <osmpbf/osmpbf.h>
std::string dirname;
int main(int argc, char* argv[]) {
const char* testcases_dir = getenv("TESTCASES_DIR");
if (testcases_dir) {
dirname = testcases_dir;
std::cerr << "Running tests from '" << dirname << "' (from TESTCASES_DIR environment variable)\n";
} else {
std::cerr << "Please set TESTCASES_DIR environment variable.\n";
exit(1);
}
int result = Catch::Session().run(argc, argv);
return result;
}
+372
View File
@@ -0,0 +1,372 @@
/* The code in this file is released into the Public Domain. */
#define CATCH_CONFIG_MAIN
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
#include "catch.hpp"
#pragma GCC diagnostic pop
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <string>
#include <osmium/io/xml_input.hpp>
#include <osmium/io/gzip_compression.hpp>
#include <osmium/visitor.hpp>
std::string filename(const char* test_id, const char* suffix = "osm") {
const char* testdir = getenv("TESTDIR");
if (!testdir) {
std::cerr << "You have to set TESTDIR environment variable before running testdata-xml\n";
exit(2);
}
std::string f;
f += testdir;
f += "/";
f += test_id;
f += "/data.";
f += suffix;
return f;
}
struct header_buffer_type {
osmium::io::Header header;
osmium::memory::Buffer buffer;
};
// =============================================
// The following helper functions are used to call different parts of the
// Osmium internals used to read and parse XML files. This way those parts
// can be tested individually. These function can not be used in normal
// operations, because they make certain assumptions, for instance that
// file contents fit into small buffers.
std::string read_file(const char* test_id) {
int fd = osmium::io::detail::open_for_reading(filename(test_id));
assert(fd >= 0);
std::string input(10000, '\0');
ssize_t n = ::read(fd, reinterpret_cast<unsigned char*>(const_cast<char*>(input.data())), 10000);
assert(n >= 0);
input.resize(static_cast<std::string::size_type>(n));
close(fd);
return input;
}
std::string read_gz_file(const char* test_id, const char* suffix) {
int fd = osmium::io::detail::open_for_reading(filename(test_id, suffix));
assert(fd >= 0);
osmium::io::GzipDecompressor gzip_decompressor(fd);
std::string input = gzip_decompressor.read();
gzip_decompressor.close();
return input;
}
header_buffer_type parse_xml(std::string input) {
osmium::thread::Queue<std::string> input_queue;
osmium::thread::Queue<osmium::memory::Buffer> output_queue;
std::promise<osmium::io::Header> header_promise;
std::atomic<bool> done {false};
input_queue.push(input);
input_queue.push(std::string()); // EOF marker
osmium::io::detail::XMLParser parser(input_queue, output_queue, header_promise, osmium::osm_entity_bits::all, done);
parser();
header_buffer_type result;
result.header = header_promise.get_future().get();
output_queue.wait_and_pop(result.buffer);
if (result.buffer) {
osmium::memory::Buffer buffer;
output_queue.wait_and_pop(buffer);
assert(!buffer);
}
return result;
}
header_buffer_type read_xml(const char* test_id) {
std::string input = read_file(test_id);
return parse_xml(input);
}
// =============================================
TEST_CASE("Reading OSM XML 100") {
SECTION("Direct") {
header_buffer_type r = read_xml("100-correct_but_no_data");
REQUIRE(r.header.get("generator") == "testdata");
REQUIRE(0 == r.buffer.committed());
REQUIRE(! r.buffer);
}
SECTION("Using Reader") {
osmium::io::Reader reader(filename("100-correct_but_no_data"));
osmium::io::Header header = reader.header();
REQUIRE(header.get("generator") == "testdata");
osmium::memory::Buffer buffer = reader.read();
REQUIRE(0 == buffer.committed());
REQUIRE(! buffer);
reader.close();
}
SECTION("Using Reader asking for header only") {
osmium::io::Reader reader(filename("100-correct_but_no_data"), osmium::osm_entity_bits::nothing);
osmium::io::Header header = reader.header();
REQUIRE(header.get("generator") == "testdata");
reader.close();
}
}
// =============================================
TEST_CASE("Reading OSM XML 101") {
SECTION("Direct") {
REQUIRE_THROWS_AS(read_xml("101-missing_version"), osmium::format_version_error);
try {
read_xml("101-missing_version");
} catch (osmium::format_version_error& e) {
REQUIRE(e.version.empty());
}
}
SECTION("Using Reader") {
REQUIRE_THROWS_AS({
osmium::io::Reader reader(filename("101-missing_version"));
osmium::io::Header header = reader.header();
osmium::memory::Buffer buffer = reader.read();
reader.close();
}, osmium::format_version_error);
}
}
// =============================================
TEST_CASE("Reading OSM XML 102") {
SECTION("Direct") {
REQUIRE_THROWS_AS(read_xml("102-wrong_version"), osmium::format_version_error);
try {
read_xml("102-wrong_version");
} catch (osmium::format_version_error& e) {
REQUIRE(e.version == "0.1");
}
}
SECTION("Using Reader") {
REQUIRE_THROWS_AS({
osmium::io::Reader reader(filename("102-wrong_version"));
osmium::io::Header header = reader.header();
osmium::memory::Buffer buffer = reader.read();
reader.close();
}, osmium::format_version_error);
}
}
// =============================================
TEST_CASE("Reading OSM XML 103") {
SECTION("Direct") {
REQUIRE_THROWS_AS(read_xml("103-old_version"), osmium::format_version_error);
try {
read_xml("103-old_version");
} catch (osmium::format_version_error& e) {
REQUIRE(e.version == "0.5");
}
}
SECTION("Using Reader") {
REQUIRE_THROWS_AS({
osmium::io::Reader reader(filename("103-old_version"));
osmium::io::Header header = reader.header();
osmium::memory::Buffer buffer = reader.read();
reader.close();
}, osmium::format_version_error);
}
}
// =============================================
TEST_CASE("Reading OSM XML 104") {
SECTION("Direct") {
REQUIRE_THROWS_AS(read_xml("104-empty_file"), osmium::xml_error);
try {
read_xml("104-empty_file");
} catch (osmium::xml_error& e) {
REQUIRE(e.line == 1);
REQUIRE(e.column == 0);
}
}
SECTION("Using Reader") {
REQUIRE_THROWS_AS({
osmium::io::Reader reader(filename("104-empty_file"));
osmium::io::Header header = reader.header();
osmium::memory::Buffer buffer = reader.read();
reader.close();
}, osmium::xml_error);
}
}
// =============================================
TEST_CASE("Reading OSM XML 105") {
SECTION("Direct") {
REQUIRE_THROWS_AS(read_xml("105-incomplete_xml_file"), osmium::xml_error);
}
SECTION("Using Reader") {
REQUIRE_THROWS_AS({
osmium::io::Reader reader(filename("105-incomplete_xml_file"));
osmium::io::Header header = reader.header();
osmium::memory::Buffer buffer = reader.read();
reader.close();
}, osmium::xml_error);
}
}
// =============================================
TEST_CASE("Reading OSM XML 120") {
SECTION("Direct") {
std::string data = read_gz_file("120-correct_gzip_file_without_data", "osm.gz");
REQUIRE(data.size() == 102);
header_buffer_type r = parse_xml(data);
REQUIRE(r.header.get("generator") == "testdata");
REQUIRE(0 == r.buffer.committed());
REQUIRE(! r.buffer);
}
SECTION("Using Reader") {
osmium::io::Reader reader(filename("120-correct_gzip_file_without_data", "osm.gz"));
osmium::io::Header header = reader.header();
REQUIRE(header.get("generator") == "testdata");
osmium::memory::Buffer buffer = reader.read();
REQUIRE(0 == buffer.committed());
REQUIRE(! buffer);
reader.close();
}
}
// =============================================
TEST_CASE("Reading OSM XML 121") {
SECTION("Direct") {
REQUIRE_THROWS_AS( {
read_gz_file("121-truncated_gzip_file", "osm.gz");
}, osmium::gzip_error);
}
#if 0
SECTION("Using Reader") {
REQUIRE_THROWS_AS({
osmium::io::Reader reader(filename("121-truncated_gzip_file", "osm.gz"));
osmium::io::Header header = reader.header();
osmium::memory::Buffer buffer = reader.read();
reader.close();
}, osmium::gzip_error);
}
#endif
}
// =============================================
TEST_CASE("Reading OSM XML 200") {
SECTION("Direct") {
header_buffer_type r = read_xml("200-nodes");
REQUIRE(r.header.get("generator") == "testdata");
REQUIRE(r.buffer.committed() > 0);
REQUIRE(r.buffer.get<osmium::memory::Item>(0).type() == osmium::item_type::node);
REQUIRE(r.buffer.get<osmium::Node>(0).id() == 36966060);
REQUIRE(std::distance(r.buffer.begin(), r.buffer.end()) == 3);
}
SECTION("Using Reader") {
osmium::io::Reader reader(filename("200-nodes"));
osmium::io::Header header = reader.header();
REQUIRE(header.get("generator") == "testdata");
osmium::memory::Buffer buffer = reader.read();
REQUIRE(buffer.committed() > 0);
REQUIRE(buffer.get<osmium::memory::Item>(0).type() == osmium::item_type::node);
REQUIRE(buffer.get<osmium::Node>(0).id() == 36966060);
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 3);
reader.close();
}
SECTION("Using Reader asking for nodes") {
osmium::io::Reader reader(filename("200-nodes"), osmium::osm_entity_bits::node);
osmium::io::Header header = reader.header();
REQUIRE(header.get("generator") == "testdata");
osmium::memory::Buffer buffer = reader.read();
REQUIRE(buffer.committed() > 0);
REQUIRE(buffer.get<osmium::memory::Item>(0).type() == osmium::item_type::node);
REQUIRE(buffer.get<osmium::Node>(0).id() == 36966060);
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 3);
reader.close();
}
SECTION("Using Reader asking for header only") {
osmium::io::Reader reader(filename("200-nodes"), osmium::osm_entity_bits::nothing);
osmium::io::Header header = reader.header();
REQUIRE(header.get("generator") == "testdata");
osmium::memory::Buffer buffer = reader.read();
REQUIRE(0 == buffer.committed());
REQUIRE(! buffer);
reader.close();
}
SECTION("Using Reader asking for ways") {
osmium::io::Reader reader(filename("200-nodes"), osmium::osm_entity_bits::way);
osmium::io::Header header = reader.header();
REQUIRE(header.get("generator") == "testdata");
osmium::memory::Buffer buffer = reader.read();
REQUIRE(0 == buffer.committed());
REQUIRE(! buffer);
reader.close();
}
}
+25
View File
@@ -0,0 +1,25 @@
#include "catch.hpp"
#include <osmium/osm/area.hpp>
TEST_CASE("area_id") {
SECTION("object_id_to_area_id_conversion") {
REQUIRE( 46 == osmium::object_id_to_area_id( 23, osmium::item_type::way));
REQUIRE( 47 == osmium::object_id_to_area_id( 23, osmium::item_type::relation));
REQUIRE( 0 == osmium::object_id_to_area_id( 0, osmium::item_type::way));
REQUIRE( 1 == osmium::object_id_to_area_id( 0, osmium::item_type::relation));
REQUIRE(-24 == osmium::object_id_to_area_id(-12, osmium::item_type::way));
REQUIRE(-25 == osmium::object_id_to_area_id(-12, osmium::item_type::relation));
}
SECTION("area_id_to_object_id_conversion") {
REQUIRE( 23 == osmium::area_id_to_object_id( 46));
REQUIRE( 23 == osmium::area_id_to_object_id( 47));
REQUIRE( 0 == osmium::area_id_to_object_id( 0));
REQUIRE( 0 == osmium::area_id_to_object_id( 1));
REQUIRE(-12 == osmium::area_id_to_object_id(-24));
REQUIRE(-12 == osmium::area_id_to_object_id(-25));
}
}
@@ -0,0 +1,115 @@
#include "catch.hpp"
#include <osmium/area/detail/node_ref_segment.hpp>
using osmium::area::detail::NodeRefSegment;
TEST_CASE("NodeRefSegmentClass") {
SECTION("instantiation_with_default_parameters") {
NodeRefSegment s;
REQUIRE(s.first().ref() == 0);
REQUIRE(s.first().location() == osmium::Location());
REQUIRE(s.second().ref() == 0);
REQUIRE(s.second().location() == osmium::Location());
}
SECTION("instantiation") {
osmium::NodeRef nr1(1, { 1.2, 3.4 });
osmium::NodeRef nr2(2, { 1.4, 3.1 });
osmium::NodeRef nr3(3, { 1.2, 3.6 });
osmium::NodeRef nr4(4, { 1.2, 3.7 });
NodeRefSegment s1(nr1, nr2, nullptr, nullptr);
REQUIRE(s1.first().ref() == 1);
REQUIRE(s1.second().ref() == 2);
NodeRefSegment s2(nr2, nr3, nullptr, nullptr);
REQUIRE(s2.first().ref() == 3);
REQUIRE(s2.second().ref() == 2);
NodeRefSegment s3(nr3, nr4, nullptr, nullptr);
REQUIRE(s3.first().ref() == 3);
REQUIRE(s3.second().ref() == 4);
}
SECTION("intersection") {
NodeRefSegment s1({ 1, {0.0, 0.0}}, { 2, {2.0, 2.0}}, nullptr, nullptr);
NodeRefSegment s2({ 3, {0.0, 2.0}}, { 4, {2.0, 0.0}}, nullptr, nullptr);
NodeRefSegment s3({ 5, {2.0, 0.0}}, { 6, {4.0, 2.0}}, nullptr, nullptr);
NodeRefSegment s4({ 7, {1.0, 0.0}}, { 8, {3.0, 2.0}}, nullptr, nullptr);
NodeRefSegment s5({ 9, {0.0, 4.0}}, {10, {4.0, 0.0}}, nullptr, nullptr);
NodeRefSegment s6({11, {0.0, 0.0}}, {12, {1.0, 1.0}}, nullptr, nullptr);
NodeRefSegment s7({13, {1.0, 1.0}}, {14, {3.0, 3.0}}, nullptr, nullptr);
REQUIRE(calculate_intersection(s1, s2) == osmium::Location(1.0, 1.0));
REQUIRE(calculate_intersection(s1, s3) == osmium::Location());
REQUIRE(calculate_intersection(s2, s3) == osmium::Location());
REQUIRE(calculate_intersection(s1, s4) == osmium::Location());
REQUIRE(calculate_intersection(s1, s5) == osmium::Location(2.0, 2.0));
REQUIRE(calculate_intersection(s1, s1) == osmium::Location());
REQUIRE(calculate_intersection(s1, s6) == osmium::Location());
REQUIRE(calculate_intersection(s1, s7) == osmium::Location());
}
SECTION("to_left_of") {
osmium::Location loc { 2.0, 2.0 };
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {4.0, 0.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {3.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {4.0, 3.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {2.0, 0.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {3.0, 1.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {1.0, 3.0}}, {1, {3.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {2.0, 0.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {2.0, 0.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {2.0, 2.0}}, {1, {2.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 1.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {0.0, 1.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {1.0, 3.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {2.0, 0.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {3.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {1.0, 0.0}}, {1, {1.0, 2.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {1.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {1.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {0.0, 0.0}}, {1, {0.0, 2.0}}, nullptr, nullptr).to_left_of(loc));
REQUIRE(NodeRefSegment({0, {0.0, 2.0}}, {1, {4.0, 4.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {0.0, 1.0}}, {1, {2.0, 2.0}}, nullptr, nullptr).to_left_of(loc) == false);
REQUIRE(NodeRefSegment({0, {2.0, 2.0}}, {1, {4.0, 0.0}}, nullptr, nullptr).to_left_of(loc) == false);
}
SECTION("ordering") {
osmium::NodeRef node_ref1(1, { 1.0, 3.0 });
osmium::NodeRef node_ref2(2, { 1.4, 2.9 });
osmium::NodeRef node_ref3(3, { 1.2, 3.0 });
osmium::NodeRef node_ref4(4, { 1.2, 3.3 });
REQUIRE(node_ref1 < node_ref2);
REQUIRE(node_ref2 < node_ref3);
REQUIRE(node_ref1 < node_ref3);
REQUIRE(node_ref1 >= node_ref1);
REQUIRE( osmium::location_less()(node_ref1, node_ref2));
REQUIRE(!osmium::location_less()(node_ref2, node_ref3));
REQUIRE( osmium::location_less()(node_ref1, node_ref3));
REQUIRE( osmium::location_less()(node_ref3, node_ref4));
REQUIRE(!osmium::location_less()(node_ref1, node_ref1));
}
}
+97
View File
@@ -0,0 +1,97 @@
#ifndef TEST_BASIC_HELPER_HPP
#define TEST_BASIC_HELPER_HPP
#include <tuple>
#include <utility>
#include <vector>
#include <osmium/builder/osm_object_builder.hpp>
inline void add_tags(osmium::memory::Buffer& buffer, osmium::builder::Builder& builder, const std::vector<std::pair<const char*, const char*>>& tags) {
osmium::builder::TagListBuilder tl_builder(buffer, &builder);
for (auto& tag : tags) {
tl_builder.add_tag(tag.first, tag.second);
}
}
inline osmium::Node& buffer_add_node(osmium::memory::Buffer& buffer, const char* user, const std::vector<std::pair<const char*, const char*>>& tags, const osmium::Location& location) {
osmium::builder::NodeBuilder builder(buffer);
builder.add_user(user);
add_tags(buffer, builder, tags);
buffer.commit();
return builder.object().set_location(location);
}
inline osmium::Way& buffer_add_way(osmium::memory::Buffer& buffer, const char* user, const std::vector<std::pair<const char*, const char*>>& tags, const std::vector<osmium::object_id_type>& nodes) {
osmium::builder::WayBuilder builder(buffer);
builder.add_user(user);
add_tags(buffer, builder, tags);
osmium::builder::WayNodeListBuilder wnl_builder(buffer, &builder);
for (const osmium::object_id_type ref : nodes) {
wnl_builder.add_node_ref(ref);
}
buffer.commit();
return builder.object();
}
inline osmium::Way& buffer_add_way(osmium::memory::Buffer& buffer, const char* user, const std::vector<std::pair<const char*, const char*>>& tags, const std::vector<std::pair<osmium::object_id_type, osmium::Location>>& nodes) {
osmium::builder::WayBuilder builder(buffer);
builder.add_user(user);
add_tags(buffer, builder, tags);
osmium::builder::WayNodeListBuilder wnl_builder(buffer, &builder);
for (auto& p : nodes) {
wnl_builder.add_node_ref(p.first, p.second);
}
buffer.commit();
return builder.object();
}
inline osmium::Relation& buffer_add_relation(
osmium::memory::Buffer& buffer,
const char* user,
const std::vector<std::pair<const char*, const char*>>& tags, const std::vector<std::tuple<char, osmium::object_id_type, const char*>>& members) {
osmium::builder::RelationBuilder builder(buffer);
builder.add_user(user);
add_tags(buffer, builder, tags);
osmium::builder::RelationMemberListBuilder rml_builder(buffer, &builder);
for (const auto& member : members) {
rml_builder.add_member(osmium::char_to_item_type(std::get<0>(member)), std::get<1>(member), std::get<2>(member));
}
buffer.commit();
return builder.object();
}
inline osmium::Area& buffer_add_area(osmium::memory::Buffer& buffer, const char* user,
const std::vector<std::pair<const char*, const char*>>& tags,
const std::vector<std::pair<bool,
std::vector<std::pair<osmium::object_id_type, osmium::Location>>>>& rings) {
osmium::builder::AreaBuilder builder(buffer);
builder.add_user(user);
add_tags(buffer, builder, tags);
for (auto& ring : rings) {
if (ring.first) {
osmium::builder::OuterRingBuilder ring_builder(buffer, &builder);
for (auto& p : ring.second) {
ring_builder.add_node_ref(p.first, p.second);
}
} else {
osmium::builder::InnerRingBuilder ring_builder(buffer, &builder);
for (auto& p : ring.second) {
ring_builder.add_node_ref(p.first, p.second);
}
}
}
buffer.commit();
return builder.object();
}
inline osmium::Changeset& buffer_add_changeset(osmium::memory::Buffer& buffer, const char* user, const std::vector<std::pair<const char*, const char*>>& tags) {
osmium::builder::ChangesetBuilder builder(buffer);
builder.add_user(user);
add_tags(buffer, builder, tags);
buffer.commit();
return builder.object();
}
#endif // TEST_BASIC_HELPER_HPP
+81
View File
@@ -0,0 +1,81 @@
#include "catch.hpp"
#include <sstream>
#include <osmium/osm/box.hpp>
#include <osmium/geom/relations.hpp>
TEST_CASE("Box") {
SECTION("instantiation") {
osmium::Box b;
REQUIRE(!b);
REQUIRE(!b.bottom_left());
REQUIRE(!b.top_right());
REQUIRE_THROWS_AS(b.size(), osmium::invalid_location);
}
SECTION("instantiation_and_extend_with_undefined") {
osmium::Box b;
REQUIRE(!b);
b.extend(osmium::Location());
REQUIRE(!b.bottom_left());
REQUIRE(!b.top_right());
}
SECTION("instantiation_and_extend") {
osmium::Box b;
b.extend(osmium::Location(1.2, 3.4));
REQUIRE(!!b);
REQUIRE(!!b.bottom_left());
REQUIRE(!!b.top_right());
b.extend(osmium::Location(3.4, 4.5));
b.extend(osmium::Location(5.6, 7.8));
REQUIRE(b.bottom_left() == osmium::Location(1.2, 3.4));
REQUIRE(b.top_right() == osmium::Location(5.6, 7.8));
// extend with undefined doesn't change anything
b.extend(osmium::Location());
REQUIRE(b.bottom_left() == osmium::Location(1.2, 3.4));
REQUIRE(b.top_right() == osmium::Location(5.6, 7.8));
}
SECTION("output_defined") {
osmium::Box b;
b.extend(osmium::Location(1.2, 3.4));
b.extend(osmium::Location(5.6, 7.8));
std::stringstream out;
out << b;
REQUIRE(out.str() == "(1.2,3.4,5.6,7.8)");
REQUIRE((19.36 - b.size()) < 0.000001);
}
SECTION("output_undefined") {
osmium::Box b;
std::stringstream out;
out << b;
REQUIRE(out.str() == "(undefined)");
}
SECTION("box_inside_box") {
osmium::Box outer;
outer.extend(osmium::Location(1, 1));
outer.extend(osmium::Location(10, 10));
osmium::Box inner;
inner.extend(osmium::Location(2, 2));
inner.extend(osmium::Location(4, 4));
osmium::Box overlap;
overlap.extend(osmium::Location(3, 3));
overlap.extend(osmium::Location(5, 5));
REQUIRE( osmium::geom::contains(inner, outer));
REQUIRE(!osmium::geom::contains(outer, inner));
REQUIRE(!osmium::geom::contains(overlap, inner));
REQUIRE(!osmium::geom::contains(inner, overlap));
}
}
+57
View File
@@ -0,0 +1,57 @@
#include "catch.hpp"
#include <osmium/osm/changeset.hpp>
#include "helper.hpp"
TEST_CASE("Basic_Changeset") {
SECTION("changeset_builder") {
osmium::memory::Buffer buffer(10 * 1000);
osmium::Changeset& cs1 = buffer_add_changeset(buffer,
"user",
{{"comment", "foo"}});
cs1.set_id(42)
.set_created_at(100)
.set_closed_at(200)
.set_num_changes(7)
.set_uid(9);
REQUIRE(42 == cs1.id());
REQUIRE(9 == cs1.uid());
REQUIRE(7 == cs1.num_changes());
REQUIRE(true == cs1.closed());
REQUIRE(osmium::Timestamp(100) == cs1.created_at());
REQUIRE(osmium::Timestamp(200) == cs1.closed_at());
REQUIRE(1 == cs1.tags().size());
REQUIRE(std::string("user") == cs1.user());
osmium::Changeset& cs2 = buffer_add_changeset(buffer,
"user",
{{"comment", "foo"}, {"foo", "bar"}});
cs2.set_id(43)
.set_created_at(120)
.set_num_changes(21)
.set_uid(9);
REQUIRE(43 == cs2.id());
REQUIRE(9 == cs2.uid());
REQUIRE(21 == cs2.num_changes());
REQUIRE(false == cs2.closed());
REQUIRE(osmium::Timestamp(120) == cs2.created_at());
REQUIRE(osmium::Timestamp() == cs2.closed_at());
REQUIRE(2 == cs2.tags().size());
REQUIRE(std::string("user") == cs2.user());
REQUIRE(cs1 != cs2);
REQUIRE(cs1 < cs2);
REQUIRE(cs1 <= cs2);
REQUIRE(false == (cs1 > cs2));
REQUIRE(false == (cs1 >= cs2));
}
}
+25
View File
@@ -0,0 +1,25 @@
#include "catch.hpp"
#include <osmium/osm/entity_bits.hpp>
TEST_CASE("entity_bits") {
SECTION("can_be_set_and_checked") {
osmium::osm_entity_bits::type entities = osmium::osm_entity_bits::node | osmium::osm_entity_bits::way;
REQUIRE(entities == (osmium::osm_entity_bits::node | osmium::osm_entity_bits::way));
entities |= osmium::osm_entity_bits::relation;
REQUIRE((entities & osmium::osm_entity_bits::object));
entities |= osmium::osm_entity_bits::area;
REQUIRE(entities == osmium::osm_entity_bits::object);
REQUIRE(! (entities & osmium::osm_entity_bits::changeset));
entities &= osmium::osm_entity_bits::node;
REQUIRE((entities & osmium::osm_entity_bits::node));
REQUIRE(! (entities & osmium::osm_entity_bits::way));
REQUIRE(entities == osmium::osm_entity_bits::node);
}
}
+154
View File
@@ -0,0 +1,154 @@
#include "catch.hpp"
#include <sstream>
#include <type_traits>
#include <osmium/osm/location.hpp>
TEST_CASE("Location") {
// fails on MSVC and doesn't really matter
// static_assert(std::is_literal_type<osmium::Location>::value, "osmium::Location not literal type");
SECTION("instantiation_with_default_parameters") {
osmium::Location loc;
REQUIRE(!loc);
REQUIRE_THROWS_AS(loc.lon(), osmium::invalid_location);
REQUIRE_THROWS_AS(loc.lat(), osmium::invalid_location);
}
SECTION("instantiation_with_double_parameters") {
osmium::Location loc1(1.2, 4.5);
REQUIRE(!!loc1);
REQUIRE(12000000 == loc1.x());
REQUIRE(45000000 == loc1.y());
REQUIRE(1.2 == loc1.lon());
REQUIRE(4.5 == loc1.lat());
osmium::Location loc2(loc1);
REQUIRE(4.5 == loc2.lat());
osmium::Location loc3 = loc1;
REQUIRE(4.5 == loc3.lat());
}
SECTION("instantiation_with_double_parameters_constructor_with_universal_initializer") {
osmium::Location loc { 2.2, 3.3 };
REQUIRE(2.2 == loc.lon());
REQUIRE(3.3 == loc.lat());
}
SECTION("instantiation_with_double_parameters_constructor_with_initializer_list") {
osmium::Location loc({ 4.4, 5.5 });
REQUIRE(4.4 == loc.lon());
REQUIRE(5.5 == loc.lat());
}
SECTION("instantiation_with_double_parameters_operator_equal") {
osmium::Location loc = { 5.5, 6.6 };
REQUIRE(5.5 == loc.lon());
REQUIRE(6.6 == loc.lat());
}
SECTION("equality") {
osmium::Location loc1(1.2, 4.5);
osmium::Location loc2(1.2, 4.5);
osmium::Location loc3(1.5, 1.5);
REQUIRE(loc1 == loc2);
REQUIRE(loc1 != loc3);
}
SECTION("order") {
REQUIRE(osmium::Location(-1.2, 10.0) < osmium::Location(1.2, 10.0));
REQUIRE(osmium::Location(1.2, 10.0) > osmium::Location(-1.2, 10.0));
REQUIRE(osmium::Location(10.2, 20.0) < osmium::Location(11.2, 20.2));
REQUIRE(osmium::Location(10.2, 20.2) < osmium::Location(11.2, 20.0));
REQUIRE(osmium::Location(11.2, 20.2) > osmium::Location(10.2, 20.0));
}
SECTION("validity") {
REQUIRE(osmium::Location(0.0, 0.0).valid());
REQUIRE(osmium::Location(1.2, 4.5).valid());
REQUIRE(osmium::Location(-1.2, 4.5).valid());
REQUIRE(osmium::Location(-180.0, -90.0).valid());
REQUIRE(osmium::Location(180.0, -90.0).valid());
REQUIRE(osmium::Location(-180.0, 90.0).valid());
REQUIRE(osmium::Location(180.0, 90.0).valid());
REQUIRE(!osmium::Location(200.0, 4.5).valid());
REQUIRE(!osmium::Location(-1.2, -100.0).valid());
REQUIRE(!osmium::Location(-180.0, 90.005).valid());
}
SECTION("output_to_iterator_comma_separator") {
char buffer[100];
osmium::Location loc(-3.2, 47.3);
*loc.as_string(buffer, ',') = 0;
REQUIRE(std::string("-3.2,47.3") == buffer);
}
SECTION("output_to_iterator_space_separator") {
char buffer[100];
osmium::Location loc(0.0, 7.0);
*loc.as_string(buffer, ' ') = 0;
REQUIRE(std::string("0 7") == buffer);
}
SECTION("output_to_iterator_check_precision") {
char buffer[100];
osmium::Location loc(-179.9999999, -90.0);
*loc.as_string(buffer, ' ') = 0;
REQUIRE(std::string("-179.9999999 -90") == buffer);
}
SECTION("output_to_iterator_undefined_location") {
char buffer[100];
osmium::Location loc;
REQUIRE_THROWS_AS(loc.as_string(buffer, ','), osmium::invalid_location);
}
SECTION("output_to_string_comman_separator") {
std::string s;
osmium::Location loc(-3.2, 47.3);
loc.as_string(std::back_inserter(s), ',');
REQUIRE(s == "-3.2,47.3");
}
SECTION("output_to_string_space_separator") {
std::string s;
osmium::Location loc(0.0, 7.0);
loc.as_string(std::back_inserter(s), ' ');
REQUIRE(s == "0 7");
}
SECTION("output_to_string_check_precision") {
std::string s;
osmium::Location loc(-179.9999999, -90.0);
loc.as_string(std::back_inserter(s), ' ');
REQUIRE(s == "-179.9999999 -90");
}
SECTION("output_to_string_undefined_location") {
std::string s;
osmium::Location loc;
REQUIRE_THROWS_AS(loc.as_string(std::back_inserter(s), ','), osmium::invalid_location);
}
SECTION("output_defined") {
osmium::Location p(-3.2, 47.3);
std::stringstream out;
out << p;
REQUIRE(out.str() == "(-3.2,47.3)");
}
SECTION("output_undefined") {
osmium::Location p;
std::stringstream out;
out << p;
REQUIRE(out.str() == "(undefined,undefined)");
}
}
+114
View File
@@ -0,0 +1,114 @@
#include "catch.hpp"
#include <osmium/osm/node.hpp>
#include "helper.hpp"
TEST_CASE("Basic_Node") {
SECTION("node_builder") {
osmium::memory::Buffer buffer(10000);
osmium::Node& node = buffer_add_node(buffer,
"foo",
{{"amenity", "pub"}, {"name", "OSM BAR"}},
{3.5, 4.7});
node.set_id(17)
.set_version(3)
.set_visible(true)
.set_changeset(333)
.set_uid(21)
.set_timestamp(123);
REQUIRE(17l == node.id());
REQUIRE(17ul == node.positive_id());
REQUIRE(3 == node.version());
REQUIRE(true == node.visible());
REQUIRE(false == node.deleted());
REQUIRE(333 == node.changeset());
REQUIRE(21 == node.uid());
REQUIRE(std::string("foo") == node.user());
REQUIRE(123 == node.timestamp());
REQUIRE(osmium::Location(3.5, 4.7) == node.location());
REQUIRE(2 == node.tags().size());
node.set_visible(false);
REQUIRE(false == node.visible());
REQUIRE(true == node.deleted());
}
SECTION("node_default_attributes") {
osmium::memory::Buffer buffer(10000);
osmium::Node& node = buffer_add_node(buffer, "", {}, osmium::Location{});
REQUIRE(0l == node.id());
REQUIRE(0ul == node.positive_id());
REQUIRE(0 == node.version());
REQUIRE(true == node.visible());
REQUIRE(0 == node.changeset());
REQUIRE(0 == node.uid());
REQUIRE(std::string("") == node.user());
REQUIRE(0 == node.timestamp());
REQUIRE(osmium::Location() == node.location());
REQUIRE(0 == node.tags().size());
}
SECTION("set_node_attributes_from_string") {
osmium::memory::Buffer buffer(10000);
osmium::Node& node = buffer_add_node(buffer,
"foo",
{{"amenity", "pub"}, {"name", "OSM BAR"}},
{3.5, 4.7});
node.set_id("-17")
.set_version("3")
.set_visible(true)
.set_changeset("333")
.set_uid("21");
REQUIRE(-17l == node.id());
REQUIRE(17ul == node.positive_id());
REQUIRE(3 == node.version());
REQUIRE(true == node.visible());
REQUIRE(333 == node.changeset());
REQUIRE(21 == node.uid());
}
SECTION("large_id") {
osmium::memory::Buffer buffer(10000);
osmium::Node& node = buffer_add_node(buffer, "", {}, osmium::Location{});
int64_t id = 3000000000l;
node.set_id(id);
REQUIRE(id == node.id());
REQUIRE(static_cast<osmium::unsigned_object_id_type>(id) == node.positive_id());
node.set_id(-id);
REQUIRE(-id == node.id());
REQUIRE(static_cast<osmium::unsigned_object_id_type>(id) == node.positive_id());
}
SECTION("tags") {
osmium::memory::Buffer buffer(10000);
osmium::Node& node = buffer_add_node(buffer,
"foo",
{{"amenity", "pub"}, {"name", "OSM BAR"}},
{3.5, 4.7});
REQUIRE(nullptr == node.tags().get_value_by_key("fail"));
REQUIRE(std::string("pub") == node.tags().get_value_by_key("amenity"));
REQUIRE(std::string("pub") == node.get_value_by_key("amenity"));
REQUIRE(std::string("default") == node.tags().get_value_by_key("fail", "default"));
REQUIRE(std::string("pub") == node.tags().get_value_by_key("amenity", "default"));
REQUIRE(std::string("pub") == node.get_value_by_key("amenity", "default"));
}
}
+57
View File
@@ -0,0 +1,57 @@
#include "catch.hpp"
#include <osmium/osm/node_ref.hpp>
TEST_CASE("NodeRef") {
SECTION("instantiation_with_default_parameters") {
osmium::NodeRef node_ref;
REQUIRE(node_ref.ref() == 0);
// REQUIRE(!node_ref.has_location());
}
SECTION("instantiation_with_id") {
osmium::NodeRef node_ref(7);
REQUIRE(node_ref.ref() == 7);
}
SECTION("equality") {
osmium::NodeRef node_ref1(7, { 1.2, 3.4 });
osmium::NodeRef node_ref2(7, { 1.4, 3.1 });
osmium::NodeRef node_ref3(9, { 1.2, 3.4 });
REQUIRE(node_ref1 == node_ref2);
REQUIRE(node_ref1 != node_ref3);
REQUIRE(!osmium::location_equal()(node_ref1, node_ref2));
REQUIRE(!osmium::location_equal()(node_ref2, node_ref3));
REQUIRE(osmium::location_equal()(node_ref1, node_ref3));
}
SECTION("set_location") {
osmium::NodeRef node_ref(7);
REQUIRE(!node_ref.location().valid());
REQUIRE(node_ref.location() == osmium::Location());
node_ref.set_location(osmium::Location(13.5, -7.2));
REQUIRE(node_ref.location().lon() == 13.5);
REQUIRE(node_ref.location().valid());
}
SECTION("ordering") {
osmium::NodeRef node_ref1(1, { 1.0, 3.0 });
osmium::NodeRef node_ref2(2, { 1.4, 2.9 });
osmium::NodeRef node_ref3(3, { 1.2, 3.0 });
osmium::NodeRef node_ref4(4, { 1.2, 3.3 });
REQUIRE(node_ref1 < node_ref2);
REQUIRE(node_ref2 < node_ref3);
REQUIRE(node_ref1 < node_ref3);
REQUIRE(node_ref1 >= node_ref1);
REQUIRE(osmium::location_less()(node_ref1, node_ref2));
REQUIRE(!osmium::location_less()(node_ref2, node_ref3));
REQUIRE(osmium::location_less()(node_ref1, node_ref3));
REQUIRE(osmium::location_less()(node_ref3, node_ref4));
REQUIRE(!osmium::location_less()(node_ref1, node_ref1));
}
}
@@ -0,0 +1,147 @@
#include "catch.hpp"
#include <osmium/builder/osm_object_builder.hpp>
#include <osmium/osm.hpp>
#include <osmium/osm/object_comparisons.hpp>
TEST_CASE("Object_Comparisons") {
SECTION("order") {
osmium::memory::Buffer buffer(10 * 1000);
{
// add node 1
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("testuser");
buffer.commit();
}
{
// add node 2
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("testuser");
buffer.commit();
}
auto it = buffer.begin();
osmium::Node& node1 = static_cast<osmium::Node&>(*it);
osmium::Node& node2 = static_cast<osmium::Node&>(*(++it));
node1.set_id(10);
node1.set_version(1);
node2.set_id(15);
node2.set_version(2);
REQUIRE(true == node1 < node2);
REQUIRE(false == node1 > node2);
node1.set_id(20);
node1.set_version(1);
node2.set_id(20);
node2.set_version(2);
REQUIRE(true == node1 < node2);
REQUIRE(false == node1 > node2);
node1.set_id(-10);
node1.set_version(2);
node2.set_id(-15);
node2.set_version(1);
REQUIRE(true == node1 < node2);
REQUIRE(false == node1 > node2);
}
SECTION("order_types") {
osmium::memory::Buffer buffer(10 * 1000);
{
// add node 1
osmium::builder::NodeBuilder node_builder(buffer);
osmium::Node& node = node_builder.object();
REQUIRE(osmium::item_type::node == node.type());
node.set_id(3);
node.set_version(3);
node_builder.add_user("testuser");
buffer.commit();
}
{
// add node 2
osmium::builder::NodeBuilder node_builder(buffer);
osmium::Node& node = node_builder.object();
REQUIRE(osmium::item_type::node == node.type());
node.set_id(3);
node.set_version(4);
node_builder.add_user("testuser");
buffer.commit();
}
{
// add node 3
osmium::builder::NodeBuilder node_builder(buffer);
osmium::Node& node = node_builder.object();
REQUIRE(osmium::item_type::node == node.type());
node.set_id(3);
node.set_version(4);
node_builder.add_user("testuser");
buffer.commit();
}
{
// add way
osmium::builder::WayBuilder way_builder(buffer);
osmium::Way& way = way_builder.object();
REQUIRE(osmium::item_type::way == way.type());
way.set_id(2);
way.set_version(2);
way_builder.add_user("testuser");
buffer.commit();
}
{
// add relation
osmium::builder::RelationBuilder relation_builder(buffer);
osmium::Relation& relation = relation_builder.object();
REQUIRE(osmium::item_type::relation == relation.type());
relation.set_id(1);
relation.set_version(1);
relation_builder.add_user("testuser");
buffer.commit();
}
auto it = buffer.begin();
const osmium::Node& node1 = static_cast<const osmium::Node&>(*it);
const osmium::Node& node2 = static_cast<const osmium::Node&>(*(++it));
const osmium::Node& node3 = static_cast<const osmium::Node&>(*(++it));
const osmium::Way& way = static_cast<const osmium::Way&>(*(++it));
const osmium::Relation& relation = static_cast<const osmium::Relation&>(*(++it));
REQUIRE(true == node1 < node2);
REQUIRE(true == node2 < way);
REQUIRE(false == node2 > way);
REQUIRE(true == way < relation);
REQUIRE(true == node1 < relation);
REQUIRE(true == osmium::object_order_type_id_version()(node1, node2));
REQUIRE(true == osmium::object_order_type_id_reverse_version()(node2, node1));
REQUIRE(true == osmium::object_order_type_id_version()(node1, way));
REQUIRE(true == osmium::object_order_type_id_reverse_version()(node1, way));
REQUIRE(false == osmium::object_equal_type_id_version()(node1, node2));
REQUIRE(true == osmium::object_equal_type_id_version()(node2, node3));
REQUIRE(true == osmium::object_equal_type_id()(node1, node2));
REQUIRE(true == osmium::object_equal_type_id()(node2, node3));
REQUIRE(false == osmium::object_equal_type_id_version()(node1, way));
REQUIRE(false == osmium::object_equal_type_id_version()(node1, relation));
REQUIRE(false == osmium::object_equal_type_id()(node1, relation));
}
}
+60
View File
@@ -0,0 +1,60 @@
#include "catch.hpp"
#include <osmium/osm/relation.hpp>
#include "helper.hpp"
TEST_CASE("Basic_Relation") {
SECTION("relation_builder") {
osmium::memory::Buffer buffer(10000);
osmium::Relation& relation = buffer_add_relation(buffer,
"foo", {
{"type", "multipolygon"},
{"name", "Sherwood Forest"}
}, {
std::make_tuple('w', 1, "inner"),
std::make_tuple('w', 2, ""),
std::make_tuple('w', 3, "outer")
});
relation.set_id(17)
.set_version(3)
.set_visible(true)
.set_changeset(333)
.set_uid(21)
.set_timestamp(123);
REQUIRE(17 == relation.id());
REQUIRE(3 == relation.version());
REQUIRE(true == relation.visible());
REQUIRE(333 == relation.changeset());
REQUIRE(21 == relation.uid());
REQUIRE(std::string("foo") == relation.user());
REQUIRE(123 == relation.timestamp());
REQUIRE(2 == relation.tags().size());
REQUIRE(3 == relation.members().size());
int n=1;
for (auto& member : relation.members()) {
REQUIRE(osmium::item_type::way == member.type());
REQUIRE(n == member.ref());
switch (n) {
case 1:
REQUIRE(std::string("inner") == member.role());
break;
case 2:
REQUIRE(std::string("") == member.role());
break;
case 3:
REQUIRE(std::string("outer") == member.role());
break;
default:
REQUIRE(false);
}
++n;
}
}
}
+45
View File
@@ -0,0 +1,45 @@
#include "catch.hpp"
#include <sstream>
#include <osmium/osm/timestamp.hpp>
TEST_CASE("Timestamp") {
SECTION("can be default initialized to invalid value") {
osmium::Timestamp t;
REQUIRE(0 == t);
REQUIRE("" == t.to_iso());
}
SECTION("invalid value is zero") {
osmium::Timestamp t(static_cast<time_t>(0));
REQUIRE(0 == t);
REQUIRE("" == t.to_iso());
}
SECTION("can be initialized from time_t") {
osmium::Timestamp t(static_cast<time_t>(1));
REQUIRE(1 == t);
REQUIRE("1970-01-01T00:00:01Z" == t.to_iso());
}
SECTION("can be initialized from string") {
osmium::Timestamp t("2000-01-01T00:00:00Z");
REQUIRE("2000-01-01T00:00:00Z" == t.to_iso());
}
SECTION("can be compared") {
osmium::Timestamp t1(10);
osmium::Timestamp t2(50);
REQUIRE(t1 < t2);
}
SECTION("can be written to stream") {
std::stringstream ss;
osmium::Timestamp t(1);
ss << t;
REQUIRE("1970-01-01T00:00:01Z" == ss.str());
}
}
+79
View File
@@ -0,0 +1,79 @@
#include "catch.hpp"
#include <osmium/builder/osm_object_builder.hpp>
#include <osmium/osm/way.hpp>
#include "helper.hpp"
TEST_CASE("Basic_Way") {
SECTION("way_builder") {
osmium::memory::Buffer buffer(10000);
osmium::Way& way = buffer_add_way(buffer,
"foo",
{{"highway", "residential"}, {"name", "High Street"}},
{1, 3, 2});
way.set_id(17)
.set_version(3)
.set_visible(true)
.set_changeset(333)
.set_uid(21)
.set_timestamp(123);
REQUIRE(17 == way.id());
REQUIRE(3 == way.version());
REQUIRE(true == way.visible());
REQUIRE(333 == way.changeset());
REQUIRE(21 == way.uid());
REQUIRE(std::string("foo") == way.user());
REQUIRE(123 == way.timestamp());
REQUIRE(2 == way.tags().size());
REQUIRE(3 == way.nodes().size());
REQUIRE(1 == way.nodes()[0].ref());
REQUIRE(3 == way.nodes()[1].ref());
REQUIRE(2 == way.nodes()[2].ref());
REQUIRE(! way.is_closed());
}
SECTION("closed_way") {
osmium::memory::Buffer buffer(10000);
osmium::Way& way = buffer_add_way(buffer,
"foo",
{{"highway", "residential"}, {"name", "High Street"}},
{1, 3, 1});
REQUIRE(way.is_closed());
}
SECTION("way_builder_with_helpers") {
osmium::memory::Buffer buffer(10000);
{
osmium::builder::WayBuilder builder(buffer);
builder.add_user("username");
builder.add_tags({
{"amenity", "restaurant"},
{"name", "Zum goldenen Schwanen"}
});
builder.add_node_refs({
{22, {3.5, 4.7}},
{67, {4.1, 2.2}}
});
}
buffer.commit();
osmium::Way& way = buffer.get<osmium::Way>(0);
REQUIRE(std::string("username") == way.user());
REQUIRE(2 == way.tags().size());
REQUIRE(std::string("amenity") == way.tags().begin()->key());
REQUIRE(std::string("Zum goldenen Schwanen") == way.tags()["name"]);
REQUIRE(2 == way.nodes().size());
REQUIRE(22 == way.nodes()[0].ref());
REQUIRE(4.1 == way.nodes()[1].location().lon());
}
}
+135
View File
@@ -0,0 +1,135 @@
#include "catch.hpp"
#include <osmium/builder/osm_object_builder.hpp>
#include <osmium/osm/node.hpp>
void check_node_1(osmium::Node& node) {
REQUIRE(1 == node.id());
REQUIRE(3 == node.version());
REQUIRE(true == node.visible());
REQUIRE(333 == node.changeset());
REQUIRE(21 == node.uid());
REQUIRE(123 == node.timestamp());
REQUIRE(osmium::Location(3.5, 4.7) == node.location());
REQUIRE(std::string("testuser") == node.user());
for (osmium::memory::Item& item : node) {
REQUIRE(osmium::item_type::tag_list == item.type());
}
REQUIRE(node.tags().begin() == node.tags().end());
REQUIRE(node.tags().empty());
REQUIRE(0 == std::distance(node.tags().begin(), node.tags().end()));
}
void check_node_2(osmium::Node& node) {
REQUIRE(2 == node.id());
REQUIRE(3 == node.version());
REQUIRE(true == node.visible());
REQUIRE(333 == node.changeset());
REQUIRE(21 == node.uid());
REQUIRE(123 == node.timestamp());
REQUIRE(osmium::Location(3.5, 4.7) == node.location());
REQUIRE(std::string("testuser") == node.user());
for (osmium::memory::Item& item : node) {
REQUIRE(osmium::item_type::tag_list == item.type());
}
REQUIRE(!node.tags().empty());
REQUIRE(2 == std::distance(node.tags().begin(), node.tags().end()));
int n = 0;
for (const osmium::Tag& tag : node.tags()) {
switch (n) {
case 0:
REQUIRE(std::string("amenity") == tag.key());
REQUIRE(std::string("bank") == tag.value());
break;
case 1:
REQUIRE(std::string("name") == tag.key());
REQUIRE(std::string("OSM Savings") == tag.value());
break;
}
++n;
}
REQUIRE(2 == n);
}
TEST_CASE("Buffer_Node") {
SECTION("buffer_node") {
constexpr size_t buffer_size = 10000;
unsigned char data[buffer_size];
osmium::memory::Buffer buffer(data, buffer_size, 0);
{
// add node 1
osmium::builder::NodeBuilder node_builder(buffer);
osmium::Node& node = node_builder.object();
REQUIRE(osmium::item_type::node == node.type());
node.set_id(1);
node.set_version(3);
node.set_visible(true);
node.set_changeset(333);
node.set_uid(21);
node.set_timestamp(123);
node.set_location(osmium::Location(3.5, 4.7));
node_builder.add_user("testuser");
buffer.commit();
}
{
// add node 2
osmium::builder::NodeBuilder node_builder(buffer);
osmium::Node& node = node_builder.object();
REQUIRE(osmium::item_type::node == node.type());
node.set_id(2);
node.set_version(3);
node.set_visible(true);
node.set_changeset(333);
node.set_uid(21);
node.set_timestamp(123);
node.set_location(osmium::Location(3.5, 4.7));
node_builder.add_user("testuser");
{
osmium::builder::TagListBuilder tag_builder(buffer, &node_builder);
tag_builder.add_tag("amenity", "bank");
tag_builder.add_tag("name", "OSM Savings");
}
buffer.commit();
}
REQUIRE(2 == std::distance(buffer.begin(), buffer.end()));
int item_no = 0;
for (osmium::memory::Item& item : buffer) {
REQUIRE(osmium::item_type::node == item.type());
osmium::Node& node = static_cast<osmium::Node&>(item);
switch (item_no) {
case 0:
check_node_1(node);
break;
case 1:
check_node_2(node);
break;
default:
break;
}
++item_no;
}
}
}
@@ -0,0 +1,186 @@
#include "catch.hpp"
#include <osmium/builder/osm_object_builder.hpp>
#include <osmium/osm/node.hpp>
struct CallbackClass {
int count = 0;
void moving_in_buffer(size_t old_offset, size_t new_offset) {
REQUIRE(old_offset > new_offset);
++count;
}
}; // struct CallbackClass
TEST_CASE("Purge data from buffer") {
constexpr size_t buffer_size = 10000;
SECTION("purge empty buffer") {
osmium::memory::Buffer buffer(buffer_size);
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 0);
CallbackClass callback;
buffer.purge_removed(&callback);
REQUIRE(callback.count == 0);
REQUIRE(buffer.committed() == 0);
}
SECTION("purge buffer with one object but nothing to delete") {
osmium::memory::Buffer buffer(buffer_size);
{
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("testuser");
}
buffer.commit();
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1);
size_t committed = buffer.committed();
CallbackClass callback;
buffer.purge_removed(&callback);
REQUIRE(callback.count == 0);
REQUIRE(committed == buffer.committed());
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1);
}
SECTION("purge buffer with one object which gets deleted") {
osmium::memory::Buffer buffer(buffer_size);
{
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("testuser");
node_builder.object().set_removed(true);
}
buffer.commit();
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1);
CallbackClass callback;
buffer.purge_removed(&callback);
REQUIRE(callback.count == 0);
REQUIRE(buffer.committed() == 0);
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 0);
}
SECTION("purge buffer with two objects, first gets deleted") {
osmium::memory::Buffer buffer(buffer_size);
{
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("testuser");
node_builder.object().set_removed(true);
}
buffer.commit();
size_t size1 = buffer.committed();
{
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("testuser");
}
buffer.commit();
size_t size2 = buffer.committed() - size1;
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 2);
CallbackClass callback;
buffer.purge_removed(&callback);
REQUIRE(callback.count == 1);
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1);
REQUIRE(buffer.committed() == size2);
}
SECTION("purge buffer with two objects, second gets deleted") {
osmium::memory::Buffer buffer(buffer_size);
{
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("testuser_longer_name");
}
buffer.commit();
size_t size1 = buffer.committed();
{
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("testuser");
node_builder.object().set_removed(true);
}
buffer.commit();
size_t size2 = buffer.committed() - size1;
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 2);
CallbackClass callback;
buffer.purge_removed(&callback);
REQUIRE(callback.count == 0);
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 1);
REQUIRE(buffer.committed() == size1);
}
SECTION("purge buffer with three objects, middle one gets deleted") {
osmium::memory::Buffer buffer(buffer_size);
{
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("testuser_longer_name");
}
buffer.commit();
size_t size1 = buffer.committed();
{
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("testuser");
node_builder.object().set_removed(true);
}
buffer.commit();
size_t size2 = buffer.committed() - size1;
{
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("sn");
}
buffer.commit();
size_t size3 = buffer.committed() - (size1 + size2);
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 3);
CallbackClass callback;
buffer.purge_removed(&callback);
REQUIRE(callback.count == 1);
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 2);
}
SECTION("purge buffer with three objects, all get deleted") {
osmium::memory::Buffer buffer(buffer_size);
{
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("testuser_longer_name");
node_builder.object().set_removed(true);
}
buffer.commit();
size_t size1 = buffer.committed();
{
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("testuser");
node_builder.object().set_removed(true);
}
buffer.commit();
size_t size2 = buffer.committed() - size1;
{
osmium::builder::NodeBuilder node_builder(buffer);
node_builder.add_user("sn");
node_builder.object().set_removed(true);
}
buffer.commit();
size_t size3 = buffer.committed() - (size1 + size2);
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 3);
CallbackClass callback;
buffer.purge_removed(&callback);
REQUIRE(callback.count == 0);
REQUIRE(std::distance(buffer.begin(), buffer.end()) == 0);
}
}
+15
View File
@@ -0,0 +1,15 @@
#ifndef TEST_GEOM_HELPER_HPP
#define TEST_GEOM_HELPER_HPP
#include <string>
#include <geos/io/WKBWriter.h>
inline std::string geos_to_wkb(const geos::geom::Geometry* geometry) {
std::stringstream ss;
geos::io::WKBWriter wkb_writer;
wkb_writer.writeHEX(*geometry, ss);
return ss.str();
}
#endif // TEST_GEOM_HELPER_HPP
@@ -0,0 +1,41 @@
#include "catch.hpp"
#include <osmium/geom/geos.hpp>
#include <osmium/geom/mercator_projection.hpp>
#include <osmium/geom/projection.hpp>
#include <osmium/geom/wkb.hpp>
#include <osmium/geom/wkt.hpp>
#include "helper.hpp"
TEST_CASE("Projection") {
SECTION("point_mercator") {
osmium::geom::WKTFactory<osmium::geom::MercatorProjection> factory(2);
std::string wkt {factory.create_point(osmium::Location(3.2, 4.2))};
REQUIRE(std::string{"POINT(356222.37 467961.14)"} == wkt);
}
SECTION("point_epsg_3857") {
osmium::geom::WKTFactory<osmium::geom::Projection> factory(osmium::geom::Projection(3857), 2);
std::string wkt {factory.create_point(osmium::Location(3.2, 4.2))};
REQUIRE(std::string{"POINT(356222.37 467961.14)"} == wkt);
}
SECTION("wkb_with_parameter") {
osmium::geom::WKBFactory<osmium::geom::Projection> wkb_factory(osmium::geom::Projection(3857), osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
osmium::geom::GEOSFactory<osmium::geom::Projection> geos_factory(osmium::geom::Projection(3857));
std::string wkb = wkb_factory.create_point(osmium::Location(3.2, 4.2));
std::unique_ptr<geos::geom::Point> geos_point = geos_factory.create_point(osmium::Location(3.2, 4.2));
REQUIRE(geos_to_wkb(geos_point.get()) == wkb);
}
SECTION("cleanup") {
// trying to make valgrind happy, but there is still a memory leak in proj library
pj_deallocate_grids();
}
}
+236
View File
@@ -0,0 +1,236 @@
#include "catch.hpp"
#include <osmium/builder/builder_helper.hpp>
#include <osmium/geom/geojson.hpp>
#include "../basic/helper.hpp"
TEST_CASE("GeoJSON_Geometry") {
SECTION("point") {
osmium::geom::GeoJSONFactory<> factory;
std::string json {factory.create_point(osmium::Location(3.2, 4.2))};
REQUIRE(std::string{"{\"type\":\"Point\",\"coordinates\":[3.2,4.2]}"} == json);
}
SECTION("empty_point") {
osmium::geom::GeoJSONFactory<> factory;
REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location);
}
SECTION("linestring") {
osmium::geom::GeoJSONFactory<> factory;
osmium::memory::Buffer buffer(10000);
auto& wnl = osmium::builder::build_way_node_list(buffer, {
{1, {3.2, 4.2}},
{3, {3.5, 4.7}},
{4, {3.5, 4.7}},
{2, {3.6, 4.9}}
});
{
std::string json {factory.create_linestring(wnl)};
REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.2,4.2],[3.5,4.7],[3.6,4.9]]}"} == json);
}
{
std::string json {factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.6,4.9],[3.5,4.7],[3.2,4.2]]}"} == json);
}
{
std::string json {factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.2,4.2],[3.5,4.7],[3.5,4.7],[3.6,4.9]]}"} == json);
}
{
std::string json {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.6,4.9],[3.5,4.7],[3.5,4.7],[3.2,4.2]]}"} == json);
}
}
SECTION("empty_linestring") {
osmium::geom::GeoJSONFactory<> factory;
osmium::memory::Buffer buffer(10000);
auto& wnl = osmium::builder::build_way_node_list(buffer, {});
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all), osmium::geometry_error);
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward), osmium::geometry_error);
}
SECTION("linestring_with_two_same_locations") {
osmium::geom::GeoJSONFactory<> factory;
osmium::memory::Buffer buffer(10000);
auto& wnl = osmium::builder::build_way_node_list(buffer, {
{1, {3.5, 4.7}},
{2, {3.5, 4.7}}
});
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
{
std::string json {factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.5,4.7],[3.5,4.7]]}"} == json);
}
{
std::string json {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
REQUIRE(std::string{"{\"type\":\"LineString\",\"coordinates\":[[3.5,4.7],[3.5,4.7]]}"} == json);
}
}
SECTION("linestring_with_undefined_location") {
osmium::geom::GeoJSONFactory<> factory;
osmium::memory::Buffer buffer(10000);
auto& wnl = osmium::builder::build_way_node_list(buffer, {
{1, {3.5, 4.7}},
{2, osmium::Location()}
});
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::invalid_location);
}
SECTION("area_1outer_0inner") {
osmium::geom::GeoJSONFactory<> factory;
osmium::memory::Buffer buffer(10000);
osmium::Area& area = buffer_add_area(buffer,
"foo",
{},
{
{ true, {
{1, {3.2, 4.2}},
{2, {3.5, 4.7}},
{3, {3.6, 4.9}},
{1, {3.2, 4.2}}
}}
});
REQUIRE(!area.is_multipolygon());
REQUIRE(std::distance(area.cbegin(), area.cend()) == 2);
REQUIRE(std::distance(area.cbegin<osmium::OuterRing>(), area.cend<osmium::OuterRing>()) == area.num_rings().first);
{
std::string json {factory.create_multipolygon(area)};
REQUIRE(std::string{"{\"type\":\"MultiPolygon\",\"coordinates\":[[[[3.2,4.2],[3.5,4.7],[3.6,4.9],[3.2,4.2]]]]}"} == json);
}
}
SECTION("area_1outer_1inner") {
osmium::geom::GeoJSONFactory<> factory;
osmium::memory::Buffer buffer(10000);
osmium::Area& area = buffer_add_area(buffer,
"foo",
{},
{
{ true, {
{1, {0.1, 0.1}},
{2, {9.1, 0.1}},
{3, {9.1, 9.1}},
{4, {0.1, 9.1}},
{1, {0.1, 0.1}}
}},
{ false, {
{5, {1.0, 1.0}},
{6, {8.0, 1.0}},
{7, {8.0, 8.0}},
{8, {1.0, 8.0}},
{5, {1.0, 1.0}}
}}
});
REQUIRE(!area.is_multipolygon());
REQUIRE(std::distance(area.cbegin(), area.cend()) == 3);
REQUIRE(std::distance(area.cbegin<osmium::OuterRing>(), area.cend<osmium::OuterRing>()) == area.num_rings().first);
REQUIRE(std::distance(area.cbegin<osmium::InnerRing>(), area.cend<osmium::InnerRing>()) == area.num_rings().second);
{
std::string json {factory.create_multipolygon(area)};
REQUIRE(std::string{"{\"type\":\"MultiPolygon\",\"coordinates\":[[[[0.1,0.1],[9.1,0.1],[9.1,9.1],[0.1,9.1],[0.1,0.1]],[[1,1],[8,1],[8,8],[1,8],[1,1]]]]}"} == json);
}
}
SECTION("area_2outer_2inner") {
osmium::geom::GeoJSONFactory<> factory;
osmium::memory::Buffer buffer(10000);
osmium::Area& area = buffer_add_area(buffer,
"foo",
{},
{
{ true, {
{1, {0.1, 0.1}},
{2, {9.1, 0.1}},
{3, {9.1, 9.1}},
{4, {0.1, 9.1}},
{1, {0.1, 0.1}}
}},
{ false, {
{5, {1.0, 1.0}},
{6, {4.0, 1.0}},
{7, {4.0, 4.0}},
{8, {1.0, 4.0}},
{5, {1.0, 1.0}}
}},
{ false, {
{10, {5.0, 5.0}},
{11, {5.0, 7.0}},
{12, {7.0, 7.0}},
{10, {5.0, 5.0}}
}},
{ true, {
{100, {10.0, 10.0}},
{101, {11.0, 10.0}},
{102, {11.0, 11.0}},
{103, {10.0, 11.0}},
{100, {10.0, 10.0}}
}}
});
REQUIRE(area.is_multipolygon());
REQUIRE(std::distance(area.cbegin(), area.cend()) == 5);
REQUIRE(std::distance(area.cbegin<osmium::OuterRing>(), area.cend<osmium::OuterRing>()) == area.num_rings().first);
REQUIRE(std::distance(area.cbegin<osmium::InnerRing>(), area.cend<osmium::InnerRing>()) == area.num_rings().second);
int outer_ring=0;
int inner_ring=0;
for (auto it_outer = area.cbegin<osmium::OuterRing>(); it_outer != area.cend<osmium::OuterRing>(); ++it_outer) {
if (outer_ring == 0) {
REQUIRE(it_outer->front().ref() == 1);
} else if (outer_ring == 1) {
REQUIRE(it_outer->front().ref() == 100);
} else {
REQUIRE(false);
}
for (auto it_inner = area.inner_ring_cbegin(it_outer); it_inner != area.inner_ring_cend(it_outer); ++it_inner) {
if (outer_ring == 0 && inner_ring == 0) {
REQUIRE(it_inner->front().ref() == 5);
} else if (outer_ring == 0 && inner_ring == 1) {
REQUIRE(it_inner->front().ref() == 10);
} else {
REQUIRE(false);
}
++inner_ring;
}
inner_ring = 0;
++outer_ring;
}
{
std::string json {factory.create_multipolygon(area)};
REQUIRE(std::string{"{\"type\":\"MultiPolygon\",\"coordinates\":[[[[0.1,0.1],[9.1,0.1],[9.1,9.1],[0.1,9.1],[0.1,0.1]],[[1,1],[4,1],[4,4],[1,4],[1,1]],[[5,5],[5,7],[7,7],[5,5]]],[[[10,10],[11,10],[11,11],[10,11],[10,10]]]]}"} == json);
}
}
}
+198
View File
@@ -0,0 +1,198 @@
#include "catch.hpp"
#include <osmium/builder/builder_helper.hpp>
#include <osmium/geom/geos.hpp>
#include "../basic/helper.hpp"
TEST_CASE("GEOS_Geometry") {
SECTION("point") {
osmium::geom::GEOSFactory<> factory;
std::unique_ptr<geos::geom::Point> point {factory.create_point(osmium::Location(3.2, 4.2))};
REQUIRE(3.2 == point->getX());
REQUIRE(4.2 == point->getY());
REQUIRE(-1 == point->getSRID());
}
SECTION("non_default_srid") {
osmium::geom::GEOSFactory<> factory(4326);
std::unique_ptr<geos::geom::Point> point {factory.create_point(osmium::Location(3.2, 4.2))};
REQUIRE(3.2 == point->getX());
REQUIRE(4.2 == point->getY());
REQUIRE(4326 == point->getSRID());
}
SECTION("empty_point") {
osmium::geom::GEOSFactory<> factory;
REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location);
}
SECTION("linestring") {
osmium::geom::GEOSFactory<> factory;
osmium::memory::Buffer buffer(10000);
auto& wnl = osmium::builder::build_way_node_list(buffer, {
{1, {3.2, 4.2}},
{3, {3.5, 4.7}},
{4, {3.5, 4.7}},
{2, {3.6, 4.9}}
});
{
std::unique_ptr<geos::geom::LineString> linestring {factory.create_linestring(wnl)};
REQUIRE(3 == linestring->getNumPoints());
std::unique_ptr<geos::geom::Point> p0 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(0));
REQUIRE(3.2 == p0->getX());
std::unique_ptr<geos::geom::Point> p2 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(2));
REQUIRE(3.6 == p2->getX());
}
{
std::unique_ptr<geos::geom::LineString> linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
REQUIRE(3 == linestring->getNumPoints());
std::unique_ptr<geos::geom::Point> p0 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(0));
REQUIRE(3.6 == p0->getX());
std::unique_ptr<geos::geom::Point> p2 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(2));
REQUIRE(3.2 == p2->getX());
}
{
std::unique_ptr<geos::geom::LineString> linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
REQUIRE(4 == linestring->getNumPoints());
std::unique_ptr<geos::geom::Point> p0 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(0));
REQUIRE(3.2 == p0->getX());
}
{
std::unique_ptr<geos::geom::LineString> linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
REQUIRE(4 == linestring->getNumPoints());
std::unique_ptr<geos::geom::Point> p0 = std::unique_ptr<geos::geom::Point>(linestring->getPointN(0));
REQUIRE(3.6 == p0->getX());
}
}
SECTION("area_1outer_0inner") {
osmium::geom::GEOSFactory<> factory;
osmium::memory::Buffer buffer(10000);
osmium::Area& area = buffer_add_area(buffer,
"foo",
{},
{
{ true, {
{1, {3.2, 4.2}},
{2, {3.5, 4.7}},
{3, {3.6, 4.9}},
{1, {3.2, 4.2}}
}}
});
std::unique_ptr<geos::geom::MultiPolygon> mp {factory.create_multipolygon(area)};
REQUIRE(1 == mp->getNumGeometries());
const geos::geom::Polygon* p0 = dynamic_cast<const geos::geom::Polygon*>(mp->getGeometryN(0));
REQUIRE(0 == p0->getNumInteriorRing());
const geos::geom::LineString* l0e = p0->getExteriorRing();
REQUIRE(4 == l0e->getNumPoints());
std::unique_ptr<geos::geom::Point> l0e_p0 = std::unique_ptr<geos::geom::Point>(l0e->getPointN(1));
REQUIRE(3.5 == l0e_p0->getX());
}
SECTION("area_1outer_1inner") {
osmium::geom::GEOSFactory<> factory;
osmium::memory::Buffer buffer(10000);
osmium::Area& area = buffer_add_area(buffer,
"foo",
{},
{
{ true, {
{1, {0.1, 0.1}},
{2, {9.1, 0.1}},
{3, {9.1, 9.1}},
{4, {0.1, 9.1}},
{1, {0.1, 0.1}}
}},
{ false, {
{5, {1.0, 1.0}},
{6, {8.0, 1.0}},
{7, {8.0, 8.0}},
{8, {1.0, 8.0}},
{5, {1.0, 1.0}}
}}
});
std::unique_ptr<geos::geom::MultiPolygon> mp {factory.create_multipolygon(area)};
REQUIRE(1 == mp->getNumGeometries());
const geos::geom::Polygon* p0 = dynamic_cast<const geos::geom::Polygon*>(mp->getGeometryN(0));
REQUIRE(1 == p0->getNumInteriorRing());
const geos::geom::LineString* l0e = p0->getExteriorRing();
REQUIRE(5 == l0e->getNumPoints());
const geos::geom::LineString* l0i0 = p0->getInteriorRingN(0);
REQUIRE(5 == l0i0->getNumPoints());
}
SECTION("area_2outer_2inner") {
osmium::geom::GEOSFactory<> factory;
osmium::memory::Buffer buffer(10000);
osmium::Area& area = buffer_add_area(buffer,
"foo",
{},
{
{ true, {
{1, {0.1, 0.1}},
{2, {9.1, 0.1}},
{3, {9.1, 9.1}},
{4, {0.1, 9.1}},
{1, {0.1, 0.1}}
}},
{ false, {
{5, {1.0, 1.0}},
{6, {4.0, 1.0}},
{7, {4.0, 4.0}},
{8, {1.0, 4.0}},
{5, {1.0, 1.0}}
}},
{ false, {
{10, {5.0, 5.0}},
{11, {5.0, 7.0}},
{12, {7.0, 7.0}},
{10, {5.0, 5.0}}
}},
{ true, {
{100, {10.0, 10.0}},
{101, {11.0, 10.0}},
{102, {11.0, 11.0}},
{103, {10.0, 11.0}},
{100, {10.0, 10.0}}
}}
});
std::unique_ptr<geos::geom::MultiPolygon> mp {factory.create_multipolygon(area)};
REQUIRE(2 == mp->getNumGeometries());
const geos::geom::Polygon* p0 = dynamic_cast<const geos::geom::Polygon*>(mp->getGeometryN(0));
REQUIRE(2 == p0->getNumInteriorRing());
const geos::geom::LineString* l0e = p0->getExteriorRing();
REQUIRE(5 == l0e->getNumPoints());
const geos::geom::Polygon* p1 = dynamic_cast<const geos::geom::Polygon*>(mp->getGeometryN(1));
REQUIRE(0 == p1->getNumInteriorRing());
const geos::geom::LineString* l1e = p1->getExteriorRing();
REQUIRE(5 == l1e->getNumPoints());
}
}
+156
View File
@@ -0,0 +1,156 @@
#include "catch.hpp"
#include <osmium/builder/builder_helper.hpp>
#include <osmium/geom/geos.hpp>
#include <osmium/geom/wkb.hpp>
#include "../basic/helper.hpp"
#include "helper.hpp"
TEST_CASE("WKB_Geometry_with_GEOS") {
SECTION("point") {
osmium::geom::WKBFactory<> wkb_factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
osmium::geom::GEOSFactory<> geos_factory;
std::string wkb {wkb_factory.create_point(osmium::Location(3.2, 4.2))};
std::unique_ptr<geos::geom::Point> geos_point = geos_factory.create_point(osmium::Location(3.2, 4.2));
REQUIRE(geos_to_wkb(geos_point.get()) == wkb);
}
SECTION("linestring") {
osmium::geom::WKBFactory<> wkb_factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
osmium::geom::GEOSFactory<> geos_factory;
osmium::memory::Buffer buffer(10000);
auto& wnl = osmium::builder::build_way_node_list(buffer, {
{1, {3.2, 4.2}},
{3, {3.5, 4.7}},
{4, {3.5, 4.7}},
{2, {3.6, 4.9}}
});
{
std::string wkb = wkb_factory.create_linestring(wnl);
std::unique_ptr<geos::geom::LineString> geos = geos_factory.create_linestring(wnl);
REQUIRE(geos_to_wkb(geos.get()) == wkb);
}
{
std::string wkb = wkb_factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward);
std::unique_ptr<geos::geom::LineString> geos = geos_factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward);
REQUIRE(geos_to_wkb(geos.get()) == wkb);
}
{
std::string wkb = wkb_factory.create_linestring(wnl, osmium::geom::use_nodes::all);
std::unique_ptr<geos::geom::LineString> geos = geos_factory.create_linestring(wnl, osmium::geom::use_nodes::all);
REQUIRE(geos_to_wkb(geos.get()) == wkb);
}
{
std::string wkb = wkb_factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward);
std::unique_ptr<geos::geom::LineString> geos = geos_factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward);
REQUIRE(geos_to_wkb(geos.get()) == wkb);
}
}
SECTION("area_1outer_0inner") {
osmium::geom::WKBFactory<> wkb_factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
osmium::geom::GEOSFactory<> geos_factory;
osmium::memory::Buffer buffer(10000);
osmium::Area& area = buffer_add_area(buffer,
"foo",
{},
{
{ true, {
{1, {3.2, 4.2}},
{2, {3.5, 4.7}},
{3, {3.6, 4.9}},
{1, {3.2, 4.2}}
}}
});
std::string wkb = wkb_factory.create_multipolygon(area);
std::unique_ptr<geos::geom::MultiPolygon> geos = geos_factory.create_multipolygon(area);
REQUIRE(geos_to_wkb(geos.get()) == wkb);
}
SECTION("area_1outer_1inner") {
osmium::geom::WKBFactory<> wkb_factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
osmium::geom::GEOSFactory<> geos_factory;
osmium::memory::Buffer buffer(10000);
osmium::Area& area = buffer_add_area(buffer,
"foo",
{},
{
{ true, {
{1, {0.1, 0.1}},
{2, {9.1, 0.1}},
{3, {9.1, 9.1}},
{4, {0.1, 9.1}},
{1, {0.1, 0.1}}
}},
{ false, {
{5, {1.0, 1.0}},
{6, {8.0, 1.0}},
{7, {8.0, 8.0}},
{8, {1.0, 8.0}},
{5, {1.0, 1.0}}
}}
});
std::string wkb = wkb_factory.create_multipolygon(area);
std::unique_ptr<geos::geom::MultiPolygon> geos = geos_factory.create_multipolygon(area);
REQUIRE(geos_to_wkb(geos.get()) == wkb);
}
SECTION("area_2outer_2inner") {
osmium::geom::WKBFactory<> wkb_factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
osmium::geom::GEOSFactory<> geos_factory;
osmium::memory::Buffer buffer(10000);
osmium::Area& area = buffer_add_area(buffer,
"foo",
{},
{
{ true, {
{1, {0.1, 0.1}},
{2, {9.1, 0.1}},
{3, {9.1, 9.1}},
{4, {0.1, 9.1}},
{1, {0.1, 0.1}}
}},
{ false, {
{5, {1.0, 1.0}},
{6, {4.0, 1.0}},
{7, {4.0, 4.0}},
{8, {1.0, 4.0}},
{5, {1.0, 1.0}}
}},
{ false, {
{10, {5.0, 5.0}},
{11, {5.0, 7.0}},
{12, {7.0, 7.0}},
{10, {5.0, 5.0}}
}},
{ true, {
{100, {10.0, 10.0}},
{101, {11.0, 10.0}},
{102, {11.0, 11.0}},
{103, {10.0, 11.0}},
{100, {10.0, 10.0}}
}}
});
std::string wkb = wkb_factory.create_multipolygon(area);
std::unique_ptr<geos::geom::MultiPolygon> geos = geos_factory.create_multipolygon(area);
REQUIRE(geos_to_wkb(geos.get()) == wkb);
}
}
+37
View File
@@ -0,0 +1,37 @@
#include "catch.hpp"
#include <osmium/geom/mercator_projection.hpp>
TEST_CASE("Mercator") {
SECTION("mercator_projection") {
osmium::geom::MercatorProjection projection;
REQUIRE(3857 == projection.epsg());
REQUIRE("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs" == projection.proj_string());
}
SECTION("low_level_mercator_functions") {
osmium::geom::Coordinates c1(17.839, -3.249);
osmium::geom::Coordinates r1 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c1));
REQUIRE(std::abs(c1.x - r1.x) < 0.000001);
REQUIRE(std::abs(c1.y - r1.y) < 0.000001);
osmium::geom::Coordinates c2(-89.2, 15.915);
osmium::geom::Coordinates r2 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c2));
REQUIRE(std::abs(c2.x - r2.x) < 0.000001);
REQUIRE(std::abs(c2.y - r2.y) < 0.000001);
osmium::geom::Coordinates c3(180.0, 85.0);
osmium::geom::Coordinates r3 = osmium::geom::mercator_to_lonlat(osmium::geom::lonlat_to_mercator(c3));
REQUIRE(std::abs(c3.x - r3.x) < 0.000001);
REQUIRE(std::abs(c3.y - r3.y) < 0.000001);
}
SECTION("mercator_bounds") {
osmium::Location mmax(180.0, osmium::geom::MERCATOR_MAX_LAT);
osmium::geom::Coordinates c = osmium::geom::lonlat_to_mercator(mmax);
REQUIRE((c.x - c.y) < 0.001);
REQUIRE((osmium::geom::MERCATOR_MAX_LAT - osmium::geom::detail::y_to_lat(osmium::geom::detail::lon_to_x(180.0))) < 0.0000001);
}
}
+185
View File
@@ -0,0 +1,185 @@
#include "catch.hpp"
#include <osmium/builder/builder_helper.hpp>
#include <osmium/geom/ogr.hpp>
#include "../basic/helper.hpp"
TEST_CASE("OGR_Geometry") {
SECTION("point") {
osmium::geom::OGRFactory<> factory;
std::unique_ptr<OGRPoint> point {factory.create_point(osmium::Location(3.2, 4.2))};
REQUIRE(3.2 == point->getX());
REQUIRE(4.2 == point->getY());
}
SECTION("empty_point") {
osmium::geom::OGRFactory<> factory;
REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location);
}
SECTION("linestring") {
osmium::geom::OGRFactory<> factory;
osmium::memory::Buffer buffer(10000);
auto& wnl = osmium::builder::build_way_node_list(buffer, {
{1, {3.2, 4.2}},
{3, {3.5, 4.7}},
{4, {3.5, 4.7}},
{2, {3.6, 4.9}}
});
{
std::unique_ptr<OGRLineString> linestring {factory.create_linestring(wnl)};
REQUIRE(3 == linestring->getNumPoints());
REQUIRE(3.2 == linestring->getX(0));
REQUIRE(3.6 == linestring->getX(2));
}
{
std::unique_ptr<OGRLineString> linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
REQUIRE(3 == linestring->getNumPoints());
REQUIRE(3.6 == linestring->getX(0));
REQUIRE(3.2 == linestring->getX(2));
}
{
std::unique_ptr<OGRLineString> linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
REQUIRE(4 == linestring->getNumPoints());
REQUIRE(3.2 == linestring->getX(0));
}
{
std::unique_ptr<OGRLineString> linestring {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
REQUIRE(4 == linestring->getNumPoints());
REQUIRE(3.6 == linestring->getX(0));
}
}
SECTION("area_1outer_0inner") {
osmium::geom::OGRFactory<> factory;
osmium::memory::Buffer buffer(10000);
osmium::Area& area = buffer_add_area(buffer,
"foo",
{},
{
{ true, {
{1, {3.2, 4.2}},
{2, {3.5, 4.7}},
{3, {3.6, 4.9}},
{1, {3.2, 4.2}}
}}
});
std::unique_ptr<OGRMultiPolygon> mp {factory.create_multipolygon(area)};
REQUIRE(1 == mp->getNumGeometries());
const OGRPolygon* p0 = dynamic_cast<const OGRPolygon*>(mp->getGeometryRef(0));
REQUIRE(0 == p0->getNumInteriorRings());
const OGRLineString* l0e = p0->getExteriorRing();
REQUIRE(4 == l0e->getNumPoints());
REQUIRE(3.5 == l0e->getX(1));
}
SECTION("area_1outer_1inner") {
osmium::geom::OGRFactory<> factory;
osmium::memory::Buffer buffer(10000);
osmium::Area& area = buffer_add_area(buffer,
"foo",
{},
{
{ true, {
{1, {0.1, 0.1}},
{2, {9.1, 0.1}},
{3, {9.1, 9.1}},
{4, {0.1, 9.1}},
{1, {0.1, 0.1}}
}},
{ false, {
{5, {1.0, 1.0}},
{6, {8.0, 1.0}},
{7, {8.0, 8.0}},
{8, {1.0, 8.0}},
{5, {1.0, 1.0}}
}}
});
std::unique_ptr<OGRMultiPolygon> mp {factory.create_multipolygon(area)};
REQUIRE(1 == mp->getNumGeometries());
const OGRPolygon* p0 = dynamic_cast<const OGRPolygon*>(mp->getGeometryRef(0));
REQUIRE(1 == p0->getNumInteriorRings());
const OGRLineString* l0e = p0->getExteriorRing();
REQUIRE(5 == l0e->getNumPoints());
const OGRLineString* l0i0 = p0->getInteriorRing(0);
REQUIRE(5 == l0i0->getNumPoints());
}
SECTION("area_2outer_2inner") {
osmium::geom::OGRFactory<> factory;
osmium::memory::Buffer buffer(10000);
osmium::Area& area = buffer_add_area(buffer,
"foo",
{},
{
{ true, {
{1, {0.1, 0.1}},
{2, {9.1, 0.1}},
{3, {9.1, 9.1}},
{4, {0.1, 9.1}},
{1, {0.1, 0.1}}
}},
{ false, {
{5, {1.0, 1.0}},
{6, {4.0, 1.0}},
{7, {4.0, 4.0}},
{8, {1.0, 4.0}},
{5, {1.0, 1.0}}
}},
{ false, {
{10, {5.0, 5.0}},
{11, {5.0, 7.0}},
{12, {7.0, 7.0}},
{10, {5.0, 5.0}}
}},
{ true, {
{100, {10.0, 10.0}},
{101, {11.0, 10.0}},
{102, {11.0, 11.0}},
{103, {10.0, 11.0}},
{100, {10.0, 10.0}}
}}
});
std::unique_ptr<OGRMultiPolygon> mp {factory.create_multipolygon(area)};
REQUIRE(2 == mp->getNumGeometries());
const OGRPolygon* p0 = dynamic_cast<const OGRPolygon*>(mp->getGeometryRef(0));
REQUIRE(2 == p0->getNumInteriorRings());
const OGRLineString* l0e = p0->getExteriorRing();
REQUIRE(5 == l0e->getNumPoints());
const OGRPolygon* p1 = dynamic_cast<const OGRPolygon*>(mp->getGeometryRef(1));
REQUIRE(0 == p1->getNumInteriorRings());
const OGRLineString* l1e = p1->getExteriorRing();
REQUIRE(5 == l1e->getNumPoints());
}
}
+131
View File
@@ -0,0 +1,131 @@
#include "catch.hpp"
#include <osmium/geom/factory.hpp>
#include <osmium/geom/mercator_projection.hpp>
#include <osmium/geom/projection.hpp>
TEST_CASE("Projection") {
SECTION("identity_projection") {
osmium::geom::IdentityProjection projection;
REQUIRE(4326 == projection.epsg());
REQUIRE("+proj=longlat +datum=WGS84 +no_defs" == projection.proj_string());
}
SECTION("project_location_4326") {
osmium::geom::Projection projection(4326);
REQUIRE(4326 == projection.epsg());
REQUIRE("+init=epsg:4326" == projection.proj_string());
const osmium::Location loc(1.0, 2.0);
const osmium::geom::Coordinates c {1.0, 2.0};
REQUIRE(c == projection(loc));
}
SECTION("project_location_4326_string") {
osmium::geom::Projection projection("+init=epsg:4326");
REQUIRE(-1 == projection.epsg());
REQUIRE("+init=epsg:4326" == projection.proj_string());
const osmium::Location loc(1.0, 2.0);
const osmium::geom::Coordinates c {1.0, 2.0};
REQUIRE(c == projection(loc));
}
SECTION("unknown_projection_string") {
REQUIRE_THROWS_AS(osmium::geom::Projection projection("abc"), osmium::projection_error);
}
SECTION("unknown_epsg_code") {
REQUIRE_THROWS_AS(osmium::geom::Projection projection(9999999), osmium::projection_error);
}
SECTION("project_location_3857") {
osmium::geom::Projection projection(3857);
REQUIRE(3857 == projection.epsg());
REQUIRE("+init=epsg:3857" == projection.proj_string());
{
const osmium::Location loc(0.0, 0.0);
const osmium::geom::Coordinates c {0.0, 0.0};
REQUIRE(std::abs(projection(loc).x - c.x) < 0.1);
REQUIRE(std::abs(projection(loc).y - c.y) < 0.1);
}
{
const osmium::Location loc(180.0, 0.0);
const osmium::geom::Coordinates c {20037508.34, 0.0};
REQUIRE(std::abs(projection(loc).x - c.x) < 0.1);
REQUIRE(std::abs(projection(loc).y - c.y) < 0.1);
}
{
const osmium::Location loc(180.0, 0.0);
const osmium::geom::Coordinates c {20037508.34, 0.0};
REQUIRE(std::abs(projection(loc).x - c.x) < 0.1);
REQUIRE(std::abs(projection(loc).y - c.y) < 0.1);
}
{
const osmium::Location loc(0.0, 85.0511288);
const osmium::geom::Coordinates c {0.0, 20037508.34};
REQUIRE(std::abs(projection(loc).x - c.x) < 0.1);
REQUIRE(std::abs(projection(loc).y - c.y) < 0.1);
}
}
SECTION("project_location_mercator") {
osmium::geom::MercatorProjection projection;
{
const osmium::Location loc(0.0, 0.0);
const osmium::geom::Coordinates c {0.0, 0.0};
REQUIRE(std::abs(projection(loc).x - c.x) < 0.1);
REQUIRE(std::abs(projection(loc).y - c.y) < 0.1);
}
{
const osmium::Location loc(180.0, 0.0);
const osmium::geom::Coordinates c {20037508.34, 0.0};
REQUIRE(std::abs(projection(loc).x - c.x) < 0.1);
REQUIRE(std::abs(projection(loc).y - c.y) < 0.1);
}
{
const osmium::Location loc(180.0, 0.0);
const osmium::geom::Coordinates c {20037508.34, 0.0};
REQUIRE(std::abs(projection(loc).x - c.x) < 0.1);
REQUIRE(std::abs(projection(loc).y - c.y) < 0.1);
}
{
const osmium::Location loc(0.0, 85.0511288);
const osmium::geom::Coordinates c {0.0, 20037508.34};
REQUIRE(std::abs(projection(loc).x - c.x) < 0.1);
REQUIRE(std::abs(projection(loc).y - c.y) < 0.1);
}
}
SECTION("compare_mercators") {
osmium::geom::MercatorProjection projection_merc;
osmium::geom::Projection projection_3857(3857);
REQUIRE(3857 == projection_3857.epsg());
REQUIRE("+init=epsg:3857" == projection_3857.proj_string());
{
const osmium::Location loc(4.2, 27.3);
REQUIRE(std::abs(projection_merc(loc).x - projection_3857(loc).x) < 0.1);
REQUIRE(std::abs(projection_merc(loc).y - projection_3857(loc).y) < 0.1);
}
{
const osmium::Location loc(160.789, -42.42);
REQUIRE(std::abs(projection_merc(loc).x - projection_3857(loc).x) < 0.1);
REQUIRE(std::abs(projection_merc(loc).y - projection_3857(loc).y) < 0.1);
}
{
const osmium::Location loc(-0.001, 0.001);
REQUIRE(std::abs(projection_merc(loc).x - projection_3857(loc).x) < 0.1);
REQUIRE(std::abs(projection_merc(loc).y - projection_3857(loc).y) < 0.1);
}
{
const osmium::Location loc(-85.2, -85.2);
REQUIRE(std::abs(projection_merc(loc).x - projection_3857(loc).x) < 0.1);
REQUIRE(std::abs(projection_merc(loc).y - projection_3857(loc).y) < 0.1);
}
}
}
+133
View File
@@ -0,0 +1,133 @@
#include "catch.hpp"
#include <osmium/builder/builder_helper.hpp>
#include <osmium/geom/wkb.hpp>
#include "../basic/helper.hpp"
#if __BYTE_ORDER == __LITTLE_ENDIAN
TEST_CASE("WKB_Geometry_byte_order_dependent") {
SECTION("point") {
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
std::string wkb {factory.create_point(osmium::Location(3.2, 4.2))};
REQUIRE(std::string{"01010000009A99999999990940CDCCCCCCCCCC1040"} == wkb);
}
SECTION("point_ewkb") {
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex);
std::string wkb {factory.create_point(osmium::Location(3.2, 4.2))};
REQUIRE(std::string{"0101000020E61000009A99999999990940CDCCCCCCCCCC1040"} == wkb);
}
SECTION("linestring") {
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
osmium::memory::Buffer buffer(10000);
auto& wnl = osmium::builder::build_way_node_list(buffer, {
{1, {3.2, 4.2}},
{3, {3.5, 4.7}},
{4, {3.5, 4.7}},
{2, {3.6, 4.9}}
});
{
std::string wkb {factory.create_linestring(wnl)};
REQUIRE(std::string{"0102000000030000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340"} == wkb);
}
{
std::string wkb {factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
REQUIRE(std::string{"010200000003000000CDCCCCCCCCCC0C409A999999999913400000000000000C40CDCCCCCCCCCC12409A99999999990940CDCCCCCCCCCC1040"} == wkb);
}
{
std::string wkb {factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
REQUIRE(std::string{"0102000000040000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340"} == wkb);
}
{
std::string wkb {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
REQUIRE(std::string{"010200000004000000CDCCCCCCCCCC0C409A999999999913400000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC12409A99999999990940CDCCCCCCCCCC1040"} == wkb);
}
}
SECTION("linestring_ewkb") {
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex);
osmium::memory::Buffer buffer(10000);
auto& wnl = osmium::builder::build_way_node_list(buffer, {
{1, {3.2, 4.2}},
{3, {3.5, 4.7}},
{4, {3.5, 4.7}},
{2, {3.6, 4.9}}
});
std::string ewkb {factory.create_linestring(wnl)};
REQUIRE(std::string{"0102000020E6100000030000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340"} == ewkb);
}
SECTION("linestring_with_two_same_locations") {
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
osmium::memory::Buffer buffer(10000);
auto& wnl = osmium::builder::build_way_node_list(buffer, {
{1, {3.5, 4.7}},
{2, {3.5, 4.7}}
});
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
{
std::string wkb {factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
REQUIRE(std::string{"0102000000020000000000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240"} == wkb);
}
{
std::string wkb {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
REQUIRE(std::string{"0102000000020000000000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240"} == wkb);
}
}
SECTION("linestring_with_undefined_location") {
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
osmium::memory::Buffer buffer(10000);
auto& wnl = osmium::builder::build_way_node_list(buffer, {
{1, {3.5, 4.7}},
{2, osmium::Location()}
});
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::invalid_location);
}
}
#endif
TEST_CASE("WKB_Geometry_byte_order_independent") {
SECTION("empty_point") {
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location);
}
SECTION("empty_linestring") {
osmium::geom::WKBFactory<> factory(osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex);
osmium::memory::Buffer buffer(10000);
auto& wnl = osmium::builder::build_way_node_list(buffer, {});
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all), osmium::geometry_error);
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward), osmium::geometry_error);
}
}
+198
View File
@@ -0,0 +1,198 @@
#include "catch.hpp"
#include <osmium/builder/builder_helper.hpp>
#include <osmium/geom/wkt.hpp>
#include "../basic/helper.hpp"
TEST_CASE("WKT_Geometry") {
SECTION("point") {
osmium::geom::WKTFactory<> factory;
std::string wkt {factory.create_point(osmium::Location(3.2, 4.2))};
REQUIRE(std::string{"POINT(3.2 4.2)"} == wkt);
}
SECTION("empty_point") {
osmium::geom::WKTFactory<> factory;
REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), osmium::invalid_location);
}
SECTION("linestring") {
osmium::geom::WKTFactory<> factory;
osmium::memory::Buffer buffer(10000);
auto& wnl = osmium::builder::build_way_node_list(buffer, {
{1, {3.2, 4.2}},
{3, {3.5, 4.7}},
{4, {3.5, 4.7}},
{2, {3.6, 4.9}}
});
{
std::string wkt {factory.create_linestring(wnl)};
REQUIRE(std::string{"LINESTRING(3.2 4.2,3.5 4.7,3.6 4.9)"} == wkt);
}
{
std::string wkt {factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
REQUIRE(std::string{"LINESTRING(3.6 4.9,3.5 4.7,3.2 4.2)"} == wkt);
}
{
std::string wkt {factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
REQUIRE(std::string{"LINESTRING(3.2 4.2,3.5 4.7,3.5 4.7,3.6 4.9)"} == wkt);
}
{
std::string wkt {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
REQUIRE(std::string{"LINESTRING(3.6 4.9,3.5 4.7,3.5 4.7,3.2 4.2)"} == wkt);
}
}
SECTION("empty_linestring") {
osmium::geom::WKTFactory<> factory;
osmium::memory::Buffer buffer(10000);
auto& wnl = osmium::builder::build_way_node_list(buffer, {});
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all), osmium::geometry_error);
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward), osmium::geometry_error);
}
SECTION("linestring_with_two_same_locations") {
osmium::geom::WKTFactory<> factory;
osmium::memory::Buffer buffer(10000);
auto& wnl = osmium::builder::build_way_node_list(buffer, {
{1, {3.5, 4.7}},
{2, {3.5, 4.7}}
});
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::geometry_error);
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), osmium::geometry_error);
{
std::string wkt {factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
REQUIRE(std::string{"LINESTRING(3.5 4.7,3.5 4.7)"} == wkt);
}
{
std::string wkt {factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
REQUIRE(std::string{"LINESTRING(3.5 4.7,3.5 4.7)"} == wkt);
}
}
SECTION("linestring_with_undefined_location") {
osmium::geom::WKTFactory<> factory;
osmium::memory::Buffer buffer(10000);
auto& wnl = osmium::builder::build_way_node_list(buffer, {
{1, {3.5, 4.7}},
{2, osmium::Location()}
});
REQUIRE_THROWS_AS(factory.create_linestring(wnl), osmium::invalid_location);
}
SECTION("area_1outer_0inner") {
osmium::geom::WKTFactory<> factory;
osmium::memory::Buffer buffer(10000);
osmium::Area& area = buffer_add_area(buffer,
"foo",
{},
{
{ true, {
{1, {3.2, 4.2}},
{2, {3.5, 4.7}},
{3, {3.6, 4.9}},
{1, {3.2, 4.2}}
}}
});
{
std::string wkt {factory.create_multipolygon(area)};
REQUIRE(std::string{"MULTIPOLYGON(((3.2 4.2,3.5 4.7,3.6 4.9,3.2 4.2)))"} == wkt);
}
}
SECTION("area_1outer_1inner") {
osmium::geom::WKTFactory<> factory;
osmium::memory::Buffer buffer(10000);
osmium::Area& area = buffer_add_area(buffer,
"foo",
{},
{
{ true, {
{1, {0.1, 0.1}},
{2, {9.1, 0.1}},
{3, {9.1, 9.1}},
{4, {0.1, 9.1}},
{1, {0.1, 0.1}}
}},
{ false, {
{5, {1.0, 1.0}},
{6, {8.0, 1.0}},
{7, {8.0, 8.0}},
{8, {1.0, 8.0}},
{5, {1.0, 1.0}}
}}
});
{
std::string wkt {factory.create_multipolygon(area)};
REQUIRE(std::string{"MULTIPOLYGON(((0.1 0.1,9.1 0.1,9.1 9.1,0.1 9.1,0.1 0.1),(1 1,8 1,8 8,1 8,1 1)))"} == wkt);
}
}
SECTION("area_2outer_2inner") {
osmium::geom::WKTFactory<> factory;
osmium::memory::Buffer buffer(10000);
osmium::Area& area = buffer_add_area(buffer,
"foo",
{},
{
{ true, {
{1, {0.1, 0.1}},
{2, {9.1, 0.1}},
{3, {9.1, 9.1}},
{4, {0.1, 9.1}},
{1, {0.1, 0.1}}
}},
{ false, {
{5, {1.0, 1.0}},
{6, {4.0, 1.0}},
{7, {4.0, 4.0}},
{8, {1.0, 4.0}},
{5, {1.0, 1.0}}
}},
{ false, {
{10, {5.0, 5.0}},
{11, {5.0, 7.0}},
{12, {7.0, 7.0}},
{10, {5.0, 5.0}}
}},
{ true, {
{100, {10.0, 10.0}},
{101, {11.0, 10.0}},
{102, {11.0, 11.0}},
{103, {10.0, 11.0}},
{100, {10.0, 10.0}}
}}
});
{
std::string wkt {factory.create_multipolygon(area)};
REQUIRE(std::string{"MULTIPOLYGON(((0.1 0.1,9.1 0.1,9.1 9.1,0.1 9.1,0.1 0.1),(1 1,4 1,4 4,1 4,1 1),(5 5,5 7,7 7,5 5)),((10 10,11 10,11 11,10 11,10 10)))"} == wkt);
}
}
}
@@ -0,0 +1,143 @@
#include "catch.hpp"
#include <osmium/osm/types.hpp>
#include <osmium/osm/location.hpp>
#include <osmium/index/map/dummy.hpp>
#include <osmium/index/map/sparse_table.hpp>
#include <osmium/index/map/stl_map.hpp>
#include <osmium/index/map/stl_vector.hpp>
#include <osmium/index/map/mmap_vector_anon.hpp>
#include <osmium/index/map/mmap_vector_file.hpp>
template <typename TIndex>
void test_func_all(TIndex& index) {
osmium::unsigned_object_id_type id1 = 12;
osmium::unsigned_object_id_type id2 = 3;
osmium::Location loc1(1.2, 4.5);
osmium::Location loc2(3.5, -7.2);
REQUIRE_THROWS_AS(index.get(id1), osmium::not_found);
index.set(id1, loc1);
index.set(id2, loc2);
index.sort();
REQUIRE_THROWS_AS(index.get(5), osmium::not_found);
REQUIRE_THROWS_AS(index.get(100), osmium::not_found);
}
template <typename TIndex>
void test_func_real(TIndex& index) {
osmium::unsigned_object_id_type id1 = 12;
osmium::unsigned_object_id_type id2 = 3;
osmium::Location loc1(1.2, 4.5);
osmium::Location loc2(3.5, -7.2);
index.set(id1, loc1);
index.set(id2, loc2);
index.sort();
REQUIRE(loc1 == index.get(id1));
REQUIRE(loc2 == index.get(id2));
REQUIRE_THROWS_AS(index.get(5), osmium::not_found);
REQUIRE_THROWS_AS(index.get(100), osmium::not_found);
index.clear();
REQUIRE_THROWS_AS(index.get(id1), osmium::not_found);
}
TEST_CASE("IdToLocation") {
SECTION("Dummy") {
typedef osmium::index::map::Dummy<osmium::unsigned_object_id_type, osmium::Location> index_type;
index_type index1;
REQUIRE(0 == index1.size());
REQUIRE(0 == index1.used_memory());
test_func_all<index_type>(index1);
REQUIRE(0 == index1.size());
REQUIRE(0 == index1.used_memory());
}
SECTION("DenseMapMem") {
typedef osmium::index::map::DenseMapMem<osmium::unsigned_object_id_type, osmium::Location> index_type;
index_type index1;
index1.reserve(1000);
test_func_all<index_type>(index1);
index_type index2;
index2.reserve(1000);
test_func_real<index_type>(index2);
}
#ifdef __linux__
SECTION("DenseMapMmap") {
typedef osmium::index::map::DenseMapMmap<osmium::unsigned_object_id_type, osmium::Location> index_type;
index_type index1;
test_func_all<index_type>(index1);
index_type index2;
test_func_real<index_type>(index2);
}
#else
# pragma message "not running 'DenseMapMmap' test case on this machine"
#endif
SECTION("DenseMapFile") {
typedef osmium::index::map::DenseMapFile<osmium::unsigned_object_id_type, osmium::Location> index_type;
index_type index1;
test_func_all<index_type>(index1);
index_type index2;
test_func_real<index_type>(index2);
}
SECTION("SparseTable") {
typedef osmium::index::map::SparseTable<osmium::unsigned_object_id_type, osmium::Location> index_type;
index_type index1;
test_func_all<index_type>(index1);
index_type index2;
test_func_real<index_type>(index2);
}
SECTION("StlMap") {
typedef osmium::index::map::StlMap<osmium::unsigned_object_id_type, osmium::Location> index_type;
index_type index1;
test_func_all<index_type>(index1);
index_type index2;
test_func_real<index_type>(index2);
}
SECTION("SparseMapMem") {
typedef osmium::index::map::SparseMapMem<osmium::unsigned_object_id_type, osmium::Location> index_type;
index_type index1;
REQUIRE(0 == index1.size());
REQUIRE(0 == index1.used_memory());
test_func_all<index_type>(index1);
REQUIRE(2 == index1.size());
index_type index2;
test_func_real<index_type>(index2);
}
}
+95
View File
@@ -0,0 +1,95 @@
#include "catch.hpp"
#include <osmium/index/detail/typed_mmap.hpp>
#if defined(_MSC_VER) || (defined(__GNUC__) && defined(_WIN32))
#include "win_mkstemp.hpp"
#endif
TEST_CASE("TypedMmap") {
SECTION("Mmap") {
uint64_t* data = osmium::detail::typed_mmap<uint64_t>::map(10);
data[0] = 4ul;
data[3] = 9ul;
data[9] = 25ul;
REQUIRE(4ul == data[0]);
REQUIRE(9ul == data[3]);
REQUIRE(25ul == data[9]);
osmium::detail::typed_mmap<uint64_t>::unmap(data, 10);
}
SECTION("MmapSizeZero") {
REQUIRE_THROWS_AS(osmium::detail::typed_mmap<uint64_t>::map(0), std::system_error);
}
SECTION("MmapHugeSize") {
// this is a horrible hack to only run the test on 64bit machines.
if (sizeof(size_t) >= 8) {
REQUIRE_THROWS_AS(osmium::detail::typed_mmap<uint64_t>::map(1ULL << (sizeof(size_t) * 6)), std::system_error);
}
}
#ifdef __linux__
SECTION("Remap") {
uint64_t* data = osmium::detail::typed_mmap<uint64_t>::map(10);
data[0] = 4ul;
data[3] = 9ul;
data[9] = 25ul;
uint64_t* new_data = osmium::detail::typed_mmap<uint64_t>::remap(data, 10, 1000);
REQUIRE(4ul == new_data[0]);
REQUIRE(9ul == new_data[3]);
REQUIRE(25ul == new_data[9]);
}
#else
# pragma message "not running 'Remap' test case on this machine"
#endif
SECTION("FileSize") {
const int size = 100;
char filename[] = "/tmp/osmium_unit_test_XXXXXX";
const int fd = mkstemp(filename);
REQUIRE(fd > 0);
REQUIRE(0 == unlink(filename));
REQUIRE(0 == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
REQUIRE(0 == ftruncate(fd, size * sizeof(uint64_t)));
REQUIRE(size == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
osmium::detail::typed_mmap<uint64_t>::grow_file(size / 2, fd);
REQUIRE(size == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
osmium::detail::typed_mmap<uint64_t>::grow_file(size, fd);
REQUIRE(size == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
osmium::detail::typed_mmap<uint64_t>::grow_file(size * 2, fd);
REQUIRE((size * 2) == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
}
SECTION("GrowAndMap") {
const int size = 100;
char filename[] = "/tmp/osmium_unit_test_XXXXXX";
const int fd = mkstemp(filename);
REQUIRE(fd > 0);
REQUIRE(0 == unlink(filename));
uint64_t* data = osmium::detail::typed_mmap<uint64_t>::grow_and_map(size, fd);
REQUIRE(size == osmium::detail::typed_mmap<uint64_t>::file_size(fd));
data[0] = 1ul;
data[1] = 8ul;
data[99] = 27ul;
REQUIRE(1ul == data[0]);
REQUIRE(8ul == data[1]);
REQUIRE(27ul == data[99]);
osmium::detail::typed_mmap<uint64_t>::unmap(data, size);
}
}
+4
View File
@@ -0,0 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<osm version="0.6" generator="testdata" upload="false">
<node id="1" version="1" timestamp="2014-01-01T00:00:00Z" uid="1" user="test" changeset="1" lon="1.02" lat="1.02"/>
</osm>
Binary file not shown.
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
TESTDATA
Binary file not shown.
+30
View File
@@ -0,0 +1,30 @@
#include "catch.hpp"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <osmium/io/bzip2_compression.hpp>
TEST_CASE("Bzip2") {
SECTION("read_compressed_file") {
int fd = ::open("t/io/data_bzip2.txt.bz2", O_RDONLY);
REQUIRE(fd > 0);
size_t size = 0;
std::string all;
{
osmium::io::Bzip2Decompressor decomp(fd);
for (std::string data = decomp.read(); !data.empty(); data = decomp.read()) {
size += data.size();
all += data;
}
}
REQUIRE(9 == size);
REQUIRE("TESTDATA\n" == all);
}
}
+251
View File
@@ -0,0 +1,251 @@
#include "catch.hpp"
#include <iterator>
#include <osmium/io/file.hpp>
TEST_CASE("FileFormats") {
SECTION("default_file_format") {
osmium::io::File f;
REQUIRE(osmium::io::file_format::unknown == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
SECTION("stdin_stdout_empty") {
osmium::io::File f {""};
REQUIRE(osmium::io::file_format::unknown == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
SECTION("stdin_stdout_dash") {
osmium::io::File f {"-"};
REQUIRE(osmium::io::file_format::unknown == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
SECTION("stdin_stdout_bz2") {
osmium::io::File f {"-", "osm.bz2"};
REQUIRE("" == f.filename());
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::bzip2 == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_osm") {
osmium::io::File f {"test.osm"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_pbf") {
osmium::io::File f {"test.pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_osm_pbf") {
osmium::io::File f {"test.osm.pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_opl") {
osmium::io::File f {"test.opl"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_osm_opl") {
osmium::io::File f {"test.osm.opl"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_osm_gz") {
osmium::io::File f {"test.osm.gz"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_opl_bz2") {
osmium::io::File f {"test.osm.opl.bz2"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::bzip2 == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_osc_gz") {
osmium::io::File f {"test.osc.gz"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_opl_gz") {
osmium::io::File f {"test.osh.opl.gz"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
SECTION("detect_file_format_by_suffix_osh_pbf") {
osmium::io::File f {"test.osh.pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_osm") {
osmium::io::File f {"test", "osm"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_pbf") {
osmium::io::File f {"test", "pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_osm_pbf") {
osmium::io::File f {"test", "osm.pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_opl") {
osmium::io::File f {"test", "opl"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_osm_opl") {
osmium::io::File f {"test", "osm.opl"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_osm_gz") {
osmium::io::File f {"test", "osm.gz"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_osm_opl_bz2") {
osmium::io::File f {"test", "osm.opl.bz2"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::bzip2 == f.compression());
REQUIRE(false == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_osc_gz") {
osmium::io::File f {"test", "osc.gz"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_osh_opl_gz") {
osmium::io::File f {"test", "osh.opl.gz"};
REQUIRE(osmium::io::file_format::opl == f.format());
REQUIRE(osmium::io::file_compression::gzip == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
SECTION("override_file_format_by_suffix_osh_pbf") {
osmium::io::File f {"test", "osh.pbf"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
SECTION("format_options_pbf_history") {
osmium::io::File f {"test", "pbf,history=true"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE(true == f.has_multiple_object_versions());
f.check();
}
SECTION("format_options_pbf_foo") {
osmium::io::File f {"test.osm", "pbf,foo=bar"};
REQUIRE(osmium::io::file_format::pbf == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE("bar" == f.get("foo"));
f.check();
}
SECTION("format_options_xml_abc_something") {
osmium::io::File f {"test.bla", "xml,abc,some=thing"};
REQUIRE(osmium::io::file_format::xml == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE("true" == f.get("abc"));
REQUIRE("thing" == f.get("some"));
REQUIRE(2 == std::distance(f.begin(), f.end()));
f.check();
}
SECTION("unknown_format_foo_bar") {
osmium::io::File f {"test.foo.bar"};
REQUIRE(osmium::io::file_format::unknown == f.format());
REQUIRE(osmium::io::file_compression::none == f.compression());
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
SECTION("unknown_format_foo") {
osmium::io::File f {"test", "foo"};
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
SECTION("unknown_format_osm_foo") {
osmium::io::File f {"test", "osm.foo"};
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
SECTION("unknown_format_bla_equals_foo") {
osmium::io::File f {"test", "bla=foo"};
REQUIRE_THROWS_AS(f.check(), std::runtime_error);
}
}
+116
View File
@@ -0,0 +1,116 @@
#include "catch.hpp"
#include <osmium/handler.hpp>
#include <osmium/io/any_compression.hpp>
#include <osmium/io/xml_input.hpp>
#include <osmium/visitor.hpp>
#include <osmium/memory/buffer.hpp>
struct CountHandler : public osmium::handler::Handler {
int count = 0;
void node(osmium::Node&) {
++count;
}
}; // class CountHandler
TEST_CASE("Reader") {
SECTION("reader can be initialized with file") {
osmium::io::File file("t/io/data.osm");
osmium::io::Reader reader(file);
osmium::handler::Handler handler;
osmium::apply(reader, handler);
}
SECTION("reader can be initialized with string") {
osmium::io::Reader reader("t/io/data.osm");
osmium::handler::Handler handler;
osmium::apply(reader, handler);
}
SECTION("should return invalid buffer after eof") {
osmium::io::File file("t/io/data.osm");
osmium::io::Reader reader(file);
REQUIRE(!reader.eof());
while (osmium::memory::Buffer buffer = reader.read()) {
}
REQUIRE(reader.eof());
// extra read always returns invalid buffer
osmium::memory::Buffer buffer = reader.read();
REQUIRE(!buffer);
}
SECTION("should not hang when apply() is called twice on reader") {
osmium::io::File file("t/io/data.osm");
osmium::io::Reader reader(file);
osmium::handler::Handler handler;
osmium::apply(reader, handler);
osmium::apply(reader, handler);
}
SECTION("should work with a buffer with uncompressed data") {
int fd = osmium::io::detail::open_for_reading("t/io/data.osm");
REQUIRE(fd >= 0);
const size_t buffer_size = 1000;
char buffer[buffer_size];
ssize_t length = ::read(fd, buffer, buffer_size);
REQUIRE(length > 0);
osmium::io::File file(buffer, static_cast<size_t>(length), "osm");
osmium::io::Reader reader(file);
CountHandler handler;
REQUIRE(handler.count == 0);
osmium::apply(reader, handler);
REQUIRE(handler.count == 1);
}
SECTION("should work with a buffer with gzip-compressed data") {
int fd = osmium::io::detail::open_for_reading("t/io/data.osm.gz");
REQUIRE(fd >= 0);
const size_t buffer_size = 1000;
char buffer[buffer_size];
ssize_t length = ::read(fd, buffer, buffer_size);
REQUIRE(length > 0);
osmium::io::File file(buffer, static_cast<size_t>(length), "osm.gz");
osmium::io::Reader reader(file);
CountHandler handler;
REQUIRE(handler.count == 0);
osmium::apply(reader, handler);
REQUIRE(handler.count == 1);
}
SECTION("should work with a buffer with bzip2-compressed data") {
int fd = osmium::io::detail::open_for_reading("t/io/data.osm.bz2");
REQUIRE(fd >= 0);
const size_t buffer_size = 1000;
char buffer[buffer_size];
ssize_t length = ::read(fd, buffer, buffer_size);
REQUIRE(length > 0);
osmium::io::File file(buffer, static_cast<size_t>(length), "osm.bz2");
osmium::io::Reader reader(file);
CountHandler handler;
REQUIRE(handler.count == 0);
osmium::apply(reader, handler);
REQUIRE(handler.count == 1);
}
}
+216
View File
@@ -0,0 +1,216 @@
#include "catch.hpp"
#include <algorithm>
#include <osmium/builder/builder_helper.hpp>
#include <osmium/memory/buffer.hpp>
#include <osmium/osm/tag.hpp>
#include <osmium/tags/taglist.hpp>
#include <osmium/tags/filter.hpp>
#include <osmium/tags/regex_filter.hpp>
template <class TFilter>
void check_filter(const osmium::TagList& tag_list, const TFilter filter, const std::vector<bool>& reference) {
REQUIRE(tag_list.size() == reference.size());
auto t_it = tag_list.begin();
for (auto it = reference.begin(); it != reference.end(); ++t_it, ++it) {
REQUIRE(filter(*t_it) == *it);
}
typename TFilter::iterator fi_begin(filter, tag_list.begin(), tag_list.end());
typename TFilter::iterator fi_end(filter, tag_list.end(), tag_list.end());
REQUIRE(std::distance(fi_begin, fi_end) == std::count(reference.begin(), reference.end(), true));
}
TEST_CASE("Filter") {
SECTION("KeyFilter_matches_some_tags") {
osmium::tags::KeyFilter filter(false);
filter.add(true, "highway").add(true, "railway");
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" }, // match
{ "name", "Main Street" }, // no match
{ "source", "GPS" } // no match
});
std::vector<bool> results = { true, false, false };
check_filter(tag_list, filter, results);
}
SECTION("KeyFilter_iterator_filters_tags") {
osmium::tags::KeyFilter filter(false);
filter.add(true, "highway").add(true, "source");
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tl = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" }, // match
{ "name", "Main Street" }, // no match
{ "source", "GPS" } // no match
});
osmium::tags::KeyFilter::iterator it(filter, tl.begin(), tl.end());
const osmium::tags::KeyFilter::iterator end(filter, tl.end(), tl.end());
REQUIRE(2 == std::distance(it, end));
REQUIRE(it != end);
REQUIRE(std::string("highway") == it->key());
REQUIRE(std::string("primary") == it->value());
++it;
REQUIRE(std::string("source") == it->key());
REQUIRE(std::string("GPS") == it->value());
REQUIRE(++it == end);
}
SECTION("KeyValueFilter_matches_some_tags") {
osmium::tags::KeyValueFilter filter(false);
filter.add(true, "highway", "residential").add(true, "highway", "primary").add(true, "railway");
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" },
{ "railway", "tram" },
{ "source", "GPS" }
});
std::vector<bool> results = {true, true, false};
check_filter(tag_list, filter, results);
}
SECTION("KeyValueFilter_ordering_matters") {
osmium::tags::KeyValueFilter filter1(false);
filter1.add(true, "highway").add(false, "highway", "road");
osmium::tags::KeyValueFilter filter2(false);
filter2.add(false, "highway", "road").add(true, "highway");
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list1 = osmium::builder::build_tag_list(buffer, {
{ "highway", "road" },
{ "name", "Main Street" }
});
const osmium::TagList& tag_list2 = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" },
{ "name", "Main Street" }
});
check_filter(tag_list1, filter1, {true, false});
check_filter(tag_list1, filter2, {false, false});
check_filter(tag_list2, filter2, {true, false});
}
SECTION("KeyValueFilter_matches_against_taglist_with_any") {
osmium::tags::KeyValueFilter filter(false);
filter.add(true, "highway", "primary").add(true, "name");
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" },
{ "railway", "tram" },
{ "source", "GPS" }
});
REQUIRE( osmium::tags::match_any_of(tag_list, filter));
REQUIRE(!osmium::tags::match_all_of(tag_list, filter));
REQUIRE(!osmium::tags::match_none_of(tag_list, filter));
}
SECTION("KeyValueFilter_matches_against_taglist_with_all") {
osmium::tags::KeyValueFilter filter(false);
filter.add(true, "highway", "primary").add(true, "name");
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" },
{ "name", "Main Street" }
});
REQUIRE( osmium::tags::match_any_of(tag_list, filter));
REQUIRE( osmium::tags::match_all_of(tag_list, filter));
REQUIRE(!osmium::tags::match_none_of(tag_list, filter));
}
SECTION("KeyValueFilter_matches_against_taglist_with_none") {
osmium::tags::KeyValueFilter filter(false);
filter.add(true, "highway", "road").add(true, "source");
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" },
{ "name", "Main Street" }
});
REQUIRE(!osmium::tags::match_any_of(tag_list, filter));
REQUIRE(!osmium::tags::match_all_of(tag_list, filter));
REQUIRE( osmium::tags::match_none_of(tag_list, filter));
}
SECTION("KeyValueFilter_matches_against_taglist_with_any_called_with_rvalue") {
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" },
{ "railway", "tram" },
{ "source", "GPS" }
});
REQUIRE(osmium::tags::match_any_of(tag_list,
osmium::tags::KeyValueFilter().add(true, "highway", "primary").add(true, "name")));
}
SECTION("RegexFilter_matches_some_tags") {
osmium::tags::RegexFilter filter(false);
filter.add(true, "highway", std::regex(".*_link"));
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list1 = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary_link" },
{ "source", "GPS" }
});
const osmium::TagList& tag_list2 = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" },
{ "source", "GPS" }
});
check_filter(tag_list1, filter, {true, false});
check_filter(tag_list2, filter, {false, false});
}
SECTION("RegexFilter_matches_some_tags_with_lvalue_regex") {
osmium::tags::RegexFilter filter(false);
std::regex r(".*straße");
filter.add(true, "name", r);
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" },
{ "name", "Hauptstraße" }
});
check_filter(tag_list, filter, {false, true});
}
SECTION("KeyPrefixFilter_matches_some_tags") {
osmium::tags::KeyPrefixFilter filter(false);
filter.add(true, "name:");
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tag_list = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" },
{ "name:de", "Hauptstraße" }
});
check_filter(tag_list, filter, {false, true});
}
}
+61
View File
@@ -0,0 +1,61 @@
#include "catch.hpp"
#include <iterator>
#include <osmium/builder/osm_object_builder.hpp>
#include <osmium/memory/buffer.hpp>
#include <osmium/osm/tag.hpp>
TEST_CASE("Operators") {
SECTION("Equal") {
osmium::memory::Buffer buffer1(10240);
{
osmium::builder::TagListBuilder tl_builder(buffer1);
tl_builder.add_tag("highway", "primary");
tl_builder.add_tag("name", "Main Street");
tl_builder.add_tag("source", "GPS");
}
buffer1.commit();
osmium::memory::Buffer buffer2(10240);
{
osmium::builder::TagListBuilder tl_builder(buffer2);
tl_builder.add_tag("highway", "primary");
}
buffer2.commit();
const osmium::TagList& tl1 = buffer1.get<const osmium::TagList>(0);
const osmium::TagList& tl2 = buffer2.get<const osmium::TagList>(0);
auto tagit1 = tl1.begin();
auto tagit2 = tl2.begin();
REQUIRE(*tagit1 == *tagit2);
++tagit1;
REQUIRE(!(*tagit1 == *tagit2));
}
SECTION("Order") {
osmium::memory::Buffer buffer(10240);
{
osmium::builder::TagListBuilder tl_builder(buffer);
tl_builder.add_tag("highway", "residential");
tl_builder.add_tag("highway", "primary");
tl_builder.add_tag("name", "Main Street");
tl_builder.add_tag("amenity", "post_box");
}
buffer.commit();
const osmium::TagList& tl = buffer.get<const osmium::TagList>(0);
const osmium::Tag& t1 = *(tl.begin());
const osmium::Tag& t2 = *(std::next(tl.begin(), 1));
const osmium::Tag& t3 = *(std::next(tl.begin(), 2));
const osmium::Tag& t4 = *(std::next(tl.begin(), 3));
REQUIRE(t2 < t1);
REQUIRE(t1 < t3);
REQUIRE(t2 < t3);
REQUIRE(t4 < t1);
}
}
+76
View File
@@ -0,0 +1,76 @@
#include "catch.hpp"
#include <osmium/builder/builder_helper.hpp>
#include <osmium/memory/buffer.hpp>
#include <osmium/osm/tag.hpp>
TEST_CASE("tag_list") {
SECTION("can_be_created_from_initializer_list") {
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tl = osmium::builder::build_tag_list(buffer, {
{ "highway", "primary" },
{ "name", "Main Street" },
{ "source", "GPS" }
});
REQUIRE(osmium::item_type::tag_list == tl.type());
REQUIRE(3 == tl.size());
REQUIRE(std::string("highway") == tl.begin()->key());
REQUIRE(std::string("primary") == tl.begin()->value());
}
SECTION("can_be_created_from_map") {
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tl = osmium::builder::build_tag_list_from_map(buffer, std::map<const char*, const char*>({
{ "highway", "primary" },
{ "name", "Main Street" }
}));
REQUIRE(osmium::item_type::tag_list == tl.type());
REQUIRE(2 == tl.size());
if (std::string("highway") == tl.begin()->key()) {
REQUIRE(std::string("primary") == tl.begin()->value());
REQUIRE(std::string("name") == std::next(tl.begin(), 1)->key());
REQUIRE(std::string("Main Street") == std::next(tl.begin(), 1)->value());
} else {
REQUIRE(std::string("highway") == std::next(tl.begin(), 1)->key());
REQUIRE(std::string("primary") == std::next(tl.begin(), 1)->value());
REQUIRE(std::string("name") == tl.begin()->key());
REQUIRE(std::string("Main Street") == tl.begin()->value());
}
}
SECTION("can_be_created_with_callback") {
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tl = osmium::builder::build_tag_list_from_func(buffer, [](osmium::builder::TagListBuilder& tlb) {
tlb.add_tag("highway", "primary");
tlb.add_tag("bridge", "true");
});
REQUIRE(osmium::item_type::tag_list == tl.type());
REQUIRE(2 == tl.size());
REQUIRE(std::string("bridge") == std::next(tl.begin(), 1)->key());
REQUIRE(std::string("true") == std::next(tl.begin(), 1)->value());
}
SECTION("returns_value_by_key") {
osmium::memory::Buffer buffer(10240);
const osmium::TagList& tl = osmium::builder::build_tag_list_from_func(buffer, [](osmium::builder::TagListBuilder& tlb) {
tlb.add_tag("highway", "primary");
tlb.add_tag("bridge", "true");
});
REQUIRE(std::string("primary") == tl.get_value_by_key("highway"));
REQUIRE(nullptr == tl.get_value_by_key("name"));
REQUIRE(std::string("foo") == tl.get_value_by_key("name", "foo"));
REQUIRE(std::string("true") == tl["bridge"]);
}
}
+33
View File
@@ -0,0 +1,33 @@
#include "catch.hpp"
#include <osmium/util/double.hpp>
TEST_CASE("Double") {
SECTION("double2string") {
std::string s1;
osmium::util::double2string(s1, 1.123, 7);
REQUIRE(s1 == "1.123");
std::string s2;
osmium::util::double2string(s2, 1.000, 7);
REQUIRE(s2 == "1");
std::string s3;
osmium::util::double2string(s3, 0.0, 7);
REQUIRE(s3 == "0");
std::string s4;
osmium::util::double2string(s4, 0.020, 7);
REQUIRE(s4 == "0.02");
std::string s5;
osmium::util::double2string(s5, -0.020, 7);
REQUIRE(s5 == "-0.02");
std::string s6;
osmium::util::double2string(s6, -0.0, 7);
REQUIRE(s6 == "-0");
}
}
+48
View File
@@ -0,0 +1,48 @@
#include "catch.hpp"
#include <iterator>
#include <osmium/util/options.hpp>
TEST_CASE("Options") {
SECTION("set_simple") {
osmium::util::Options o;
o.set("foo", "bar");
REQUIRE("bar" == o.get("foo"));
REQUIRE("" == o.get("empty"));
REQUIRE("default" == o.get("empty", "default"));
REQUIRE(!o.is_true("foo"));
REQUIRE(!o.is_true("empty"));
REQUIRE(1 == o.size());
}
SECTION("set_from_bool") {
osmium::util::Options o;
o.set("t", true);
o.set("f", false);
REQUIRE("true" == o.get("t"));
REQUIRE("false" == o.get("f"));
REQUIRE("" == o.get("empty"));
REQUIRE(o.is_true("t"));
REQUIRE(!o.is_true("f"));
REQUIRE(2 == o.size());
}
SECTION("set_from_single_string_with_equals") {
osmium::util::Options o;
o.set("foo=bar");
REQUIRE("bar" == o.get("foo"));
REQUIRE(1 == o.size());
}
SECTION("set_from_single_string_without_equals") {
osmium::util::Options o;
o.set("foo");
REQUIRE("true" == o.get("foo"));
REQUIRE(o.is_true("foo"));
REQUIRE(1 == o.size());
}
}
+57
View File
@@ -0,0 +1,57 @@
#include "catch.hpp"
#include <osmium/util/string.hpp>
TEST_CASE("split_string") {
SECTION("split_string string") {
std::string str { "foo,baramba,baz" };
std::vector<std::string> result = {"foo", "baramba", "baz"};
REQUIRE(result == osmium::split_string(str, ','));
}
SECTION("split_string string without sep") {
std::string str { "foo" };
std::vector<std::string> result = {"foo"};
REQUIRE(result == osmium::split_string(str, ','));
}
SECTION("split_string string with empty at end") {
std::string str { "foo,bar," };
std::vector<std::string> result = {"foo", "bar", ""};
REQUIRE(result == osmium::split_string(str, ','));
}
SECTION("split_string string with empty in middle") {
std::string str { "foo,,bar" };
std::vector<std::string> result = {"foo", "", "bar"};
REQUIRE(result == osmium::split_string(str, ','));
}
SECTION("split_string string with empty at start") {
std::string str { ",bar,baz" };
std::vector<std::string> result = {"", "bar", "baz"};
REQUIRE(result == osmium::split_string(str, ','));
}
SECTION("split_string sep") {
std::string str { "," };
std::vector<std::string> result = {"", ""};
REQUIRE(result == osmium::split_string(str, ','));
}
SECTION("split_string empty string") {
std::string str { "" };
std::vector<std::string> result;
REQUIRE(result == osmium::split_string(str, ','));
}
}
+2
View File
@@ -0,0 +1,2 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
+38
View File
@@ -0,0 +1,38 @@
{
dl_error1
Memcheck:Cond
fun:index
fun:expand_dynamic_string_token
fun:fillin_rpath
fun:_dl_init_paths
fun:dl_main
fun:_dl_sysdep_start
fun:_dl_start
}
{
dl_error2
Memcheck:Cond
fun:index
fun:expand_dynamic_string_token
fun:_dl_map_object
fun:map_doit
fun:_dl_catch_error
fun:do_preload
fun:dl_main
fun:_dl_sysdep_start
fun:_dl_start
}
{
libpoppler_leak
Memcheck:Leak
fun:malloc
fun:gmalloc
fun:copyString
}
{
tmpfile
Memcheck:Leak
fun:malloc
fun:fdopen@@GLIBC_*
fun:tmpfile@@GLIBC_*
}