Boost.Geometry    Boost C++ Libraries
Boost.Geometry

Boost.Geometry (aka GGL, Generic Geometry Library)

Copyright © 1995-2012 Barend Gehrels, Geodan, Amsterdam, the Netherlands.
Copyright © 2008-2012 Bruno Lalande, Paris, France.
Copyright © 2010-2012 Mateusz Loskot, Cadcorp, London, UK.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

Introduction

Boost.Geometry, formally accepted by Boost, defines concepts "concepts" for geometries and implements some algorithms on such geometries. Before acceptance by Boost it was known as GGL (Generic Geometry Library) and this documentation still contains that name on various places.

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, convert, and more. The library is also designed to support high precision arithmetic numbers, such as GMP.

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 the Boost.Geometry Concepts.

Boost.Geometry might be used in all domains where geometry plays a role: mapping and GIS, gaming, computer graphics and widgets, robotics, astronomy... The core is designed to be as generic as possible and support those domains. However, for now the development has been mostly GIS-oriented.

Boost.Geometry supports the extension model, the same way as GIL also applies it. An extension is (mostly) something more specific to domains like mentioned above.

The library follows existing conventions:

The library can be downloaded from the Boost Sandbox, go to the Download page for more information.

A (recently started) Wiki is here: http://trac.osgeo.org/ggl/wiki

Quick start

It is not possible to show the whole library at a glance. A few very small examples are shown below.

It should be possible to use a very small part of the library, for example only the distance between two points.

    int a[2] = {1,1};
    int b[2] = {2,3};
    double d = distance(a, b);
    std::cout << "Distance a-b is:" << d << std::endl;

Other often used algorithms are point-in-polygon:

    ring_2d poly;
    double points[][2] = {{2.0, 1.3}, {4.1, 3.0}, {5.3, 2.6}, {2.9, 0.7}, {2.0, 1.3}};
    append(poly, points);
    boost::tuple<double, double> p = boost::make_tuple(3.7, 2.0);
    std::cout << "Point p is in polygon? " << (within(p, poly) ? "YES" : "NO")  << std::endl;

or area:

    std::cout << "Area: " << area(poly) << std::endl;

It is possible, by the nature of a template library, to mix the point types declared above:

    double d2 = distance(a, p);
    std::cout << "Distance a-p is:" << d2 << std::endl;

The pieces above generate this output:

output_main.png

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 "inspects" that it is handling spherical points and calculates the distance over the sphere, instead of applying the Pythagorean theorem.

Finally an example from a totally different domain: developing window-based applications, for example using QtWidgets. We 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(r2, 200, 300, 220, 320);
    }

More examples are on the page Examples


April 2, 2011

Copyright © 2007-2011 Barend Gehrels, Amsterdam, the Netherlands
Copyright © 2008-2011 Bruno Lalande, Paris, France
Copyright © 2009-2010 Mateusz Loskot, London, UK
Documentation is generated by Doxygen