3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
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="../make.html" title="make">
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>
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="../make.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
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
29 </h5></div></div></div>
31 <a class="indexterm" name="idp101137568"></a>
32 Calculates the length of a geometry using the specified strategy.
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>
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
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>
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>
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>
60 <div class="informaltable"><table class="table">
98 Any type fulfilling a Geometry Concept
108 A model of the specified concept
120 Any type fulfilling a distance Strategy Concept
130 The strategy which will be used for distance calculations
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>
141 The calculated length
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>
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>
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>
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>
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>.
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>
171 <div class="informaltable"><table class="table">
192 pointlike (e.g. point)
204 linear (e.g. linestring)
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>
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>
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.
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>
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>
262 <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
263 <span class="special">}</span>
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>
276 <pre class="programlisting">length is 1272.03 kilometers
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-2017 Barend
282 Gehrels, Bruno Lalande, Mateusz Loskot, Adam Wulkiewicz, Oracle and/or its
284 Distributed under the Boost Software License, Version 1.0. (See accompanying
285 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>)
290 <div class="spirit-nav">
291 <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="../make.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>