1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>num_points</title> 5<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../../index.html" title="Chapter 1. Geometry"> 8<link rel="up" href="../algorithms.html" title="Algorithms"> 9<link rel="prev" href="num_interior_rings.html" title="num_interior_rings"> 10<link rel="next" href="num_segments.html" title="num_segments"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="num_interior_rings.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../algorithms.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="num_segments.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h4 class="title"> 27<a name="geometry.reference.algorithms.num_points"></a><a class="link" href="num_points.html" title="num_points">num_points</a> 28</h4></div></div></div> 29<p> 30 <a class="indexterm" name="idm45635691545792"></a> 31Calculates the number of points of a geometry. 32 </p> 33<h6> 34<a name="geometry.reference.algorithms.num_points.h0"></a> 35 <span class="phrase"><a name="geometry.reference.algorithms.num_points.description"></a></span><a class="link" href="num_points.html#geometry.reference.algorithms.num_points.description">Description</a> 36 </h6> 37<p> 38 The free function num_points calculates the number of points of a geometry. 39 </p> 40<h6> 41<a name="geometry.reference.algorithms.num_points.h1"></a> 42 <span class="phrase"><a name="geometry.reference.algorithms.num_points.synopsis"></a></span><a class="link" href="num_points.html#geometry.reference.algorithms.num_points.synopsis">Synopsis</a> 43 </h6> 44<p> 45</p> 46<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Geometry</span><span class="special">></span> 47<span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">num_points</span><span class="special">(</span><span class="identifier">Geometry</span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">geometry</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">add_for_open</span> <span class="special">=</span> <span class="keyword">false</span><span class="special">)</span></pre> 48<p> 49 </p> 50<h6> 51<a name="geometry.reference.algorithms.num_points.h2"></a> 52 <span class="phrase"><a name="geometry.reference.algorithms.num_points.parameters"></a></span><a class="link" href="num_points.html#geometry.reference.algorithms.num_points.parameters">Parameters</a> 53 </h6> 54<div class="informaltable"><table class="table"> 55<colgroup> 56<col> 57<col> 58<col> 59<col> 60</colgroup> 61<thead><tr> 62<th> 63 <p> 64 Type 65 </p> 66 </th> 67<th> 68 <p> 69 Concept 70 </p> 71 </th> 72<th> 73 <p> 74 Name 75 </p> 76 </th> 77<th> 78 <p> 79 Description 80 </p> 81 </th> 82</tr></thead> 83<tbody> 84<tr> 85<td> 86 <p> 87 Geometry const & 88 </p> 89 </td> 90<td> 91 <p> 92 Any type fulfilling a Geometry Concept 93 </p> 94 </td> 95<td> 96 <p> 97 geometry 98 </p> 99 </td> 100<td> 101 <p> 102 A model of the specified concept 103 </p> 104 </td> 105</tr> 106<tr> 107<td> 108 <p> 109 bool 110 </p> 111 </td> 112<td> 113 </td> 114<td> 115 <p> 116 add_for_open 117 </p> 118 </td> 119<td> 120 <p> 121 add one for open geometries (i.e. polygon types which are not 122 closed) 123 </p> 124 </td> 125</tr> 126</tbody> 127</table></div> 128<h6> 129<a name="geometry.reference.algorithms.num_points.h3"></a> 130 <span class="phrase"><a name="geometry.reference.algorithms.num_points.returns"></a></span><a class="link" href="num_points.html#geometry.reference.algorithms.num_points.returns">Returns</a> 131 </h6> 132<p> 133 The calculated number of points 134 </p> 135<h6> 136<a name="geometry.reference.algorithms.num_points.h4"></a> 137 <span class="phrase"><a name="geometry.reference.algorithms.num_points.header"></a></span><a class="link" href="num_points.html#geometry.reference.algorithms.num_points.header">Header</a> 138 </h6> 139<p> 140 Either 141 </p> 142<p> 143 <code class="computeroutput"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> 144 </p> 145<p> 146 Or 147 </p> 148<p> 149 <code class="computeroutput"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">algorithms</span><span class="special">/</span><span class="identifier">num_points</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> 150 </p> 151<h6> 152<a name="geometry.reference.algorithms.num_points.h5"></a> 153 <span class="phrase"><a name="geometry.reference.algorithms.num_points.conformance"></a></span><a class="link" href="num_points.html#geometry.reference.algorithms.num_points.conformance">Conformance</a> 154 </h6> 155<p> 156 The function num_points implements function NumPoints from the <a href="http://www.opengeospatial.org/standards/sfa" target="_top">OGC 157 Simple Feature Specification</a>. 158 </p> 159<div class="note"><table border="0" summary="Note"> 160<tr> 161<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td> 162<th align="left">Note</th> 163</tr> 164<tr><td align="left" valign="top"><p> 165 num_points can be called for any geometry and not just linestrings (as 166 the standard describes) 167 </p></td></tr> 168</table></div> 169<h6> 170<a name="geometry.reference.algorithms.num_points.h6"></a> 171 <span class="phrase"><a name="geometry.reference.algorithms.num_points.behavior"></a></span><a class="link" href="num_points.html#geometry.reference.algorithms.num_points.behavior">Behavior</a> 172 </h6> 173<div class="informaltable"><table class="table"> 174<colgroup> 175<col> 176<col> 177</colgroup> 178<thead><tr> 179<th> 180 <p> 181 Case 182 </p> 183 </th> 184<th> 185 <p> 186 Behavior 187 </p> 188 </th> 189</tr></thead> 190<tbody> 191<tr> 192<td> 193 <p> 194 Point 195 </p> 196 </td> 197<td> 198 <p> 199 Returns 1 200 </p> 201 </td> 202</tr> 203<tr> 204<td> 205 <p> 206 Segment 207 </p> 208 </td> 209<td> 210 <p> 211 Returns 2 212 </p> 213 </td> 214</tr> 215<tr> 216<td> 217 <p> 218 Box 219 </p> 220 </td> 221<td> 222 <p> 223 Returns 2^d, where d is the dimension of the box 224 </p> 225 </td> 226</tr> 227<tr> 228<td> 229 <p> 230 Rangelike (linestring, ring) 231 </p> 232 </td> 233<td> 234 <p> 235 Returns boost::size(geometry) 236 </p> 237 </td> 238</tr> 239<tr> 240<td> 241 <p> 242 Other geometries 243 </p> 244 </td> 245<td> 246 <p> 247 Returns the sum of the number of points of its elements 248 </p> 249 </td> 250</tr> 251<tr> 252<td> 253 <p> 254 Open geometries 255 </p> 256 </td> 257<td> 258 <p> 259 Returns the sum of the number of points of its elements, it adds 260 one for open (per ring) if specified 261 </p> 262 </td> 263</tr> 264<tr> 265<td> 266 <p> 267 Closed geometries 268 </p> 269 </td> 270<td> 271 <p> 272 Returns the sum of the number of points of its elements 273 </p> 274 </td> 275</tr> 276</tbody> 277</table></div> 278<h6> 279<a name="geometry.reference.algorithms.num_points.h7"></a> 280 <span class="phrase"><a name="geometry.reference.algorithms.num_points.complexity"></a></span><a class="link" href="num_points.html#geometry.reference.algorithms.num_points.complexity">Complexity</a> 281 </h6> 282<p> 283 Constant or Linear 284 </p> 285<h6> 286<a name="geometry.reference.algorithms.num_points.h8"></a> 287 <span class="phrase"><a name="geometry.reference.algorithms.num_points.examples"></a></span><a class="link" href="num_points.html#geometry.reference.algorithms.num_points.examples">Examples</a> 288 </h6> 289<p> 290 Get the number of points in a geometry 291 </p> 292<p> 293</p> 294<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span> 295 296<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 297<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">point_xy</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 298<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">polygon</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 299<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">geometry</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">/</span><span class="identifier">multi_polygon</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 300 301 302<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> 303<span class="special">{</span> 304 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">multi_polygon</span> 305 <span class="special"><</span> 306 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">polygon</span> 307 <span class="special"><</span> 308 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">d2</span><span class="special">::</span><span class="identifier">point_xy</span><span class="special"><</span><span class="keyword">double</span><span class="special">></span> 309 <span class="special">></span> 310 <span class="special">></span> <span class="identifier">mp</span><span class="special">;</span> 311 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">read_wkt</span><span class="special">(</span><span class="string">"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)))"</span><span class="special">,</span> <span class="identifier">mp</span><span class="special">);</span> 312 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Number of points: "</span> <span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">num_points</span><span class="special">(</span><span class="identifier">mp</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 313 314 <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span> 315<span class="special">}</span> 316</pre> 317<p> 318 </p> 319<p> 320 Output: 321 </p> 322<pre class="programlisting">Number of points: 12 323</pre> 324</div> 325<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 326<td align="left"></td> 327<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam 328 Wulkiewicz, Oracle and/or its affiliates<p> 329 Distributed under the Boost Software License, Version 1.0. (See accompanying 330 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 331 </p> 332</div></td> 333</tr></table> 334<hr> 335<div class="spirit-nav"> 336<a accesskey="p" href="num_interior_rings.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../algorithms.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="num_segments.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 337</div> 338</body> 339</html> 340