Boost Geometry
Introduction*
Boost.Geometry (aka Generic Geometry Library, GGL), part of collection of the Boost C++ Libraries, defines concepts, primitives and algorithms for solving geometry problems.
Boost.Geometry contains a dimension-agnostic, coordinate-system-agnostic and scalable kernel, based on concepts, meta-functions and tag dispatching. On top of that kernel, algorithms are built: area, length, perimeter, centroid, convex hull, intersection (clipping), within (point in polygon), distance, envelope (bounding box), simplify, transform, and much more. The library supports high precision arithmetic numbers, such as ttmath
.
Boost.Geometry contains instantiable geometry classes, but library users can also use their own. Using registration macros or traits classes their geometries can be adapted to fulfil Boost.Geometry concepts.
Boost.Geometry might be used in all domains where geometry plays a role: mapping and GIS, game development, computer graphics and widgets, robotics, astronomy and more. The core is designed to be as generic as possible and support those domains. For now, the development has been mostly GIS-oriented.
The library follows existing conventions:
- conventions from boost
- conventions from the std library
- conventions and names from one of the OGC standards on geometry and, more specificly, from the OGC Simple Feature Specification
Coordinate Systems in Boost.Geometry
These are:
- cs::cartesian
- cs::spherical
- cs::spherical_equatorial
- cs::geographic
To use these tags type either:
#include <boost/geometry.hpp>
or
#include <boost/geometry/core/cs.hpp>
Quick Start
This Quick Start section shows some of the features of Boost.Geometry in the form of annotated, relatively simple, code snippets.
The code below assumes that boost/geometry.hpp is included, and that namespace boost::geometry is used. Boost.Geometry is header only, so including headerfiles is enough. No linking with any library is necessary.
#include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> #include <boost/geometry/geometries/polygon.hpp> using namespace boost::geometry;
Cartesian Coordinates
It is possible to use only a small part of the library. For example: the distance between two points is a common use case. Boost.Geometry can calculate it from various types. Using one of its own types:
model::d2::point_xy<t>int> p1(1, 1), p2(2, 2); std::cout << "Distance p1-p2 is: " << distance(p1, p2) << std::endl;
If the right headers are included and the types are bound to a coordinate system, various other types can be used as points: plain C array's, Boost.Array's, Boost.Tuple's, Boost.Fusion imported structs, your own classes...
Registering and using a C array:
#include <boost/geometry/geometries/adapted/c_array.hpp> BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) int a[2] = {1,1}; int b[2] = {2,3}; double d = distance(a, b); std::cout << "Distance a-b is: " << d << std::endl;
Another often used algorithm is point-in-polygon. It is implemented in Boost.Geometry under the name
But it is first necessary to register a Boost.Tuple, like the C array:
#include <boost/geometry/geometries/adapted/boost_tuple.hpp> BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) double points[][2] = {{2.0, 1.3}, {4.1, 3.0}, {5.3, 2.6}, {2.9, 0.7}, {2.0, 1.3}}; model::polygon<model::d2::point_xy<double> > poly; append(poly, points); boost::tuple<double, double> p = boost::make_tuple(3.7, 2.0); std::cout << "Point p is in polygon? " << std::boolalpha << within(p, poly) << std::endl;
We can calculate the area of a polygon:
std::cout << "Area: " << area(poly) << std::endl;
By the nature of a template library, it is possible to mix point types. We calculate distance again, now using a C array point and a Boost.Tuple point:
double d2 = distance(a, p); std::cout << "Distance a-p is: " << d2 << std::endl;
The snippets listed above generate the following output:
Distance p1-p2 is: 1.41421 Distance a-b is: 2.23607 Point p is in polygon? true Area: 3.015 Distance a-p is: 2.87924
Non-Cartesian Coordinates
It is also possible to use non-Cartesian points. For example: points on a sphere. When then an algorithm such as distance is used the library realizes
that it is handling spherical points and calculates the distance over the sphere, instead of applying the Pythagorean theorem.
Boost.Geometry supports a geographical coordinate system, but that is in an extension and not released in the current Boost release.
We approximate the Earth as a sphere and calculate the distance between Amsterdam and Paris:
typedef boost::geometry::model::point < double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree> > spherical_point; spherical_point amsterdam(4.90, 52.37); spherical_point paris(2.35, 48.86); double const earth_radius = 3959; // miles std::cout << "Distance in miles: " << distance(amsterdam, paris) * earth_radius << std::endl;
Output:
Distance in miles: 267.02
Adapted Structures
Finally an example from a totally different domain: developing window-based applications, for example using QtWidgets. As soon as Qt classes are registered in Boost.Geometry we can use them. We can, for example, check if two rectangles overlap and if so, move the second one to another place:
QRect r1(100, 200, 15, 15); QRect r2(110, 210, 20, 20); if (overlaps(r1, r2)) { assign_values(r2, 200, 300, 220, 320); }
Containers of Points in Boost.Geometry*
Basic Concepts*
[...]
Models of Containers of Points in Boost.Geometry
-
Basic point class, having coordinates defined in a neutral way.
Defines a neutral point class, fulfilling the Point Concept. Library users can use this point class, or use their own point classes. This point class is used in most of the samples and tests of Boost.Geometry. This point class is used occasionally within the library, where a temporary point class is necessary.
template<typename CoordinateType, std::size_t DimensionCount, typename CoordinateSystem> class model::point { // ... };
Constructor(s):
point()
template<typename C, std::enable_if_tgeometry::detail::is_coordinates_number_leq< C, 2, DimensionCount >::value, int >> point(CoordinateType const & v0, CoordinateType const & v1)
template<typename C, std::enable_if_tgeometry::detail::is_coordinates_number_leq< C, 1, DimensionCount >::value, int >> point(CoordinateType const & v0)
template<typename C, std::enable_if_tgeometry::detail::is_coordinates_number_leq< C, 3, DimensionCount >::value, int >> point(CoordinateType const & v0, CoordinateType const & v1, CoordinateType const & v2)
Header
Either
#include <boost/geometry/geometries/geometries.hpp>
or
#include <boost/geometry/geometries/point.hpp>
Example:
namespace bg = boost::geometry; int main() { bg::model::point<double, 2, bg::cs::cartesian> point1; bg::model::point<double, 3, bg::cs::cartesian> point2(1.0, 2.0, 3.0); 1 bg::set<0>(point1, 1.0); 2 point1.set<1>(2.0); 3 double x = bg::get<0>(point1); 4 double y = point1.get<1>(); 5 std::cout << x << ", " << y << std::endl;
-
2D point in Cartesian coordinate system.
template<typename CoordinateType, typename CoordinateSystem> class model::d2::point_xy : public model::point< CoordinateType, 2, CoordinateSystem > { // ... };
Constructor(s):
point_xy()
point_xy(CoordinateType const & x, CoordinateType const & y)
Member functions:
constexpr CoordinateType const & x()
constexpr CoordinateType const & y()
void x(CoordinateType const & v)
void y(CoordinateType const & v)
Header
Either
#include <boost/geometry/geometries/geometries.hpp>
or
#include <boost/geometry/geometries/point_xy.hpp>
Example:
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xy.hpp> namespace bg = boost::geometry; int main() { bg::model::d2::point_xy<double> point1; bg::model::d2::point_xy<double> point2(1.0, 2.0); bg::set<0>(point1, 1.0); point1.y(2.0); double x = bg::get<0>(point1); double y = point1.y(); std::cout << x << ", " << y << std::endl; return 0; }
-
2D point in Cartesian coordinate system.
template<typename CoordinateType, typename CoordinateSystem> class model::d3::point_xyz : public model::point< CoordinateType, 3, CoordinateSystem > { // ... };
Constructor(s):
point_xyz()
point_xyz(CoordinateType const & x, CoordinateType const & y, CoordinateType const & z)
Member functions:
constexpr CoordinateType const & x()
constexpr CoordinateType const & y()
constexpr CoordinateType const & z()
void x(CoordinateType const & v)
void y(CoordinateType const & v)
void z(CoordinateType const & v)
Header
Either
#include <boost/geometry/geometries/geometries.hpp>
or
#include <boost/geometry/geometries/point_xyz.hpp>
Example:
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/point_xyz.hpp> namespace bg = boost::geometry; int main() { bg::model::d3::point_xyzlt;double> point1; bg::model::d3::point_xyzlt;double> point2(3, 4, 5); bg::set<0>(point1, 1.0); point1.y(2.0); point1.z(4.0); double x = bg::get<0>(point1); double y = point1.y(); double z = point1.z(); std::cout << x << ", " << y << ", " << z << std::endl; return 0; }
-
A
linestring
(named so by OGC) is a collection (default a vector) of points.template<typename Point, template< typename, typename > class Container, template< typename > class Allocator> class model::linestring : public Container< Point, Allocator< Point > > { // ... };
Constructor(s):
linestring()
template<typename Iterator> linestring(Iterator begin, Iterator end)
linestring(std::initializer_list< Point > l)
Header
Either
#include <boost/geometry/geometries/geometries.hpp>
or
#include <boost/geometry/geometries/linestring.hpp>
Example:
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/geometries.hpp> namespace bg = boost::geometry; int main() { typedef bg::model::point<double, 2, bg::cs::cartesian> point_t; typedef bg::model::linestring<point_t> linestring_t; linestring_t ls1; #if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) \ && !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) linestring_t ls2{{0.0, 0.0}, {1.0, 0.0}, {1.0, 2.0}}; #endif bg::append(ls1, point_t(0.0, 0.0)); bg::append(ls1, point_t(1.0, 0.0)); bg::append(ls1, point_t(1.0, 2.0)); double l = bg::length(ls1); std::cout << l << std::endl; return 0; }
-
The polygon contains an outer ring and zero or more inner rings.
template<typename Point, bool ClockWise, bool Closed, template< typename, typename > class PointList, template< typename, typename > class RingList, template< typename > class PointAlloc, template< typename > class RingAlloc> class model::polygon { // ... };
Constructor(s):
polygon()
polygon(std::initializer_list< ring_type > l)
Member functions:
ring_type const & outer()
inner_container_type const & inners()
ring_type & outer()
inner_container_type & inners()
void clear()
Header
Either
#include <boost/geometry/geometries/geometries.hpp>
or
#include <boost/geometry/geometries/polygon.hpp>
Example:
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/geometries.hpp> namespace bg = boost::geometry; int main() { typedef bg::model::point<double, 2, bg::cs::cartesian> point_t; // Default parameters, clockwise, closed polygon: typedef bg::model::polygon<point_t> polygon_t; polygon_t poly1; // Default-construct a polygon. #if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) \ && !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) // Construct a polygon containing an exterior and interior ring, using C++11 unified initialization syntax: polygon_t polygon2{{{0.0, 0.0}, {0.0, 5.0}, {5.0, 5.0}, {5.0, 0.0}, {0.0, 0.0}}, {{1.0, 1.0}, {4.0, 1.0}, {4.0, 4.0}, {1.0, 4.0}, {1.0, 1.0}}}; #endif // Append point to the exterior ring: bg::append(poly1.outer(), point_t(0.0, 0.0)); bg::append(poly1.outer(), point_t(0.0, 5.0)); bg::append(poly1.outer(), point_t(5.0, 5.0)); bg::append(poly1.outer(), point_t(5.0, 0.0)); bg::append(poly1.outer(), point_t(0.0, 0.0)); // Resize a container of interior rings. poly1.inners().resize(1); // Append point to the interior ring: bg::append(poly1.inners()[0], point_t(1.0, 1.0)); bg::append(poly1.inners()[0], point_t(4.0, 1.0)); bg::append(poly1.inners()[0], point_t(4.0, 4.0)); bg::append(poly1.inners()[0], point_t(1.0, 4.0)); bg::append(poly1.inners()[0], point_t(1.0, 1.0)); double a = bg::area(poly1); std::cout << a << std::endl; return 0; }
-
multi_point, a collection of points
template<typename Point, template< typename, typename > class Container, template< typename > class Allocator> class model::multi_point : public Container< Point, Allocator< Point > > { // ... };
Constructor(s):
multi_point()
template<typename Iterator> multi_point(Iterator begin, Iterator end)
multi_point(std::initializer_list< Point > l)
Header
Either
#include <boost/geometry/geometries/geometries.hpp>
or
#include <boost/geometry/geometries/multi_point.hpp>
Example:
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/geometries.hpp> namespace bg = boost::geometry; int main() { typedef bg::model::point<double, 2, bg::cs::cartesian> point_t; typedef bg::model::multi_point<point_t> mpoint_t; mpoint_t mpt1; #if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) \ && !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) mpoint_t mpt2{{{0.0, 0.0}, {1.0, 1.0}, {2.0, 2.0}}}; #endif bg::append(mpt1, point_t(0.0, 0.0)); bg::append(mpt1, point_t(1.0, 1.0)); bg::append(mpt1, point_t(2.0, 2.0)); std::size_t count = bg::num_points(mpt1); std::cout << count << std::endl; return 0; }
-
A collection of linestring. Multi-linestring can be used to group lines belonging to each other, e.g. a highway (with interruptions)
template<typename LineString, template< typename, typename > class Container, template< typename > class Allocator> class model::multi_linestring : public Container< LineString, Allocator< LineString > > { // ... };
Constructor(s):
multi_linestring()
multi_linestring(std::initializer_list< LineString > l)
Header
Either
#include <boost/geometry/geometries/geometries.hpp>
or
#include <boost/geometry/geometries/multi_linestring.hpp>
Example:
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/geometries.hpp> namespace bg = boost::geometry; int main() { typedef bg::model::point<double, 2, bg::cs::cartesian> point_t; typedef bg::model::linestring<point_t> linestring_t; typedef bg::model::multi_linestring<linestring_t> mlinestring_t; mlinestring_t mls1; #if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) \ && !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) mlinestring_t mls2{{{0.0, 0.0}, {0.0, 1.0}, {2.0, 1.0}}, {{1.0, 0.0}, {2.0, 0.0}}}; #endif mls1.resize(2); bg::append(mls1[0], point_t(0.0, 0.0)); bg::append(mls1[0], point_t(0.0, 1.0)); bg::append(mls1[0], point_t(2.0, 1.0)); bg::append(mls1[1], point_t(1.0, 0.0)); bg::append(mls1[1], point_t(2.0, 0.0)); double l = bg::length(mls1); std::cout << l << std::endl; return 0; }
-
A collection of polygons. Multi-polygon can be used to group polygons belonging to each other, e.g. Hawaii
template<typename Polygon, template< typename, typename > class Container, template< typename > class Allocator > class model::multi_polygon : public Container< Polygon, Allocator< Polygon > > { // ... };
Constructor(s):
multi_polygon()
multi_polygon(std::initializer_list< Polygon > l)
Header
Either
#include <boost/geometry/geometries/geometries.hpp>
or
#include <boost/geometry/geometries/multi_polygon.hpp>
Example:
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/geometries.hpp> namespace bg = boost::geometry; int main() { typedef bg::model::point<double, 2, bg::cs::cartesian> point_t; typedef bg::model::polygon<point_t> polygon_t; typedef bg::model::multi_polygon<polygon_t> mpolygon_t; mpolygon_t mpoly1; #if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) \ && !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) mpolygon_t mpoly2{{{{0.0, 0.0}, {0.0, 5.0}, {5.0, 5.0}, {5.0, 0.0}, {0.0, 0.0}}, {{1.0, 1.0}, {4.0, 1.0}, {4.0, 4.0}, {1.0, 4.0}, {1.0, 1.0}}}, {{{5.0, 5.0}, {5.0, 6.0}, {6.0, 6.0}, {6.0, 5.0}, {5.0, 5.0}}}}; #endif mpoly1.resize(2); bg::append(mpoly1[0].outer(), point_t(0.0, 0.0)); bg::append(mpoly1[0].outer(), point_t(0.0, 5.0)); bg::append(mpoly1[0].outer(), point_t(5.0, 5.0)); bg::append(mpoly1[0].outer(), point_t(5.0, 0.0)); bg::append(mpoly1[0].outer(), point_t(0.0, 0.0)); mpoly1[0].inners().resize(1); bg::append(mpoly1[0].inners()[0], point_t(1.0, 1.0)); bg::append(mpoly1[0].inners()[0], point_t(4.0, 1.0)); bg::append(mpoly1[0].inners()[0], point_t(4.0, 4.0)); bg::append(mpoly1[0].inners()[0], point_t(1.0, 4.0)); bg::append(mpoly1[0].inners()[0], point_t(1.0, 1.0)); bg::append(mpoly1[1].outer(), point_t(5.0, 5.0)); bg::append(mpoly1[1].outer(), point_t(5.0, 6.0)); bg::append(mpoly1[1].outer(), point_t(6.0, 6.0)); bg::append(mpoly1[1].outer(), point_t(6.0, 5.0)); bg::append(mpoly1[1].outer(), point_t(5.0, 5.0)); double a = bg::area(mpoly1); std::cout << a << std::endl; return 0; }
-
Defines a box made of two describing points. Box is always described by a min_corner() and a max_corner() point. If another rectangle is used, use linear_ring or polygon.
Constructor(s):
box()
template<typename P, std::enable_if_t< ! std::is_copy_constructible< P >::value, int >> box(Point const & min_corner, Point const & max_corner)
template<typename P, std::enable_if_t< std::is_copy_constructible< P >::value, int >> box(Point const & min_corner, Point const & max_corner)
Member functions:
constexpr Point const & min_corner()
constexpr Point const & max_corner()
Point & min_corner()
Point & max_corner()
Header
Either
#include <boost/geometry/geometries/geometries.hpp>
or
#include <boost/geometry/geometries/box.hpp>
Example:
#include <iostream> #include <boost/geometry.hpp> namespace bg = boost::geometry; int main() { typedef bg::model::point<double, 2, bg::cs::cartesian> point_t; typedef bg::model::box<point_t> box_t; box_t box1; box_t box2(point_t(0.0, 0.0), point_t(5.0, 5.0)); #ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX box_t box3{{0.0, 0.0}, {5.0, 5.0}}; #endif bg::set<bg::min_corner, 0>(box1, 1.0); bg::set<bg::min_corner, 1>(box1, 2.0); box1.max_corner().set<0>(3.0); box1.max_corner().set<1>(4.0); double min_x = bg::get<bg::min_corner, 0>(box1); double min_y = bg::get<bg::min_corner, 1>(box1); double max_x = box1.max_corner().get<0>(); double max_y = box1.max_corner().get<1>(); std::cout << min_x << ", " << min_y << ", " << max_x << ", " << max_y << std::endl; return 0; }
-
A ring (aka linear ring) is an open or closed line which should not be self-intersecting.
template<typename Point, bool ClockWise, bool Closed, template< typename, typename > class Container, template< typename > class Allocator> class model::ring : public Container< Point, Allocator< Point > > { // ... };
Constructor(s):
ring()
template<typename Iterator> ring(Iterator begin, Iterator end)
ring(std::initializer_list< Point > l)
Header
Either
#include <boost/geometry/geometries/geometries.hpp>
or
#include <boost/geometry/geometries/ring.hpp>
Example:
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/geometries.hpp> namespace bg = boost::geometry; int main() { typedef bg::model::point<double, 2, bg::cs::cartesian> point_t; typedef bg::model::ring<point_t> ring_t; ring_t ring1; #if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) \ && !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) ring_t ring2{{0.0, 0.0}, {0.0, 5.0}, {5.0, 5.0}, {5.0, 0.0}, {0.0, 0.0}}; #endif bg::append(ring1, point_t(0.0, 0.0)); bg::append(ring1, point_t(0.0, 5.0)); bg::append(ring1, point_t(5.0, 5.0)); bg::append(ring1, point_t(5.0, 0.0)); bg::append(ring1, point_t(0.0, 0.0)); double a = bg::area(ring1); std::cout << a << std::endl; return 0; }
-
A small class containing two points. From Wikipedia: In geometry, a line segment is a part of a line that is bounded by two distinct end points, and contains every point on the line between its end points.
template<typename Point> class model::segment : public std::pair< Point, Point > { ... };
Constructor(s):
segment()
segment(Point const & p1, Point const & p2)
Header
Either
#include <boost/geometry/geometries/geometries.hpp>
or
#include <boost/geometry/geometries/segment.hpp>
Example:
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/geometries.hpp> namespace bg = boost::geometry; int main() { typedef bg::model::point<double, 2, bg::cs::cartesian> point_t; typedef bg::model::segment<point_t> segment_t; segment_t seg1; segment_t seg2(point_t(0.0, 0.0), point_t(5.0, 5.0)); #ifndef BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX segment_t seg3{{0.0, 0.0}, {5.0, 5.0}}; #endif bg::set<0, 0>(seg1, 1.0); bg::set<0, 1>(seg1, 2.0); bg::set<1, 0>(seg1, 3.0); bg::set<1, 1>(seg1, 4.0); double x0 = bg::get<0, 0>(seg1); double y0 = bg::get<0, 1>(seg1); double x1 = bg::get<1, 0>(seg1); double y1 = bg::get<1, 1>(seg1); std::cout << x0 << ", " << y0 << ", " << x1 << ", " << y1 << std::endl; return 0; }
-
A small class containing two (templatized) point references. From Wikipedia: In geometry, a line segment is a part of a line that is bounded by two distinct end points, and contains every point on the line between its end points.
template<typename ConstOrNonConstPoint> class model::referring_segment { // ... };
Constructor(s):
referring_segment(point_type & p1, point_type & p2)
Header
Either
#include <boost/geometry/geometries/geometries.hpp>
or
#include <boost/geometry/geometries/segment.hpp>
Example:
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/geometries.hpp> namespace bg = boost::geometry; int main() { typedef bg::model::point<double, 2, bg::cs::cartesian> point_t; typedef bg::model::referring_segment<point_t> referring_segment_t; //typedef bg::model::segment<point_t> referring_segment_t; point_t p1(0.0, 0.0), p2(5.0, 5.0); //referring_segment_t rs1; referring_segment_t rs2(p1,p2); bg::set<0, 0>(rs2, 1.0); bg::set<0, 1>(rs2, 2.0); bg::set<1, 0>(rs2, 3.0); bg::set<1, 1>(rs2, 4.0); double x0 = bg::get<0, 0>(rs2); double y0 = bg::get<0, 1>(rs2); double x1 = bg::get<1, 0>(rs2); double y1 = bg::get<1, 1>(rs2); std::cout << x0 << ", " << y0 << ", " << x1 << ", " << y1 << std::endl; // Now try changing a point that the referring_segment points to: std::cout << "After changing p1: "; bg::set<0>(p1, 0.5); // ... and print the member variables again: x0 = bg::get<0, 0>(rs2); y0 = bg::get<0, 1>(rs2); x1 = bg::get<1, 0>(rs2); y1 = bg::get<1, 1>(rs2); std::cout << x0 << ", " << y0 << ", " << x1 << ", " << y1 << std::endl; return 0; }
model::point
model::d2::point_xy
model::d3::point_xyz
model::linestring
model::polygon
model::multi_point
model::multi_linestring(
model::multi_polygon
model::box
model::ring
model::segment
model::referring_segment
Adapted Models: C Arrays
C arrays are adapted to the Boost.Geometry point concept. C arrays, such as double[2] or int[3], are (optionally) adapted to the Boost.Geometry point concept. They can therefore be used in many Boost.Geometry algorithms.
A C array cannot be the point type of a linestring or a polygon. The reason for that is that a std::vector does not allow containing C arrays (this is not related to Boost.Geometry). The C array is therefore limited to the point type.
Header:
#include <boost/geometry/geometries/adapted/c_array.hpp>
The standard header boost/geometry.hpp does not include this header.
Example:
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/adapted/c_array.hpp> BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian) int main() { int a[3] = {1, 2, 3}; int b[3] = {2, 3, 4}; std::cout << boost::geometry::distance(a, b) << std::endl; return 0; }
Adapted Models: std::array<>
C++11 array containers are adapted to the Boost.Geometry point concept. A C++11 std::array is (optionally) adapted to the Boost.Geometry point concept. It can therefore be used in all Boost.Geometry algorithms.
A std::array can be the point type used by the models linestring, polygon, segment, box, and ring.
Header:
#include <boost/geometry/geometries/adapted/std_array.hpp>
Example:
#include <iostream> #include <boost/geometry.hpp> #include <boost/geometry/geometries/linestring.hpp> #include <boost/geometry/geometries/adapted/std_array.hpp> BOOST_GEOMETRY_REGISTER_STD_ARRAY_CS(cs::cartesian) int main() { std::array<float, 2> a = { {1, 2} }; std::array<double, 2> b = { {2, 3} }; std::cout << boost::geometry::distance(a, b) << std::endl; boost::geometry::set<0>(a, 1.1f); boost::geometry::set<1>(a, 2.2f); std::cout << boost::geometry::distance(a, b) << std::endl; boost::geometry::assign_values(b, 2.2, 3.3); std::cout << boost::geometry::distance(a, b) << std::endl; boost::geometry::model::linestring<std::array<double, 2> > line; line.push_back(b); return 0; }