CPP/Boost/Geometry/Simplify

From ProgrammingExamples

< CPP
Jump to: navigation, search

Simplify.cpp

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/linestring.hpp>
 
#include <iostream>
 
int main ()
{
  typedef boost::geometry::model::d2::point_xy<double> xy;
 
  boost::geometry::model::linestring<xy> line;
  //line += xy(1.1, 1.1), xy(2.5, 2.1), xy(3.1, 3.1), xy(4.9, 1.1), xy(3.1, 1.9);
  line.push_back(xy(1.1, 1.1));
  line.push_back(xy(2.5, 2.1));
  line.push_back(xy(3.1, 3.1));
  line.push_back(xy(4.9, 1.1));
  line.push_back(xy(3.1, 1.9));
 
  // Simplify it, using distance of 0.5 units
  boost::geometry::model::linestring<xy> simplified;
  boost::geometry::simplify(line, simplified, 0.5);
  std::cout
      << "  original: " << boost::geometry::dsv(line) << std::endl
      << "simplified: " << boost::geometry::dsv(simplified) << std::endl;
  return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
 
Project(Simplify)
 
set(Boost_USE_MULTITHREADED ON)
FIND_PACKAGE(Boost 1.38 COMPONENTS required)
 
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${LINK_DIRECTORIES} ${Boost_LIBRARY_DIRS})
 
ADD_EXECUTABLE(Simplify Simplify.cpp)
Personal tools