mirror of
https://github.com/boostorg/geometry.git
synced 2026-02-13 12:32:09 +00:00
142 lines
6.6 KiB
HTML
142 lines
6.6 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
<title>Boost.Geometry (aka GGL, Generic Geometry Library)</title>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css">
|
|
<link href="tabs.css" rel="stylesheet" type="text/css">
|
|
</head>
|
|
|
|
<table cellpadding="2" width="100%">
|
|
<tbody>
|
|
<tr>
|
|
<td valign="top">
|
|
<img alt="Boost.Geometry" src="images/ggl-logo-big.png" height="80" width="200">
|
|
|
|
</td>
|
|
<td valign="top" align="right">
|
|
<a href="http://www.boost.org">
|
|
<img alt="Boost C++ Libraries" src="images/accepted_by_boost.png" height="80" width="230" border="0">
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<!-- Generated by Doxygen 1.5.9 -->
|
|
<div class="navigation" id="top">
|
|
<div class="tabs">
|
|
<ul>
|
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
|
<li><a href="pages.html"><span>Related Pages</span></a></li>
|
|
<li><a href="modules.html"><span>Modules</span></a></li>
|
|
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
|
|
<li><a href="annotated.html"><span>Classes</span></a></li>
|
|
<li><a href="files.html"><span>Files</span></a></li>
|
|
<li><a href="examples.html"><span>Examples</span></a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="contents">
|
|
<h1>x03_a_soci_example.cpp</h1>First example showing how to get spatial data from a database using SOCI and put them into GGL<p>
|
|
<div class="fragment"><pre class="fragment"><span class="comment">// Boost.Geometry (aka GGL, Generic Geometry Library)</span>
|
|
<span class="comment">//</span>
|
|
<span class="comment">// Copyright Barend Gehrels 2007-2009, Geodan, Amsterdam, the Netherlands</span>
|
|
<span class="comment">// Use, modification and distribution is subject to the Boost Software License,</span>
|
|
<span class="comment">// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at</span>
|
|
<span class="comment">// http://www.boost.org/LICENSE_1_0.txt)</span>
|
|
|
|
<span class="comment">// SOCI example</span>
|
|
|
|
<span class="comment">// a: using boost::tuple to retrieve points</span>
|
|
|
|
<span class="comment">// SOCI is a generic C++ template interface to access relational databases</span>
|
|
|
|
<span class="comment">// To build and run this example:</span>
|
|
<span class="comment">// 1) download SOCI from http://soci.sourceforge.net/</span>
|
|
<span class="comment">// 2) put it in contrib/soci-3.0.0 (or another version/folder, but then update this VCPROJ)</span>
|
|
<span class="comment">// 3) adapt your makefile or use this VCPROJ file</span>
|
|
<span class="comment">// (note that SOCI sources are included directly, building SOCI is not necessary)</span>
|
|
<span class="comment">// 4) load the demo-data, see script data/cities.sql (for PostgreSQL)</span>
|
|
|
|
<span class="preprocessor">#include <soci.h></span>
|
|
<span class="preprocessor">#include <soci-postgresql.h></span>
|
|
|
|
<span class="preprocessor">#include <boost/algorithm/string.hpp></span>
|
|
<span class="preprocessor">#include <boost/optional.hpp></span>
|
|
<span class="preprocessor">#include <boost/timer.hpp></span>
|
|
<span class="preprocessor">#include <boost/random.hpp></span>
|
|
<span class="preprocessor">#include <boost/tuple/tuple.hpp></span>
|
|
|
|
<span class="preprocessor">#include <iostream></span>
|
|
<span class="preprocessor">#include <istream></span>
|
|
<span class="preprocessor">#include <ostream></span>
|
|
<span class="preprocessor">#include <sstream></span>
|
|
<span class="preprocessor">#include <string></span>
|
|
<span class="preprocessor">#include <exception></span>
|
|
|
|
<span class="preprocessor">#include <boost/geometry/geometry.hpp></span>
|
|
<span class="preprocessor">#include <<a class="code" href="tuple__cartesian_8hpp.html">boost/geometry/geometries/adapted/tuple_cartesian.hpp</a>></span>
|
|
<span class="preprocessor">#include <boost/geometry/extensions/gis/io/wkt/wkt.hpp></span>
|
|
|
|
|
|
|
|
<span class="keywordtype">int</span> main()
|
|
{
|
|
<span class="keywordflow">try</span>
|
|
{
|
|
soci::session sql(soci::postgresql, <span class="stringliteral">"dbname=ggl user=ggl password=ggl"</span>);
|
|
|
|
<span class="keywordtype">int</span> count;
|
|
sql << <span class="stringliteral">"select count(*) from cities"</span>, soci::into(count);
|
|
std::cout << <span class="stringliteral">"# Capitals: "</span> << count << std::endl;
|
|
|
|
<span class="keyword">typedef</span> std::vector<boost::tuple<double, double> > V;
|
|
|
|
soci::rowset<boost::tuple<double, double> > rows
|
|
= sql.prepare << <span class="stringliteral">"select x(location),y(location) from cities"</span>;
|
|
V vec;
|
|
std::copy(rows.begin(), rows.end(), std::back_inserter(vec));
|
|
|
|
<span class="keywordflow">for</span> (V::const_iterator it = vec.begin(); it != vec.end(); ++it)
|
|
{
|
|
std::cout << it->get<0>() << <span class="stringliteral">" "</span> << it->get<1>() << std::endl;
|
|
}
|
|
<span class="comment">// Calculate distances</span>
|
|
<span class="keywordflow">for</span> (V::const_iterator it1 = vec.begin(); it1 != vec.end(); ++it1)
|
|
{
|
|
<span class="keywordflow">for</span> (V::const_iterator it2 = vec.begin(); it2 != vec.end(); ++it2)
|
|
{
|
|
std::cout << <a name="a0"></a><a class="code" href="group__utility.html#g62cc5db4d3bb1147591298b3500f8f1a" title="Main DSV-streaming function.">boost::geometry::dsv</a>(*it1) << <span class="stringliteral">" "</span> << <a name="a1"></a><a class="code" href="group__distance.html#g8fb8022d64a75b24c80a64ba46ec4738" title="Calculate distance between two geometries with a specified strategy.">boost::geometry::distance</a>(*it1, *it2) << std::endl;
|
|
}
|
|
}
|
|
}
|
|
<span class="keywordflow">catch</span> (std::exception <span class="keyword">const</span> &e)
|
|
{
|
|
std::cerr << <span class="stringliteral">"Error: "</span> << e.what() << <span class="charliteral">'\n'</span>;
|
|
}
|
|
<span class="keywordflow">return</span> 0;
|
|
}
|
|
</pre></div> </div>
|
|
<hr size="1">
|
|
<table width="100%">
|
|
<tbody>
|
|
<tr>
|
|
<td align="left"><small>
|
|
<p>December 1, 2009</p>
|
|
</small></td>
|
|
<td align="right">
|
|
<small>Copyright © 1995-2009 Barend Gehrels, Geodan, Amsterdam<br>
|
|
Copyright © 2008-2009 Bruno Lalande, Paris<br>
|
|
Copyright © 2009 Mateusz Loskot, Cadcorp, London<br>
|
|
</small>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<address style="text-align: right;"><small>
|
|
Documentation is generated by <a href="http://www.doxygen.org/index.html">Doxygen</a>
|
|
</small></address>
|
|
</body>
|
|
</html>
|