1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>read_wkt</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="../wkt.html" title="WKT (Well-Known Text)"> 9<link rel="prev" href="../wkt.html" title="WKT (Well-Known Text)"> 10<link rel="next" href="wkt.html" title="wkt"> 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="../wkt.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../wkt.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="wkt.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.wkt.read_wkt"></a><a class="link" href="read_wkt.html" title="read_wkt">read_wkt</a> 28</h5></div></div></div> 29<p> 30 <a class="indexterm" name="idm45635681833984"></a> 31Parses OGC Well-Known Text (WKT (Well-Known Text)) into a geometry (any 32 geometry) 33 </p> 34<h6> 35<a name="geometry.reference.io.wkt.read_wkt.h0"></a> 36 <span class="phrase"><a name="geometry.reference.io.wkt.read_wkt.synopsis"></a></span><a class="link" href="read_wkt.html#geometry.reference.io.wkt.read_wkt.synopsis">Synopsis</a> 37 </h6> 38<p> 39</p> 40<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> 41<span class="keyword">void</span> <span class="identifier">read_wkt</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">wkt</span><span class="special">,</span> <span class="identifier">Geometry</span> <span class="special">&</span> <span class="identifier">geometry</span><span class="special">)</span></pre> 42<p> 43 </p> 44<h6> 45<a name="geometry.reference.io.wkt.read_wkt.h1"></a> 46 <span class="phrase"><a name="geometry.reference.io.wkt.read_wkt.parameters"></a></span><a class="link" href="read_wkt.html#geometry.reference.io.wkt.read_wkt.parameters">Parameters</a> 47 </h6> 48<div class="informaltable"><table class="table"> 49<colgroup> 50<col> 51<col> 52<col> 53<col> 54</colgroup> 55<thead><tr> 56<th> 57 <p> 58 Type 59 </p> 60 </th> 61<th> 62 <p> 63 Concept 64 </p> 65 </th> 66<th> 67 <p> 68 Name 69 </p> 70 </th> 71<th> 72 <p> 73 Description 74 </p> 75 </th> 76</tr></thead> 77<tbody> 78<tr> 79<td> 80 <p> 81 std::string const & 82 </p> 83 </td> 84<td> 85 </td> 86<td> 87 <p> 88 wkt 89 </p> 90 </td> 91<td> 92 <p> 93 string containing WKT (Well-Known Text) 94 </p> 95 </td> 96</tr> 97<tr> 98<td> 99 <p> 100 Geometry & 101 </p> 102 </td> 103<td> 104 <p> 105 Any type fulfilling a Geometry Concept 106 </p> 107 </td> 108<td> 109 <p> 110 geometry 111 </p> 112 </td> 113<td> 114 <p> 115 A model of the specified concept output geometry 116 </p> 117 </td> 118</tr> 119</tbody> 120</table></div> 121<h6> 122<a name="geometry.reference.io.wkt.read_wkt.h2"></a> 123 <span class="phrase"><a name="geometry.reference.io.wkt.read_wkt.header"></a></span><a class="link" href="read_wkt.html#geometry.reference.io.wkt.read_wkt.header">Header</a> 124 </h6> 125<p> 126 Either 127 </p> 128<p> 129 <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> 130 </p> 131<p> 132 Or 133 </p> 134<p> 135 <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">wkt</span><span class="special">/</span><span class="identifier">read</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> 136 </p> 137<h6> 138<a name="geometry.reference.io.wkt.read_wkt.h3"></a> 139 <span class="phrase"><a name="geometry.reference.io.wkt.read_wkt.conformance"></a></span><a class="link" href="read_wkt.html#geometry.reference.io.wkt.read_wkt.conformance">Conformance</a> 140 </h6> 141<p> 142 Other libraries refer to this functionality as <span class="bold"><strong>ST_GeomFromText</strong></span> 143 or <span class="bold"><strong>STGeomFromText</strong></span>. That is not done 144 here because Boost.Geometry support more text formats. The name GeomFromText 145 is reserved for future usage, which will then have an indication of the 146 used text format. 147 </p> 148<h6> 149<a name="geometry.reference.io.wkt.read_wkt.h4"></a> 150 <span class="phrase"><a name="geometry.reference.io.wkt.read_wkt.example"></a></span><a class="link" href="read_wkt.html#geometry.reference.io.wkt.read_wkt.example">Example</a> 151 </h6> 152<p> 153 Shows the usage of read_wkt 154 </p> 155<p> 156</p> 157<pre class="programlisting"><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> 158<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> 159<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> 160<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> 161 162<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> 163<span class="special">{</span> 164 <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> 165 166 <span class="identifier">point_type</span> <span class="identifier">a</span><span class="special">;</span> 167 <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">b</span><span class="special">;</span> 168 <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">c</span><span class="special">;</span> 169 <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">box</span><span class="special"><</span><span class="identifier">point_type</span><span class="special">></span> <span class="identifier">d</span><span class="special">;</span> 170 <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">segment</span><span class="special"><</span><span class="identifier">point_type</span><span class="special">></span> <span class="identifier">e</span><span class="special">;</span> 171 172 <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">"POINT(1 2)"</span><span class="special">,</span> <span class="identifier">a</span><span class="special">);</span> 173 <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">"LINESTRING(0 0,2 2,3 1)"</span><span class="special">,</span> <span class="identifier">b</span><span class="special">);</span> 174 <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">c</span><span class="special">);</span> 175 <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">"BOX(0 0,3 3)"</span><span class="special">,</span> <span class="identifier">d</span><span class="special">);</span> 176 <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">"SEGMENT(1 0,3 4)"</span><span class="special">,</span> <span class="identifier">e</span><span class="special">);</span> 177 178 <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span> 179<span class="special">}</span> 180</pre> 181<p> 182 </p> 183<h6> 184<a name="geometry.reference.io.wkt.read_wkt.h5"></a> 185 <span class="phrase"><a name="geometry.reference.io.wkt.read_wkt.see_also"></a></span><a class="link" href="read_wkt.html#geometry.reference.io.wkt.read_wkt.see_also">See 186 also</a> 187 </h6> 188<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 189 <a class="link" href="wkt.html" title="wkt">WKT streaming manipulator</a> 190 </li></ul></div> 191</div> 192<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 193<td align="left"></td> 194<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam 195 Wulkiewicz, Oracle and/or its affiliates<p> 196 Distributed under the Boost Software License, Version 1.0. (See accompanying 197 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>) 198 </p> 199</div></td> 200</tr></table> 201<hr> 202<div class="spirit-nav"> 203<a accesskey="p" href="../wkt.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../wkt.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="wkt.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 204</div> 205</body> 206</html> 207