num_geometries

| Home | Libraries | People | FAQ | More

#### num_geometries

Calculates the number of geometries of a geometry.

###### Description

The free function num_geometries calculates the number of geometries of a geometry.

###### Synopsis

    template<typename Geometry>
    std::size_t num_geometries(Geometry const & geometry)

###### Parameters

Type | Concept | Name | Description
--- | --- | --- | ---
Geometry const & | Any type fulfilling a Geometry Concept | geometry | A model of the specified concept

###### Returns

The calculated number of geometries

###### Header

Either

`#include <boost/geometry.hpp>`

Or

`#include <boost/geometry/algorithms/num_geometries.hpp>`

###### Conformance

The function num_geometries implements function NumGeometries from the OGC Simple Feature Specification.

###### Behavior

Case | Behavior
--- | ---
single (e.g. point, polygon) | Returns 1
multiple (e.g. multi_point, multi_polygon) | Returns boost::size(geometry); the input is considered as a range

###### Complexity

Constant

###### Examples

Get the number of geometries making up a multi-geometry

    #include <iostream>

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

    int main()
    {
        boost::geometry::model::multi_polygon
            <
                boost::geometry::model::polygon
                    <
                        boost::geometry::model::d2::point_xy<double>
                    >
            > mp;
        boost::geometry::read_wkt("MULTIPOLYGON(((0 0,0 10,10 0,0 0),(1 1,1 9,9 1,1 1)),((10 10,10 7,7 10,10 10)))", mp);
        std::cout << "Number of geometries: " << boost::geometry::num_geometries(mp) << std::endl;

        return 0;
    }

Output:

    Number of geometries: 2