1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>svg_mapper</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="../svg.html" title="SVG (Scalable Vector Graphics)"> 9<link rel="prev" href="svg.html" title="svg"> 10<link rel="next" href="../../iterators.html" title="Iterators"> 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="svg.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../svg.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="../../iterators.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.io.svg.svg_mapper"></a><a class="link" href="svg_mapper.html" title="svg_mapper">svg_mapper</a> 28</h5></div></div></div> 29<p> 30 <a class="indexterm" name="idm45635681419216"></a> 31Helper class to create SVG maps. 32 </p> 33<h6> 34<a name="geometry.reference.io.svg.svg_mapper.h0"></a> 35 <span class="phrase"><a name="geometry.reference.io.svg.svg_mapper.synopsis"></a></span><a class="link" href="svg_mapper.html#geometry.reference.io.svg.svg_mapper.synopsis">Synopsis</a> 36 </h6> 37<p> 38</p> 39<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">bool</span> <span class="identifier">SameScale</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">SvgCoordinateType</span><span class="special">></span> 40<span class="keyword">class</span> <span class="identifier">svg_mapper</span> 41 <span class="special">:</span> <span class="identifier">noncopyable</span> 42<span class="special">{</span> 43 <span class="comment">// ...</span> 44<span class="special">};</span> 45</pre> 46<p> 47 </p> 48<h6> 49<a name="geometry.reference.io.svg.svg_mapper.h1"></a> 50 <span class="phrase"><a name="geometry.reference.io.svg.svg_mapper.template_parameter_s_"></a></span><a class="link" href="svg_mapper.html#geometry.reference.io.svg.svg_mapper.template_parameter_s_">Template 51 parameter(s)</a> 52 </h6> 53<div class="informaltable"><table class="table"> 54<colgroup> 55<col> 56<col> 57<col> 58</colgroup> 59<thead><tr> 60<th> 61 <p> 62 Parameter 63 </p> 64 </th> 65<th> 66 <p> 67 Default 68 </p> 69 </th> 70<th> 71 <p> 72 Description 73 </p> 74 </th> 75</tr></thead> 76<tbody> 77<tr> 78<td> 79 <p> 80 typename Point 81 </p> 82 </td> 83<td> 84 </td> 85<td> 86 <p> 87 Point type, for input geometries. 88 </p> 89 </td> 90</tr> 91<tr> 92<td> 93 <p> 94 bool SameScale 95 </p> 96 </td> 97<td> 98 <p> 99 true 100 </p> 101 </td> 102<td> 103 <p> 104 Boolean flag indicating if horizontal and vertical scale should 105 be the same. The default value is true 106 </p> 107 </td> 108</tr> 109<tr> 110<td> 111 <p> 112 typename SvgCoordinateType 113 </p> 114 </td> 115<td> 116 <p> 117 double 118 </p> 119 </td> 120<td> 121 <p> 122 Coordinate type of SVG points. SVG is capable to use floating 123 point coordinates. Therefore the default value is double 124 </p> 125 </td> 126</tr> 127</tbody> 128</table></div> 129<h6> 130<a name="geometry.reference.io.svg.svg_mapper.h2"></a> 131 <span class="phrase"><a name="geometry.reference.io.svg.svg_mapper.constructor_s_"></a></span><a class="link" href="svg_mapper.html#geometry.reference.io.svg.svg_mapper.constructor_s_">Constructor(s)</a> 132 </h6> 133<div class="informaltable"><table class="table"> 134<colgroup> 135<col> 136<col> 137<col> 138</colgroup> 139<thead><tr> 140<th> 141 <p> 142 Function 143 </p> 144 </th> 145<th> 146 <p> 147 Description 148 </p> 149 </th> 150<th> 151 <p> 152 Parameters 153 </p> 154 </th> 155</tr></thead> 156<tbody> 157<tr> 158<td> 159 <p> 160</p> 161<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">svg_mapper</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream</span> <span class="special">&</span> <span class="identifier">stream</span><span class="special">,</span> <span class="identifier">SvgCoordinateType</span> <span class="identifier">width</span><span class="special">,</span> <span class="identifier">SvgCoordinateType</span> <span class="identifier">height</span><span class="special">,</span> 162 <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">width_height</span> <span class="special">=</span> <span class="string">"width=\"100%\" height=\"100%\""</span><span class="special">)</span></pre> 163<p> 164 </p> 165 </td> 166<td> 167 <p> 168 Constructor, initializing the SVG map. Opens and initializes 169 the SVG. Should be called explicitly. 170 </p> 171 </td> 172<td> 173 <p> 174 <span class="bold"><strong>std::ostream &</strong></span>: <span class="emphasis"><em>stream</em></span>: 175 Output stream, should be a stream already open 176 </p> 177 <p> 178 <span class="bold"><strong>SvgCoordinateType</strong></span>: <span class="emphasis"><em>width</em></span>: 179 Width of the SVG map (in SVG pixels) 180 </p> 181 <p> 182 <span class="bold"><strong>SvgCoordinateType</strong></span>: <span class="emphasis"><em>height</em></span>: 183 Height of the SVG map (in SVG pixels) 184 </p> 185 <p> 186 <span class="bold"><strong>std::string const &</strong></span>: 187 <span class="emphasis"><em>width_height</em></span>: Optional information to 188 increase width and/or height 189 </p> 190 </td> 191</tr> 192<tr> 193<td> 194 <p> 195</p> 196<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">~</span><span class="identifier">svg_mapper</span><span class="special">()</span></pre> 197<p> 198 </p> 199 </td> 200<td> 201 <p> 202 Destructor, called automatically. Closes the SVG by streaming 203 </svg> 204 </p> 205 </td> 206<td> 207 </td> 208</tr> 209</tbody> 210</table></div> 211<h6> 212<a name="geometry.reference.io.svg.svg_mapper.h3"></a> 213 <span class="phrase"><a name="geometry.reference.io.svg.svg_mapper.member_function_s_"></a></span><a class="link" href="svg_mapper.html#geometry.reference.io.svg.svg_mapper.member_function_s_">Member 214 Function(s)</a> 215 </h6> 216<div class="informaltable"><table class="table"> 217<colgroup> 218<col> 219<col> 220<col> 221<col> 222</colgroup> 223<thead><tr> 224<th> 225 <p> 226 Function 227 </p> 228 </th> 229<th> 230 <p> 231 Description 232 </p> 233 </th> 234<th> 235 <p> 236 Parameters 237 </p> 238 </th> 239<th> 240 <p> 241 Returns 242 </p> 243 </th> 244</tr></thead> 245<tbody> 246<tr> 247<td> 248 <p> 249</p> 250<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">Geometry</span><span class="special">></span> 251<span class="keyword">void</span> <span class="identifier">add</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></pre> 252<p> 253 </p> 254 </td> 255<td> 256 <p> 257 Adds a geometry to the transformation matrix. After doing this, 258 the specified geometry can be mapped fully into the SVG map. 259 </p> 260 </td> 261<td> 262 <p> 263 <span class="bold"><strong>Geometry const &</strong></span>: <span class="emphasis"><em>geometry</em></span>: 264 A model of the specified concept 265 </p> 266 </td> 267<td> 268 </td> 269</tr> 270<tr> 271<td> 272 <p> 273</p> 274<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">Geometry</span><span class="special">></span> 275<span class="keyword">void</span> <span class="identifier">map</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">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">style</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">size</span> <span class="special">=</span> <span class="special">-</span><span class="number">1.0</span><span class="special">)</span></pre> 276<p> 277 </p> 278 </td> 279<td> 280 <p> 281 Maps a geometry into the SVG map using the specified style. 282 </p> 283 </td> 284<td> 285 <p> 286 <span class="bold"><strong>Geometry const &</strong></span>: <span class="emphasis"><em>geometry</em></span>: 287 A model of the specified concept 288 </p> 289 <p> 290 <span class="bold"><strong>std::string const &</strong></span>: 291 <span class="emphasis"><em>style</em></span>: String containing verbatim SVG 292 style information 293 </p> 294 <p> 295 <span class="bold"><strong>double</strong></span>: <span class="emphasis"><em>size</em></span>: 296 Optional size (used for SVG points) in SVG pixels. For linestrings, 297 specify linewidth in the SVG style information 298 </p> 299 </td> 300<td> 301 </td> 302</tr> 303<tr> 304<td> 305 <p> 306</p> 307<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">TextPoint</span><span class="special">></span> 308<span class="keyword">void</span> <span class="identifier">text</span><span class="special">(</span><span class="identifier">TextPoint</span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">point</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">s</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="keyword">const</span> <span class="special">&</span> <span class="identifier">style</span><span class="special">,</span> 309 <span class="keyword">double</span> <span class="identifier">offset_x</span> <span class="special">=</span> <span class="number">0.0</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">offset_y</span> <span class="special">=</span> <span class="number">0.0</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">lineheight</span> <span class="special">=</span> <span class="number">10.0</span><span class="special">)</span></pre> 310<p> 311 </p> 312 </td> 313<td> 314 <p> 315 Adds a text to the SVG map. 316 </p> 317 </td> 318<td> 319 <p> 320 <span class="bold"><strong>TextPoint const &</strong></span>: <span class="emphasis"><em>point</em></span>: 321 Location of the text (in map units) 322 </p> 323 <p> 324 <span class="bold"><strong>std::string const &</strong></span>: 325 <span class="emphasis"><em>s</em></span>: The text itself 326 </p> 327 <p> 328 <span class="bold"><strong>std::string const &</strong></span>: 329 <span class="emphasis"><em>style</em></span>: String containing verbatim SVG 330 style information, of the text 331 </p> 332 <p> 333 <span class="bold"><strong>double</strong></span>: <span class="emphasis"><em>offset_x</em></span>: 334 Offset in SVG pixels, defaults to 0 335 </p> 336 <p> 337 <span class="bold"><strong>double</strong></span>: <span class="emphasis"><em>offset_y</em></span>: 338 Offset in SVG pixels, defaults to 0 339 </p> 340 <p> 341 <span class="bold"><strong>double</strong></span>: <span class="emphasis"><em>lineheight</em></span>: 342 Line height in SVG pixels, in case the text contains 343 </p> 344 </td> 345<td> 346 </td> 347</tr> 348</tbody> 349</table></div> 350<h6> 351<a name="geometry.reference.io.svg.svg_mapper.h4"></a> 352 <span class="phrase"><a name="geometry.reference.io.svg.svg_mapper.header"></a></span><a class="link" href="svg_mapper.html#geometry.reference.io.svg.svg_mapper.header">Header</a> 353 </h6> 354<p> 355 Either 356 </p> 357<p> 358 <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> 359 </p> 360<p> 361 Or 362 </p> 363<p> 364 <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">io</span><span class="special">/</span><span class="identifier">svg</span><span class="special">/</span><span class="identifier">svg_mapper</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> 365 </p> 366<h6> 367<a name="geometry.reference.io.svg.svg_mapper.h5"></a> 368 <span class="phrase"><a name="geometry.reference.io.svg.svg_mapper.example"></a></span><a class="link" href="svg_mapper.html#geometry.reference.io.svg.svg_mapper.example">Example</a> 369 </h6> 370<p> 371 Shows the usage of svg_mapper 372 </p> 373<p> 374</p> 375<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span> 376<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">fstream</span><span class="special">></span> 377 378<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> 379<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> 380<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> 381 382<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> 383<span class="special">{</span> 384 <span class="comment">// Specify the basic type</span> 385 <span class="keyword">typedef</span> <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> <span class="identifier">point_type</span><span class="special">;</span> 386 387 <span class="comment">// Declare some geometries and set their values</span> 388 <span class="identifier">point_type</span> <span class="identifier">a</span><span class="special">;</span> 389 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">assign_values</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span> <span class="number">3</span><span class="special">,</span> <span class="number">6</span><span class="special">);</span> 390 391 <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><span class="special"><</span><span class="identifier">point_type</span><span class="special">></span> <span class="identifier">b</span><span class="special">;</span> 392 <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">"POLYGON((0 0,0 7,4 2,2 0,0 0))"</span><span class="special">,</span> <span class="identifier">b</span><span class="special">);</span> 393 394 <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">linestring</span><span class="special"><</span><span class="identifier">point_type</span><span class="special">></span> <span class="identifier">c</span><span class="special">;</span> 395 <span class="identifier">c</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">point_type</span><span class="special">(</span><span class="number">3</span><span class="special">,</span> <span class="number">4</span><span class="special">));</span> 396 <span class="identifier">c</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">point_type</span><span class="special">(</span><span class="number">4</span><span class="special">,</span> <span class="number">5</span><span class="special">));</span> 397 398 <span class="comment">// Declare a stream and an SVG mapper</span> 399 <span class="identifier">std</span><span class="special">::</span><span class="identifier">ofstream</span> <span class="identifier">svg</span><span class="special">(</span><span class="string">"my_map.svg"</span><span class="special">);</span> 400 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">geometry</span><span class="special">::</span><span class="identifier">svg_mapper</span><span class="special"><</span><span class="identifier">point_type</span><span class="special">></span> <span class="identifier">mapper</span><span class="special">(</span><span class="identifier">svg</span><span class="special">,</span> <span class="number">400</span><span class="special">,</span> <span class="number">400</span><span class="special">);</span> 401 402 <span class="comment">// Add geometries such that all these geometries fit on the map</span> 403 <span class="identifier">mapper</span><span class="special">.</span><span class="identifier">add</span><span class="special">(</span><span class="identifier">a</span><span class="special">);</span> 404 <span class="identifier">mapper</span><span class="special">.</span><span class="identifier">add</span><span class="special">(</span><span class="identifier">b</span><span class="special">);</span> 405 <span class="identifier">mapper</span><span class="special">.</span><span class="identifier">add</span><span class="special">(</span><span class="identifier">c</span><span class="special">);</span> 406 407 <span class="comment">// Draw the geometries on the SVG map, using a specific SVG style</span> 408 <span class="identifier">mapper</span><span class="special">.</span><span class="identifier">map</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span> <span class="string">"fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:2"</span><span class="special">,</span> <span class="number">5</span><span class="special">);</span> 409 <span class="identifier">mapper</span><span class="special">.</span><span class="identifier">map</span><span class="special">(</span><span class="identifier">b</span><span class="special">,</span> <span class="string">"fill-opacity:0.3;fill:rgb(51,51,153);stroke:rgb(51,51,153);stroke-width:2"</span><span class="special">);</span> 410 <span class="identifier">mapper</span><span class="special">.</span><span class="identifier">map</span><span class="special">(</span><span class="identifier">c</span><span class="special">,</span> <span class="string">"opacity:0.4;fill:none;stroke:rgb(212,0,0);stroke-width:5"</span><span class="special">);</span> 411 412 <span class="comment">// Destructor of map will be called - adding </svg></span> 413 <span class="comment">// Destructor of stream will be called, closing the file</span> 414 415 <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span> 416<span class="special">}</span> 417</pre> 418<p> 419 </p> 420<p> 421 Output: 422 </p> 423<p> 424 <span class="inlinemediaobject"><img src="../../../../img/io/svg_mapper.png" alt="svg_mapper"></span> 425 </p> 426<h6> 427<a name="geometry.reference.io.svg.svg_mapper.h6"></a> 428 <span class="phrase"><a name="geometry.reference.io.svg.svg_mapper.see_also"></a></span><a class="link" href="svg_mapper.html#geometry.reference.io.svg.svg_mapper.see_also">See 429 also</a> 430 </h6> 431<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 432 <a class="link" href="svg.html" title="svg">The SVG manipulator</a> 433 </li></ul></div> 434</div> 435<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 436<td align="left"></td> 437<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam 438 Wulkiewicz, Oracle and/or its affiliates<p> 439 Distributed under the Boost Software License, Version 1.0. (See accompanying 440 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>) 441 </p> 442</div></td> 443</tr></table> 444<hr> 445<div class="spirit-nav"> 446<a accesskey="p" href="svg.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../svg.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="../../iterators.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 447</div> 448</body> 449</html> 450