|  | Home | Libraries | People | FAQ | More | 
Calculates the number of geometries of a geometry.
The free function num_geometries calculates the number of geometries of a geometry.
template<typename Geometry> std::size_t num_geometries(Geometry const & geometry)
| Type | Concept | Name | Description | 
|---|---|---|---|
| Geometry const & | Any type fulfilling a Geometry Concept | geometry | A model of the specified concept | 
The calculated number of geometries
Either
          #include <boost/geometry.hpp>
        
Or
          #include <boost/geometry/algorithms/num_geometries.hpp>
        
The function num_geometries implements function NumGeometries from the OGC Simple Feature Specification.
| 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 | 
Constant
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