1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>length (with strategy)</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="../length.html" title="length"> 9<link rel="prev" href="length_1.html" title="length"> 10<link rel="next" href="../line_interpolate.html" title="line_interpolate"> 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="length_1.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../length.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="../line_interpolate.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h5 class="title"> 27<a name="geometry.reference.algorithms.length.length_2_with_strategy"></a><a class="link" href="length_2_with_strategy.html" title="length (with strategy)">length 28 (with strategy)</a> 29</h5></div></div></div> 30<p> 31 <a class="indexterm" name="idm45635693049568"></a> 32Calculates the length of a geometry using the specified strategy. 33 </p> 34<h6> 35<a name="geometry.reference.algorithms.length.length_2_with_strategy.h0"></a> 36 <span class="phrase"><a name="geometry.reference.algorithms.length.length_2_with_strategy.description"></a></span><a class="link" href="length_2_with_strategy.html#geometry.reference.algorithms.length.length_2_with_strategy.description">Description</a> 37 </h6> 38<p> 39 The free function length calculates the length (the sum of distances 40 between consecutive points) of a geometry using the specified strategy. 41 Reasons to specify a strategy include: use another coordinate system 42 for calculations; construct the strategy beforehand (e.g. with the radius 43 of the Earth); select a strategy when there are more than one available 44 for a calculation. 45 </p> 46<h6> 47<a name="geometry.reference.algorithms.length.length_2_with_strategy.h1"></a> 48 <span class="phrase"><a name="geometry.reference.algorithms.length.length_2_with_strategy.synopsis"></a></span><a class="link" href="length_2_with_strategy.html#geometry.reference.algorithms.length.length_2_with_strategy.synopsis">Synopsis</a> 49 </h6> 50<p> 51</p> 52<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> <span class="keyword">typename</span> <span class="identifier">Strategy</span><span class="special">></span> 53<span class="identifier">default_length_result</span><span class="special"><</span><span class="identifier">Geometry</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">length</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="identifier">Strategy</span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">strategy</span><span class="special">)</span></pre> 54<p> 55 </p> 56<h6> 57<a name="geometry.reference.algorithms.length.length_2_with_strategy.h2"></a> 58 <span class="phrase"><a name="geometry.reference.algorithms.length.length_2_with_strategy.parameters"></a></span><a class="link" href="length_2_with_strategy.html#geometry.reference.algorithms.length.length_2_with_strategy.parameters">Parameters</a> 59 </h6> 60<div class="informaltable"><table class="table"> 61<colgroup> 62<col> 63<col> 64<col> 65<col> 66</colgroup> 67<thead><tr> 68<th> 69 <p> 70 Type 71 </p> 72 </th> 73<th> 74 <p> 75 Concept 76 </p> 77 </th> 78<th> 79 <p> 80 Name 81 </p> 82 </th> 83<th> 84 <p> 85 Description 86 </p> 87 </th> 88</tr></thead> 89<tbody> 90<tr> 91<td> 92 <p> 93 Geometry const & 94 </p> 95 </td> 96<td> 97 <p> 98 Any type fulfilling a Geometry Concept 99 </p> 100 </td> 101<td> 102 <p> 103 geometry 104 </p> 105 </td> 106<td> 107 <p> 108 A model of the specified concept 109 </p> 110 </td> 111</tr> 112<tr> 113<td> 114 <p> 115 Strategy const & 116 </p> 117 </td> 118<td> 119 <p> 120 Any type fulfilling a distance Strategy Concept 121 </p> 122 </td> 123<td> 124 <p> 125 strategy 126 </p> 127 </td> 128<td> 129 <p> 130 The strategy which will be used for distance calculations 131 </p> 132 </td> 133</tr> 134</tbody> 135</table></div> 136<h6> 137<a name="geometry.reference.algorithms.length.length_2_with_strategy.h3"></a> 138 <span class="phrase"><a name="geometry.reference.algorithms.length.length_2_with_strategy.returns"></a></span><a class="link" href="length_2_with_strategy.html#geometry.reference.algorithms.length.length_2_with_strategy.returns">Returns</a> 139 </h6> 140<p> 141 The calculated length 142 </p> 143<h6> 144<a name="geometry.reference.algorithms.length.length_2_with_strategy.h4"></a> 145 <span class="phrase"><a name="geometry.reference.algorithms.length.length_2_with_strategy.header"></a></span><a class="link" href="length_2_with_strategy.html#geometry.reference.algorithms.length.length_2_with_strategy.header">Header</a> 146 </h6> 147<p> 148 Either 149 </p> 150<p> 151 <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> 152 </p> 153<p> 154 Or 155 </p> 156<p> 157 <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">length</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> 158 </p> 159<h6> 160<a name="geometry.reference.algorithms.length.length_2_with_strategy.h5"></a> 161 <span class="phrase"><a name="geometry.reference.algorithms.length.length_2_with_strategy.conformance"></a></span><a class="link" href="length_2_with_strategy.html#geometry.reference.algorithms.length.length_2_with_strategy.conformance">Conformance</a> 162 </h6> 163<p> 164 The function length implements function Length from the <a href="http://www.opengeospatial.org/standards/sfa" target="_top">OGC 165 Simple Feature Specification</a>. 166 </p> 167<h6> 168<a name="geometry.reference.algorithms.length.length_2_with_strategy.h6"></a> 169 <span class="phrase"><a name="geometry.reference.algorithms.length.length_2_with_strategy.behavior"></a></span><a class="link" href="length_2_with_strategy.html#geometry.reference.algorithms.length.length_2_with_strategy.behavior">Behavior</a> 170 </h6> 171<div class="informaltable"><table class="table"> 172<colgroup> 173<col> 174<col> 175</colgroup> 176<thead><tr> 177<th> 178 <p> 179 Case 180 </p> 181 </th> 182<th> 183 <p> 184 Behavior 185 </p> 186 </th> 187</tr></thead> 188<tbody> 189<tr> 190<td> 191 <p> 192 pointlike (e.g. point) 193 </p> 194 </td> 195<td> 196 <p> 197 Returns 0 198 </p> 199 </td> 200</tr> 201<tr> 202<td> 203 <p> 204 linear (e.g. linestring) 205 </p> 206 </td> 207<td> 208 <p> 209 Returns the length 210 </p> 211 </td> 212</tr> 213<tr> 214<td> 215 <p> 216 areal (e.g. polygon) 217 </p> 218 </td> 219<td> 220 <p> 221 Returns 0 222 </p> 223 </td> 224</tr> 225</tbody> 226</table></div> 227<h6> 228<a name="geometry.reference.algorithms.length.length_2_with_strategy.h7"></a> 229 <span class="phrase"><a name="geometry.reference.algorithms.length.length_2_with_strategy.complexity"></a></span><a class="link" href="length_2_with_strategy.html#geometry.reference.algorithms.length.length_2_with_strategy.complexity">Complexity</a> 230 </h6> 231<p> 232 Linear 233 </p> 234<h6> 235<a name="geometry.reference.algorithms.length.length_2_with_strategy.h8"></a> 236 <span class="phrase"><a name="geometry.reference.algorithms.length.length_2_with_strategy.examples"></a></span><a class="link" href="length_2_with_strategy.html#geometry.reference.algorithms.length.length_2_with_strategy.examples">Examples</a> 237 </h6> 238<p> 239 The following example shows the length measured over a sphere, expressed 240 in kilometers. To do that the radius of the sphere must be specified 241 in the constructor of the strategy. 242 </p> 243<p> 244</p> 245<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span> 246<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> 247<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">linestring</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 248 249<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> 250<span class="special">{</span> 251 <span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">;</span> 252 <span class="keyword">typedef</span> <span class="identifier">model</span><span class="special">::</span><span class="identifier">point</span><span class="special"><</span><span class="keyword">float</span><span class="special">,</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">cs</span><span class="special">::</span><span class="identifier">spherical_equatorial</span><span class="special"><</span><span class="identifier">degree</span><span class="special">></span> <span class="special">></span> <span class="identifier">P</span><span class="special">;</span> 253 <span class="identifier">model</span><span class="special">::</span><span class="identifier">linestring</span><span class="special"><</span><span class="identifier">P</span><span class="special">></span> <span class="identifier">line</span><span class="special">;</span> 254 <span class="identifier">line</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">P</span><span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="number">41</span><span class="special">));</span> 255 <span class="identifier">line</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">P</span><span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="number">48</span><span class="special">));</span> 256 <span class="identifier">line</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">P</span><span class="special">(</span><span class="number">5</span><span class="special">,</span> <span class="number">52</span><span class="special">));</span> 257 <span class="keyword">double</span> <span class="keyword">const</span> <span class="identifier">mean_radius</span> <span class="special">=</span> <span class="number">6371.0</span><span class="special">;</span> <a class="co" name="geometry.reference.algorithms.length.length_2_with_strategy.c0" href="length_2_with_strategy.html#geometry.reference.algorithms.length.length_2_with_strategy.c1"><img src="../../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> 258 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"length is "</span> 259 <span class="special"><<</span> <span class="identifier">length</span><span class="special">(</span><span class="identifier">line</span><span class="special">,</span> <span class="identifier">strategy</span><span class="special">::</span><span class="identifier">distance</span><span class="special">::</span><span class="identifier">haversine</span><span class="special"><</span><span class="keyword">float</span><span class="special">>(</span><span class="identifier">mean_radius</span><span class="special">)</span> <span class="special">)</span> 260 <span class="special"><<</span> <span class="string">" kilometers "</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 261 262 <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span> 263<span class="special">}</span> 264</pre> 265<p> 266 </p> 267<div class="calloutlist"><table border="0" summary="Callout list"><tr> 268<td width="5%" valign="top" align="left"><p><a name="geometry.reference.algorithms.length.length_2_with_strategy.c1"></a><a href="#geometry.reference.algorithms.length.length_2_with_strategy.c0"><img src="../../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> </p></td> 269<td valign="top" align="left"><p> 270 <a href="http://en.wikipedia.org/wiki/Earth_radius" target="_top">Wiki</a> 271 </p></td> 272</tr></table></div> 273<p> 274 Output: 275 </p> 276<pre class="programlisting">length is 1272.03 kilometers 277</pre> 278</div> 279<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 280<td align="left"></td> 281<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam 282 Wulkiewicz, Oracle and/or its affiliates<p> 283 Distributed under the Boost Software License, Version 1.0. (See accompanying 284 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>) 285 </p> 286</div></td> 287</tr></table> 288<hr> 289<div class="spirit-nav"> 290<a accesskey="p" href="length_1.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../length.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="../line_interpolate.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 291</div> 292</body> 293</html> 294