| Home | Libraries | People | FAQ | More

#### num_points

Calculates the number of points of a geometry.

###### Description

The free function num_points calculates the number of points of a geometry.

###### Synopsis

    template<typename Geometry>
    std::size_t num_points(Geometry const & geometry, bool add_for_open = false)

###### Parameters

Type | Concept | Name | Description
--- | --- | --- | ---
Geometry const & | Any type fulfilling a Geometry Concept | geometry | A model of the specified concept
bool |  | add_for_open | add one for open geometries (i.e. polygon types which are not closed)

###### Returns

The calculated number of points

###### Header

Either

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

Or

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

###### Conformance

The function num_points implements function NumPoints from the OGC Simple Feature Specification.

| Note
num_points can be called for any geometry and not just linestrings (as the standard describes)

###### Behavior

Case | Behavior
--- | ---
Point | Returns 1
Segment | Returns 2
Box | Returns 4
Rangelike (linestring, ring) | Returns boost::size(geometry)
Other geometries | Returns the sum of the number of points of its elements
Open geometries | Returns the sum of the number of points of its elements, it adds one for open (per ring) if specified
Closed geometries | Returns the sum of the number of points of its elements

###### Complexity

Constant or Linear

###### Examples

Get the number of points in a geometry

    #include <iostream>

    #include <boost/geometry.hpp>
    #include <boost/geometry/multi/multi.hpp>
    #include <boost/geometry/geometries/point_xy.hpp>
    #include <boost/geometry/geometries/polygon.hpp>
    #include <boost/geometry/multi/geometries/multi_polygon.hpp>
    #include <boost/geometry/io/wkt/wkt.hpp>
    #include <boost/geometry/multi/io/wkt/wkt.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 points: " << boost::geometry::num_points(mp) << std::endl;

        return 0;
    }

Output:

    Number of points: 12