index

# 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:

- conventions from boost

- conventions from the std library

- conventions and names from one of the OGC standards on Geometry

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.

    inta[2]={1,1};
    intb[2]={2,3};
    doubled=distance(a,b);
    std::cout<<"Distancea-bis:"<<d<<std::endl;

Other often used algorithms are point-in-polygon:

    ring_2dpoly;
    doublepoints[][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<<"Pointpisinpolygon?"<<(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:

    doubled2=distance(a,p);
    std::cout<<"Distancea-pis:"<<d2<<std::endl;

The pieces above generate this output:

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:

    QRectr1(100,200,15,15);
    QRectr2(110,210,20,20);
    if(overlaps(r1,r2))
    {
    assign(r2,200,300,220,320);
    }

More examples are on the page Examples