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 an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
is_valid

Checks if a geometry is valid (in the OGC sense)

Synopsis

template<typename Geometry>
bool is_valid(Geometry const & geometry)

Parameters

Type

Concept

Name

Description

Geometry const &

Any type fulfilling a Geometry Concept

geometry

A model of the specified concept

Returns

Returns true if the geometry is valid (in the OGC sense); furthermore, the following geometries are considered valid: multi-geometries with no elements, linear geometries containing spikes, areal geometries with duplicate (consecutive) points

Header

Either

#include <boost/geometry.hpp>

Or

#include <boost/geometry/algorithms/is_valid.hpp>

Conformance

The function is_valid is not defined by OGC.

Supported geometries

Geometry

Status

Point

ok

Segment

ok

Box

ok

Linestring

ok

Ring

ok

Polygon

ok

MultiPoint

ok

MultiLinestring

ok

MultiPolygon

ok

Variant

ok

Complexity

Constant-time for points, segments, boxes and multi-points

Linear for linestrings and multi-linestrings

Linearithmic for rings

Currently, worst-case quadratic for polygons and multi-polygons

Example

Checks whether a geometry is valid

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>


int main()
{
    typedef boost::geometry::model::d2::point_xy<double> point_type;
    typedef boost::geometry::model::polygon<point_type> polygon_type;

    polygon_type poly;
    boost::geometry::read_wkt("POLYGON((0 0,0 10,10 10,10 0,0 0),(0 0,9 1,9 2,0 0),(0 0,2 9,1 9,0 0),(2 9,9 2,9 9,2 9))", poly);

    std::cout << "is valid? " << (boost::geometry::is_valid(poly) ? "yes" : "no") << std::endl;

    return 0;
}

Output:

is valid? no

is_valid_example

See also

PrevUpHomeNext