(C++) BoostGeometryExample14
February 24, 2017 · View on GitHub
(C++) BoostGeometryExample14



Boost.Geometry example 14: Convert points to a linestring and back is a Boost.Geometry example.
Technical facts
Operating system(s) or programming environment(s)
Lubuntu 15.04 (vivid)
Qt Creator 3.1.1
- G++ 4.9.2
Libraries used:
Qt project file: ./CppBoostGeometryExample14/CppBoostGeometryExample14.pro
exists(../../ConsoleApplication.pri) { include(../../ConsoleApplication.pri) } !exists(../../ConsoleApplication.pri) { QT += core QT += gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += console CONFIG -= app_bundle TEMPLATE = app CONFIG(release, debug|release) { DEFINES += NDEBUG NTRACE_BILDERBIKKEL } QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++ unix { QMAKE_CXXFLAGS += -Werror } } exists(../../Libraries/Boost.pri) { include(../../Libraries/Boost.pri) } !exists(../../Libraries/Boost.pri) { win32 { INCLUDEPATH += \ ../../Libraries/boost_1_55_0 } } SOURCES += main.cpp
./CppBoostGeometryExample14/main.cpp
#include <cassert> #include <iostream> #include <vector> #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Weffc++" #pragma GCC diagnostic ignored "-Wunused-local-typedefs" #pragma GCC diagnostic ignored "-Wunused-variable" #include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> #include <boost/geometry/geometries/linestring.hpp> #pragma GCC diagnostic pop int main() { typedef boost::geometry::model::d2::point_xy<double> Point; typedef boost::geometry::model::linestring<Point> Linestring; //Obtain the points const std::vector<Point> points { {1.2,3.4}, {2.3,4.5}, {3.4,5.6}, {4.5,6.7} }; //Create a linestring from these points Linestring linestring; boost::geometry::append(linestring, points); assert(boost::geometry::num_points(linestring) == 4); //Create the points back again from that linestring const std::vector<Point> points_again = linestring; //Initial and re-created points must be equal assert( std::equal(points.begin(),points.end(),points_again.begin(), [](const boost::geometry::model::d2::point_xy<double>& a, const boost::geometry::model::d2::point_xy<double>& b) { return boost::geometry::equals(a,b); } ) ); }