Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the develop branch, built from commit 03313ef1c6.
PrevUpHomeNext
BOOST_GEOMETRY_REGISTER_POINT_2D

Macro to register a 2D point type.

Description

The macro BOOST_GEOMETRY_REGISTER_POINT_2D registers a two-dimensional point type such that it is recognized by Boost.Geometry and that Boost.Geometry functionality can used with the specified type. For geographic coordinate systems, be sure to specify first longitude and then latitude, to be able to use the strategies included in the library.

Synopsis

#define BOOST_GEOMETRY_REGISTER_POINT_2D(Point, CoordinateType, CoordinateSystem,
                                  Field0, Field1)

Parameters

Name

Description

Point

Point type to be registered

CoordinateType

Type of the coordinates of the point (e.g. double)

CoordinateSystem

Coordinate system (e.g. cs::cartesian)

Field0

Member containing first (usually x, or longitude) coordinate

Field1

Member containing second (usually y, or latitude) coordinate

Header

#include <boost/geometry/geometries/register/point.hpp>

[Caution] Caution

Use the macro outside any namespace

[Note] Note

A point can include a namespace

Examples

Show the use of the macro BOOST_GEOMETRY_REGISTER_POINT_2D

#include <iostream>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/register/point.hpp>

1
struct legacy_point
{
    double x, y;
};

BOOST_GEOMETRY_REGISTER_POINT_2D(legacy_point, double, cs::cartesian, x, y) 2

int main()
{
    legacy_point p1, p2;

    namespace bg = boost::geometry;

    3
    bg::assign_values(p1, 1, 1);
    bg::assign_values(p2, 2, 2);

    double d = bg::distance(p1, p2);

    std::cout << "Distance: " << d << std::endl;

    return 0;
}

1

Somewhere, any legacy point struct is defined

2

The magic: adapt it to Boost.Geometry Point Concept

3

Any Boost.Geometry function can be used for legacy point now. Here: assign_values and distance

Output:

Distance: 1.41421

PrevUpHomeNext