1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 //
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Use, modification and distribution is subject to the Boost Software License,
5 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7
8 // SOCI example
9
10 // a: using boost::tuple to retrieve points
11
12 // SOCI is a generic C++ template interface to access relational databases
13
14 // To build and run this example:
15 // 1) download SOCI from http://soci.sourceforge.net/
16 // 2) put it in contrib/soci-3.0.0 (or another version/folder, but then update this VCPROJ)
17 // 3) adapt your makefile or use this VCPROJ file
18 // (note that SOCI sources are included directly, building SOCI is not necessary)
19 // 4) load the demo-data, see script data/cities.sql (for PostgreSQL)
20
21 #include <soci.h>
22 #include <soci-postgresql.h>
23
24 #include <boost/algorithm/string.hpp>
25 #include <boost/optional.hpp>
26 #include <boost/timer.hpp>
27 #include <boost/random.hpp>
28 #include <boost/tuple/tuple.hpp>
29
30 #include <iostream>
31 #include <istream>
32 #include <ostream>
33 #include <sstream>
34 #include <string>
35 #include <exception>
36
37 #include <boost/geometry/geometry.hpp>
38 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
39
40 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian);
41
42
main()43 int main()
44 {
45 try
46 {
47 soci::session sql(soci::postgresql, "dbname=ggl user=ggl password=ggl");
48
49 int count;
50 sql << "select count(*) from cities", soci::into(count);
51 std::cout << "# Capitals: " << count << std::endl;
52
53 typedef std::vector<boost::tuple<double, double> > V;
54
55 soci::rowset<boost::tuple<double, double> > rows
56 = sql.prepare << "select x(location),y(location) from cities";
57 V vec;
58 std::copy(rows.begin(), rows.end(), std::back_inserter(vec));
59
60 for (V::const_iterator it = vec.begin(); it != vec.end(); ++it)
61 {
62 std::cout << it->get<0>() << " " << it->get<1>() << std::endl;
63 }
64 // Calculate distances
65 for (V::const_iterator it1 = vec.begin(); it1 != vec.end(); ++it1)
66 {
67 for (V::const_iterator it2 = vec.begin(); it2 != vec.end(); ++it2)
68 {
69 std::cout << boost::geometry::dsv(*it1) << " " << boost::geometry::distance(*it1, *it2) << std::endl;
70 }
71 }
72 }
73 catch (std::exception const &e)
74 {
75 std::cerr << "Error: " << e.what() << '\n';
76 }
77 return 0;
78 }
79