Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) BoostGeometryExample12

 

BoostQt CreatorLubuntu

 

Boost.Geometry example 12: Create a linestring from WKT is a Boost.Geometry example.

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppBoostGeometryExample12/CppBoostGeometryExample12.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

 

 

 

 

 

./CppBoostGeometryExample12/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/algorithms/intersection.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/io/wkt/read.hpp>
#include <boost/geometry/io/wkt/write.hpp>
#include <boost/geometry/io/wkt/wkt.hpp>
#pragma GCC diagnostic pop

// 5 +
//   |
// 4 +   *---*
//   |   |   |
// 3 + *-+-* |
//   | | | | |
// 2 + | * | *
//   | |   |
// 1 + *   *
//   |
// 0 +-+-+-+-+-+
//   0 1 2 3 4 5

int main()
{
  typedef boost::geometry::model::d2::point_xy<double> Point;
  typedef boost::geometry::model::linestring<Point> Linestring;
  typedef std::vector<Point> Points;

  Linestring linestring_a;
  boost::geometry::read_wkt(
    "LINESTRING(1.0 1.0, 1.0 3.0, 3.0 3.0, 3.0 1.0)",
    linestring_a
  );

  Linestring linestring_b;
  boost::geometry::read_wkt(
    "LINESTRING(2.0 2.0, 2.0 4.0, 4.0 4.0, 4.0 2.0)",
    linestring_b
  );

  assert(boost::geometry::intersects(linestring_a,linestring_b));
  Points results_found;
  boost::geometry::intersection(linestring_a,linestring_b,results_found);

  assert(results_found.size() == 1);

  std::cout
    << "Found:" << '\n'
    << "#points: " << results_found.size() << '\n'
  ;
  for (const auto result: results_found)
  {
    std::cout << boost::geometry::wkt<Point>(result) << '\n';
  }
}

/* Screen output:

Found:
#points: 1
POINT(2 3)
Press <RETURN> to close this window...

*/

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml