1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>model::linestring</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="../models.html" title="Models"> 9<link rel="prev" href="model_d3_point_xyz.html" title="model::d3::point_xyz"> 10<link rel="next" href="model_polygon.html" title="model::polygon"> 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="model_d3_point_xyz.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../models.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="model_polygon.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.models.model_linestring"></a><a class="link" href="model_linestring.html" title="model::linestring">model::linestring</a> 28</h4></div></div></div> 29<p> 30 <a class="indexterm" name="idm45635680187856"></a><a class="indexterm" name="idm45635680187168"></a> 31A linestring (named so by OGC) is a collection (default a vector) of points. 32 </p> 33<h6> 34<a name="geometry.reference.models.model_linestring.h0"></a> 35 <span class="phrase"><a name="geometry.reference.models.model_linestring.model_of"></a></span><a class="link" href="model_linestring.html#geometry.reference.models.model_linestring.model_of">Model of</a> 36 </h6> 37<p> 38 <a class="link" href="../concepts/concept_linestring.html" title="Linestring Concept">Linestring 39 Concept</a> 40 </p> 41<h6> 42<a name="geometry.reference.models.model_linestring.h1"></a> 43 <span class="phrase"><a name="geometry.reference.models.model_linestring.synopsis"></a></span><a class="link" href="model_linestring.html#geometry.reference.models.model_linestring.synopsis">Synopsis</a> 44 </h6> 45<p> 46</p> 47<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Point</span><span class="special">,</span> <span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span><span class="special">,</span> <span class="keyword">typename</span> <span class="special">></span> <span class="keyword">class</span> <span class="identifier">Container</span><span class="special">,</span> <span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="special">></span> <span class="keyword">class</span> <span class="identifier">Allocator</span><span class="special">></span> 48<span class="keyword">class</span> <span class="identifier">model</span><span class="special">::</span><span class="identifier">linestring</span> 49 <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">Container</span><span class="special"><</span> <span class="identifier">Point</span><span class="special">,</span> <span class="identifier">Allocator</span><span class="special"><</span> <span class="identifier">Point</span> <span class="special">></span> <span class="special">></span> 50<span class="special">{</span> 51 <span class="comment">// ...</span> 52<span class="special">};</span> 53</pre> 54<p> 55 </p> 56<h6> 57<a name="geometry.reference.models.model_linestring.h2"></a> 58 <span class="phrase"><a name="geometry.reference.models.model_linestring.template_parameter_s_"></a></span><a class="link" href="model_linestring.html#geometry.reference.models.model_linestring.template_parameter_s_">Template 59 parameter(s)</a> 60 </h6> 61<div class="informaltable"><table class="table"> 62<colgroup> 63<col> 64<col> 65<col> 66</colgroup> 67<thead><tr> 68<th> 69 <p> 70 Parameter 71 </p> 72 </th> 73<th> 74 <p> 75 Default 76 </p> 77 </th> 78<th> 79 <p> 80 Description 81 </p> 82 </th> 83</tr></thead> 84<tbody> 85<tr> 86<td> 87 <p> 88 typename Point 89 </p> 90 </td> 91<td> 92 </td> 93<td> 94 <p> 95 Any type fulfilling a Point Concept 96 </p> 97 </td> 98</tr> 99<tr> 100<td> 101 <p> 102 template< typename, typename > class Container 103 </p> 104 </td> 105<td> 106 <p> 107 std::vector 108 </p> 109 </td> 110<td> 111 <p> 112 container type, for example std::vector, std::deque 113 </p> 114 </td> 115</tr> 116<tr> 117<td> 118 <p> 119 template< typename > class Allocator 120 </p> 121 </td> 122<td> 123 <p> 124 std::allocator 125 </p> 126 </td> 127<td> 128 <p> 129 container-allocator-type 130 </p> 131 </td> 132</tr> 133</tbody> 134</table></div> 135<h6> 136<a name="geometry.reference.models.model_linestring.h3"></a> 137 <span class="phrase"><a name="geometry.reference.models.model_linestring.constructor_s_"></a></span><a class="link" href="model_linestring.html#geometry.reference.models.model_linestring.constructor_s_">Constructor(s)</a> 138 </h6> 139<div class="informaltable"><table class="table"> 140<colgroup> 141<col> 142<col> 143<col> 144</colgroup> 145<thead><tr> 146<th> 147 <p> 148 Function 149 </p> 150 </th> 151<th> 152 <p> 153 Description 154 </p> 155 </th> 156<th> 157 <p> 158 Parameters 159 </p> 160 </th> 161</tr></thead> 162<tbody> 163<tr> 164<td> 165 <p> 166</p> 167<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">linestring</span><span class="special">()</span></pre> 168<p> 169 </p> 170 </td> 171<td> 172 <p> 173 Default constructor, creating an empty linestring. 174 </p> 175 </td> 176<td> 177 </td> 178</tr> 179<tr> 180<td> 181 <p> 182</p> 183<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Iterator</span><span class="special">></span> 184<span class="identifier">linestring</span><span class="special">(</span><span class="identifier">Iterator</span> <span class="identifier">begin</span><span class="special">,</span> <span class="identifier">Iterator</span> <span class="identifier">end</span><span class="special">)</span></pre> 185<p> 186 </p> 187 </td> 188<td> 189 <p> 190 Constructor with begin and end, filling the linestring. 191 </p> 192 </td> 193<td> 194 <p> 195 <span class="bold"><strong>Iterator</strong></span>: <span class="emphasis"><em>begin</em></span>: 196 </p> 197 <p> 198 <span class="bold"><strong>Iterator</strong></span>: <span class="emphasis"><em>end</em></span>: 199 </p> 200 </td> 201</tr> 202<tr> 203<td> 204 <p> 205</p> 206<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">linestring</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">initializer_list</span><span class="special"><</span> <span class="identifier">Point</span> <span class="special">></span> <span class="identifier">l</span><span class="special">)</span></pre> 207<p> 208 </p> 209 </td> 210<td> 211 <p> 212 Constructor taking std::initializer_list, filling the linestring. 213 </p> 214 </td> 215<td> 216 <p> 217 <span class="bold"><strong>std::initializer_list< Point ></strong></span>: 218 <span class="emphasis"><em>l</em></span>: 219 </p> 220 </td> 221</tr> 222</tbody> 223</table></div> 224<h6> 225<a name="geometry.reference.models.model_linestring.h4"></a> 226 <span class="phrase"><a name="geometry.reference.models.model_linestring.header"></a></span><a class="link" href="model_linestring.html#geometry.reference.models.model_linestring.header">Header</a> 227 </h6> 228<p> 229 Either 230 </p> 231<p> 232 <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">geometries</span><span class="special">/</span><span class="identifier">geometries</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> 233 </p> 234<p> 235 Or 236 </p> 237<p> 238 <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">geometries</span><span class="special">/</span><span class="identifier">linestring</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> 239 </p> 240<h6> 241<a name="geometry.reference.models.model_linestring.h5"></a> 242 <span class="phrase"><a name="geometry.reference.models.model_linestring.examples"></a></span><a class="link" href="model_linestring.html#geometry.reference.models.model_linestring.examples">Examples</a> 243 </h6> 244<p> 245 Declaration and use of the Boost.Geometry model::linestring, modelling 246 the Linestring Concept 247 </p> 248<p> 249</p> 250<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span> 251<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> 252<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">geometries</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 253 254<span class="keyword">namespace</span> <span class="identifier">bg</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">;</span> 255 256<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> 257<span class="special">{</span> 258 <span class="keyword">typedef</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">point</span><span class="special"><</span><span class="keyword">double</span><span class="special">,</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">cs</span><span class="special">::</span><span class="identifier">cartesian</span><span class="special">></span> <span class="identifier">point_t</span><span class="special">;</span> 259 <span class="keyword">typedef</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">model</span><span class="special">::</span><span class="identifier">linestring</span><span class="special"><</span><span class="identifier">point_t</span><span class="special">></span> <span class="identifier">linestring_t</span><span class="special">;</span> 260 261 <span class="identifier">linestring_t</span> <span class="identifier">ls1</span><span class="special">;</span> <a class="co" name="geometry.reference.models.model_linestring.c0" href="model_linestring.html#geometry.reference.models.model_linestring.c1"><img src="../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> 262 263<span class="preprocessor">#if</span> <span class="special">!</span><span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX</span><span class="special">)</span> <span class="special">\</span> 264 <span class="special">&&</span> <span class="special">!</span><span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_NO_CXX11_HDR_INITIALIZER_LIST</span><span class="special">)</span> 265 266 <span class="identifier">linestring_t</span> <span class="identifier">ls2</span><span class="special">{{</span><span class="number">0.0</span><span class="special">,</span> <span class="number">0.0</span><span class="special">},</span> <span class="special">{</span><span class="number">1.0</span><span class="special">,</span> <span class="number">0.0</span><span class="special">},</span> <span class="special">{</span><span class="number">1.0</span><span class="special">,</span> <span class="number">2.0</span><span class="special">}};</span> <a class="co" name="geometry.reference.models.model_linestring.c2" href="model_linestring.html#geometry.reference.models.model_linestring.c3"><img src="../../../../../../../doc/src/images/callouts/2.png" alt="2" border="0"></a> 267 268<span class="preprocessor">#endif</span> 269 270 <span class="identifier">bg</span><span class="special">::</span><span class="identifier">append</span><span class="special">(</span><span class="identifier">ls1</span><span class="special">,</span> <span class="identifier">point_t</span><span class="special">(</span><span class="number">0.0</span><span class="special">,</span> <span class="number">0.0</span><span class="special">));</span> <a class="co" name="geometry.reference.models.model_linestring.c4" href="model_linestring.html#geometry.reference.models.model_linestring.c5"><img src="../../../../../../../doc/src/images/callouts/3.png" alt="3" border="0"></a> 271 <span class="identifier">bg</span><span class="special">::</span><span class="identifier">append</span><span class="special">(</span><span class="identifier">ls1</span><span class="special">,</span> <span class="identifier">point_t</span><span class="special">(</span><span class="number">1.0</span><span class="special">,</span> <span class="number">0.0</span><span class="special">));</span> 272 <span class="identifier">bg</span><span class="special">::</span><span class="identifier">append</span><span class="special">(</span><span class="identifier">ls1</span><span class="special">,</span> <span class="identifier">point_t</span><span class="special">(</span><span class="number">1.0</span><span class="special">,</span> <span class="number">2.0</span><span class="special">));</span> 273 274 <span class="keyword">double</span> <span class="identifier">l</span> <span class="special">=</span> <span class="identifier">bg</span><span class="special">::</span><span class="identifier">length</span><span class="special">(</span><span class="identifier">ls1</span><span class="special">);</span> 275 276 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">l</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 277 278 <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span> 279<span class="special">}</span> 280</pre> 281<p> 282 </p> 283<div class="calloutlist"><table border="0" summary="Callout list"> 284<tr> 285<td width="5%" valign="top" align="left"><p><a name="geometry.reference.models.model_linestring.c1"></a><a href="#geometry.reference.models.model_linestring.c0"><img src="../../../../../../../doc/src/images/callouts/1.png" alt="1" border="0"></a> </p></td> 286<td valign="top" align="left"><p> 287 Default-construct a linestring. 288 </p></td> 289</tr> 290<tr> 291<td width="5%" valign="top" align="left"><p><a name="geometry.reference.models.model_linestring.c3"></a><a href="#geometry.reference.models.model_linestring.c2"><img src="../../../../../../../doc/src/images/callouts/2.png" alt="2" border="0"></a> </p></td> 292<td valign="top" align="left"><p> 293 Construct a linestring containing three points, using C++11 unified 294 initialization syntax. 295 </p></td> 296</tr> 297<tr> 298<td width="5%" valign="top" align="left"><p><a name="geometry.reference.models.model_linestring.c5"></a><a href="#geometry.reference.models.model_linestring.c4"><img src="../../../../../../../doc/src/images/callouts/3.png" alt="3" border="0"></a> </p></td> 299<td valign="top" align="left"><p> 300 Append point. 301 </p></td> 302</tr> 303</table></div> 304<p> 305 Output: 306 </p> 307<pre class="programlisting">3 308</pre> 309</div> 310<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 311<td align="left"></td> 312<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam 313 Wulkiewicz, Oracle and/or its affiliates<p> 314 Distributed under the Boost Software License, Version 1.0. (See accompanying 315 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>) 316 </p> 317</div></td> 318</tr></table> 319<hr> 320<div class="spirit-nav"> 321<a accesskey="p" href="model_d3_point_xyz.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../models.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="model_polygon.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 322</div> 323</body> 324</html> 325