1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>is_valid (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="../is_valid.html" title="is_valid"> 9<link rel="prev" href="../is_valid.html" title="is_valid"> 10<link rel="next" href="is_valid_1.html" title="is_valid"> 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="../is_valid.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../is_valid.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="is_valid_1.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.is_valid.is_valid_2_with_strategy"></a><a class="link" href="is_valid_2_with_strategy.html" title="is_valid (with strategy)">is_valid 28 (with strategy)</a> 29</h5></div></div></div> 30<p> 31 <a class="indexterm" name="idm45635694504816"></a> 32Checks if a geometry is valid (in the OGC sense) 33 </p> 34<h6> 35<a name="geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.h0"></a> 36 <span class="phrase"><a name="geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.synopsis"></a></span><a class="link" href="is_valid_2_with_strategy.html#geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.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> <span class="keyword">typename</span> <span class="identifier">Strategy</span><span class="special">></span> 41<span class="keyword">bool</span> <span class="identifier">is_valid</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> 42<p> 43 </p> 44<h6> 45<a name="geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.h1"></a> 46 <span class="phrase"><a name="geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.parameters"></a></span><a class="link" href="is_valid_2_with_strategy.html#geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.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 Geometry const & 82 </p> 83 </td> 84<td> 85 <p> 86 Any type fulfilling a Geometry Concept 87 </p> 88 </td> 89<td> 90 <p> 91 geometry 92 </p> 93 </td> 94<td> 95 <p> 96 A model of the specified concept 97 </p> 98 </td> 99</tr> 100<tr> 101<td> 102 <p> 103 Strategy const & 104 </p> 105 </td> 106<td> 107 <p> 108 Any type fulfilling a Is_valid Strategy Concept 109 </p> 110 </td> 111<td> 112 <p> 113 strategy 114 </p> 115 </td> 116<td> 117 <p> 118 The strategy which will be used for is_valid calculations 119 </p> 120 </td> 121</tr> 122</tbody> 123</table></div> 124<h6> 125<a name="geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.h2"></a> 126 <span class="phrase"><a name="geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.returns"></a></span><a class="link" href="is_valid_2_with_strategy.html#geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.returns">Returns</a> 127 </h6> 128<p> 129 Returns true if the geometry is valid (in the OGC sense); furthermore, 130 the following geometries are considered valid: multi-geometries with 131 no elements, linear geometries containing spikes, areal geometries with 132 duplicate (consecutive) points 133 </p> 134<h6> 135<a name="geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.h3"></a> 136 <span class="phrase"><a name="geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.header"></a></span><a class="link" href="is_valid_2_with_strategy.html#geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.header">Header</a> 137 </h6> 138<p> 139 Either 140 </p> 141<p> 142 <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> 143 </p> 144<p> 145 Or 146 </p> 147<p> 148 <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">is_valid</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> 149 </p> 150<h6> 151<a name="geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.h4"></a> 152 <span class="phrase"><a name="geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.conformance"></a></span><a class="link" href="is_valid_2_with_strategy.html#geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.conformance">Conformance</a> 153 </h6> 154<p> 155 The function is_valid is not defined by OGC. 156 </p> 157<h6> 158<a name="geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.h5"></a> 159 <span class="phrase"><a name="geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.supported_geometries"></a></span><a class="link" href="is_valid_2_with_strategy.html#geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.supported_geometries">Supported 160 geometries</a> 161 </h6> 162<div class="informaltable"><table class="table"> 163<colgroup> 164<col> 165<col> 166</colgroup> 167<thead><tr> 168<th> 169 <p> 170 Geometry 171 </p> 172 </th> 173<th> 174 <p> 175 Status 176 </p> 177 </th> 178</tr></thead> 179<tbody> 180<tr> 181<td> 182 <p> 183 Point 184 </p> 185 </td> 186<td> 187 <p> 188 <span class="inlinemediaobject"><img src="../../../../img/ok.png" alt="ok"></span> 189 </p> 190 </td> 191</tr> 192<tr> 193<td> 194 <p> 195 Segment 196 </p> 197 </td> 198<td> 199 <p> 200 <span class="inlinemediaobject"><img src="../../../../img/ok.png" alt="ok"></span> 201 </p> 202 </td> 203</tr> 204<tr> 205<td> 206 <p> 207 Box 208 </p> 209 </td> 210<td> 211 <p> 212 <span class="inlinemediaobject"><img src="../../../../img/ok.png" alt="ok"></span> 213 </p> 214 </td> 215</tr> 216<tr> 217<td> 218 <p> 219 Linestring 220 </p> 221 </td> 222<td> 223 <p> 224 <span class="inlinemediaobject"><img src="../../../../img/ok.png" alt="ok"></span> 225 </p> 226 </td> 227</tr> 228<tr> 229<td> 230 <p> 231 Ring 232 </p> 233 </td> 234<td> 235 <p> 236 <span class="inlinemediaobject"><img src="../../../../img/ok.png" alt="ok"></span> 237 </p> 238 </td> 239</tr> 240<tr> 241<td> 242 <p> 243 Polygon 244 </p> 245 </td> 246<td> 247 <p> 248 <span class="inlinemediaobject"><img src="../../../../img/ok.png" alt="ok"></span> 249 </p> 250 </td> 251</tr> 252<tr> 253<td> 254 <p> 255 MultiPoint 256 </p> 257 </td> 258<td> 259 <p> 260 <span class="inlinemediaobject"><img src="../../../../img/ok.png" alt="ok"></span> 261 </p> 262 </td> 263</tr> 264<tr> 265<td> 266 <p> 267 MultiLinestring 268 </p> 269 </td> 270<td> 271 <p> 272 <span class="inlinemediaobject"><img src="../../../../img/ok.png" alt="ok"></span> 273 </p> 274 </td> 275</tr> 276<tr> 277<td> 278 <p> 279 MultiPolygon 280 </p> 281 </td> 282<td> 283 <p> 284 <span class="inlinemediaobject"><img src="../../../../img/ok.png" alt="ok"></span> 285 </p> 286 </td> 287</tr> 288<tr> 289<td> 290 <p> 291 Variant 292 </p> 293 </td> 294<td> 295 <p> 296 <span class="inlinemediaobject"><img src="../../../../img/ok.png" alt="ok"></span> 297 </p> 298 </td> 299</tr> 300</tbody> 301</table></div> 302<h6> 303<a name="geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.h6"></a> 304 <span class="phrase"><a name="geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.complexity"></a></span><a class="link" href="is_valid_2_with_strategy.html#geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.complexity">Complexity</a> 305 </h6> 306<p> 307 Constant-time for points, segments, boxes and multi-points 308 </p> 309<p> 310 Linear for linestrings and multi-linestrings 311 </p> 312<p> 313 Linearithmic for rings 314 </p> 315<p> 316 Currently, worst-case quadratic for polygons and multi-polygons 317 </p> 318<h6> 319<a name="geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.h7"></a> 320 <span class="phrase"><a name="geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.example"></a></span><a class="link" href="is_valid_2_with_strategy.html#geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.example">Example</a> 321 </h6> 322<p> 323 Checks whether a geometry is valid 324 </p> 325<p> 326</p> 327<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span> 328 329<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> 330<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> 331<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> 332 333 334<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> 335<span class="special">{</span> 336 <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> 337 <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">polygon</span><span class="special"><</span><span class="identifier">point_type</span><span class="special">></span> <span class="identifier">polygon_type</span><span class="special">;</span> 338 339 <span class="identifier">polygon_type</span> <span class="identifier">poly</span><span class="special">;</span> 340 <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 10,10 10,10 0,0 0),(0 0,9 1,9 2,0 0),(0 0,2 9,1 9,0 0),(2 9,9 2,9 9,2 9))"</span><span class="special">,</span> <span class="identifier">poly</span><span class="special">);</span> 341 342 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"is valid? "</span> <span class="special"><<</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">is_valid</span><span class="special">(</span><span class="identifier">poly</span><span class="special">)</span> <span class="special">?</span> <span class="string">"yes"</span> <span class="special">:</span> <span class="string">"no"</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 343 344 <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span> 345<span class="special">}</span> 346</pre> 347<p> 348 </p> 349<p> 350 Output: 351 </p> 352<pre class="programlisting">is valid? no 353 354<img src="../../../../img/algorithms/is_valid_example.png" alt="is_valid_example"> 355 356</pre> 357<h6> 358<a name="geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.h8"></a> 359 <span class="phrase"><a name="geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.see_also"></a></span><a class="link" href="is_valid_2_with_strategy.html#geometry.reference.algorithms.is_valid.is_valid_2_with_strategy.see_also">See 360 also</a> 361 </h6> 362<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> 363 <a class="link" href="../is_simple.html" title="is_simple">is_simple</a> 364 </li></ul></div> 365</div> 366<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 367<td align="left"></td> 368<td align="right"><div class="copyright-footer">Copyright © 2009-2019 Barend Gehrels, Bruno Lalande, Mateusz Loskot, Adam 369 Wulkiewicz, Oracle and/or its affiliates<p> 370 Distributed under the Boost Software License, Version 1.0. (See accompanying 371 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>) 372 </p> 373</div></td> 374</tr></table> 375<hr> 376<div class="spirit-nav"> 377<a accesskey="p" href="../is_valid.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../is_valid.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="is_valid_1.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 378</div> 379</body> 380</html> 381