Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r70920 - in branches/release/libs/geometry/example: . with_external_libs
From: barend.gehrels_at_[hidden]
Date: 2011-04-03 03:55:47


Author: barendgehrels
Date: 2011-04-03 03:55:46 EDT (Sun, 03 Apr 2011)
New Revision: 70920
URL: http://svn.boost.org/trac/boost/changeset/70920

Log:
Merged changes with ifdefs for release branch
Removed:
   branches/release/libs/geometry/example/c03_custom_linestring_example.cpp
   branches/release/libs/geometry/example/with_external_libs/x02_gd_example.cpp
   branches/release/libs/geometry/example/with_external_libs/x03_c_soci_example.cpp
   branches/release/libs/geometry/example/with_external_libs/x03_d_soci_example.cpp
Properties modified:
   branches/release/libs/geometry/example/ (props changed)
Text files modified:
   branches/release/libs/geometry/example/05_a_overlay_polygon_example.cpp | 12 ++++++++++--
   branches/release/libs/geometry/example/05_b_overlay_linestring_polygon_example.cpp | 9 +++++++--
   branches/release/libs/geometry/example/06_b_transformation_example.cpp | 11 ++++++++---
   branches/release/libs/geometry/example/07_a_graph_route_example.cpp | 19 ++++++++++++++-----
   branches/release/libs/geometry/example/07_b_graph_route_example.cpp | 18 +++++++++++++-----
   branches/release/libs/geometry/example/Jamfile.v2 | 2 +-
   6 files changed, 53 insertions(+), 18 deletions(-)

Modified: branches/release/libs/geometry/example/05_a_overlay_polygon_example.cpp
==============================================================================
--- branches/release/libs/geometry/example/05_a_overlay_polygon_example.cpp (original)
+++ branches/release/libs/geometry/example/05_a_overlay_polygon_example.cpp 2011-04-03 03:55:46 EDT (Sun, 03 Apr 2011)
@@ -21,7 +21,9 @@
 #include <boost/geometry/geometry.hpp>
 #include <boost/geometry/geometries/adapted/c_array_cartesian.hpp>
 
-#include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+#if defined(HAVE_SVG)
+# include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+#endif
 
 
 int main(void)
@@ -32,8 +34,10 @@
     typedef bg::model::polygon<point_2d> polygon_2d;
 
 
+#if defined(HAVE_SVG)
     std::ofstream stream("05_a_intersection_polygon_example.svg");
     bg::svg_mapper<point_2d> svg(stream, 500, 500);
+#endif
 
     // Define a polygons and fill the outer rings.
     polygon_2d a;
@@ -45,7 +49,6 @@
     }
     bg::correct(a);
     std::cout << "A: " << bg::dsv(a) << std::endl;
- svg.add(a);
 
     polygon_2d b;
     {
@@ -56,10 +59,13 @@
     }
     bg::correct(b);
     std::cout << "B: " << bg::dsv(b) << std::endl;
+#if defined(HAVE_SVG)
+ svg.add(a);
     svg.add(b);
 
     svg.map(a, "opacity:0.6;fill:rgb(0,255,0);");
     svg.map(b, "opacity:0.6;fill:rgb(0,0,255);");
+#endif
 
 
     // Calculate interesection(s)
@@ -70,7 +76,9 @@
     BOOST_FOREACH(polygon_2d const& polygon, intersection)
     {
         std::cout << bg::dsv(polygon) << std::endl;
+#if defined(HAVE_SVG)
         svg.map(polygon, "opacity:0.5;fill:none;stroke:rgb(255,0,0);stroke-width:6");
+#endif
     }
 
     return 0;

Modified: branches/release/libs/geometry/example/05_b_overlay_linestring_polygon_example.cpp
==============================================================================
--- branches/release/libs/geometry/example/05_b_overlay_linestring_polygon_example.cpp (original)
+++ branches/release/libs/geometry/example/05_b_overlay_linestring_polygon_example.cpp 2011-04-03 03:55:46 EDT (Sun, 03 Apr 2011)
@@ -21,7 +21,9 @@
 #include <boost/geometry/geometry.hpp>
 #include <boost/geometry/geometries/adapted/c_array_cartesian.hpp>
 
-#include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+#if defined(HAVE_SVG)
+# include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+#endif
 
 
 int main(void)
@@ -43,6 +45,7 @@
     }
     bg::correct(p);
 
+#if defined(HAVE_SVG)
     // Create SVG-mapper
     std::ofstream stream("05_b_overlay_linestring_polygon_example.svg");
     bg::svg_mapper<point_2d> svg(stream, 500, 500);
@@ -52,7 +55,7 @@
     // Map geometries
     svg.map(ls, "opacity:0.6;stroke:rgb(255,0,0);stroke-width:2;");
     svg.map(p, "opacity:0.6;fill:rgb(0,0,255);");
-
+#endif
 
     // Calculate intersection points (turn points)
     typedef bg::detail::overlay::turn_info<point_2d> turn_info;
@@ -76,8 +79,10 @@
 
         }
         std::cout << action << " polygon at " << bg::dsv(turn.point) << std::endl;
+#if defined(HAVE_SVG)
         svg.map(turn.point, "fill:rgb(255,128,0);stroke:rgb(0,0,100);stroke-width:1");
         svg.text(turn.point, action, "fill:rgb(0,0,0);font-family:Arial;font-size:10px");
+#endif
     }
 
     return 0;

Modified: branches/release/libs/geometry/example/06_b_transformation_example.cpp
==============================================================================
--- branches/release/libs/geometry/example/06_b_transformation_example.cpp (original)
+++ branches/release/libs/geometry/example/06_b_transformation_example.cpp 2011-04-03 03:55:46 EDT (Sun, 03 Apr 2011)
@@ -19,9 +19,12 @@
 #include <boost/geometry/algorithms/centroid.hpp>
 #include <boost/geometry/strategies/transform.hpp>
 #include <boost/geometry/strategies/transform/matrix_transformers.hpp>
-#include <boost/geometry/extensions/io/svg/write_svg.hpp>
 #include <boost/geometry/domains/gis/io/wkt/read_wkt.hpp>
 
+#if defined(HAVE_SVG)
+# include <boost/geometry/extensions/io/svg/write_svg.hpp>
+#endif
+
 #include <boost/bind.hpp>
 #include <boost/random.hpp>
 #include <boost/range.hpp>
@@ -84,8 +87,9 @@
     void put(G const& g, std::string const& label)
     {
         std::string style_str(style.fill(opacity) + style.stroke(5, opacity));
- os << ::boost::geometry::svg(g, style_str) << std::endl;
-
+#if defined(HAVE_SVG)
+ os << boost::geometry::svg(g, style_str) << std::endl;
+#endif
         if (!label.empty())
         {
             typename point_type<G>::type c;
@@ -101,6 +105,7 @@
     random_style style;
 };
 
+
 int main()
 {
     using namespace boost::geometry::strategy::transform;

Modified: branches/release/libs/geometry/example/07_a_graph_route_example.cpp
==============================================================================
--- branches/release/libs/geometry/example/07_a_graph_route_example.cpp (original)
+++ branches/release/libs/geometry/example/07_a_graph_route_example.cpp 2011-04-03 03:55:46 EDT (Sun, 03 Apr 2011)
@@ -30,10 +30,12 @@
 // Yes, this example currently uses some extensions:
 
     // For output:
- #include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+ #if defined(HAVE_SVG)
+ # include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+ #endif
 
     // For distance-calculations over the Earth:
- #include <boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp>
+ //#include <boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp>
 
 
 
@@ -260,10 +262,11 @@
 
 int main()
 {
- // Define a point in the Geographic coordinate system
+ // Define a point in the Geographic coordinate system (currently Spherical)
+ // (geographic calculations are in an extension; for sample it makes no difference)
     typedef boost::geometry::model::point
         <
- double, 2, boost::geometry::cs::geographic<boost::geometry::degree>
+ double, 2, boost::geometry::cs::spherical<boost::geometry::degree>
> point_type;
 
     typedef boost::geometry::model::linestring<point_type> line_type;
@@ -302,8 +305,12 @@
     double const km = 1000.0;
     std::cout << "distances, all in KM" << std::endl
         << std::fixed << std::setprecision(0);
+
+ // To calculate distance, declare and construct a strategy with average earth radius
+ boost::geometry::strategy::distance::haversine<point_type> haversine(6372795.0);
 
     // Main functionality: calculate shortest routes from/to all cities
+
 
     // For the first one, the complete route is stored as a linestring
     bool first = true;
@@ -329,7 +336,7 @@
             if (! boost::equals(city1.get<1>(), city2.get<1>()))
             {
                 double distance = costs[city2.get<2>()] / km;
- double acof = boost::geometry::distance(city1.get<0>(), city2.get<0>()) / km;
+ double acof = boost::geometry::distance(city1.get<0>(), city2.get<0>(), haversine) / km;
 
                 std::cout
                     << std::setiosflags (std::ios_base::left) << std::setw(15)
@@ -351,6 +358,7 @@
         }
     }
 
+#if defined(HAVE_SVG)
     // Create the SVG
     std::ofstream stream("routes.svg");
     boost::geometry::svg_mapper<point_type> mapper(stream, 600, 600);
@@ -378,6 +386,7 @@
         mapper.text(city.get<0>(), city.get<1>(),
                 "fill:rgb(0,0,0);font-family:Arial;font-size:10px", 5, 5);
     }
+#endif
 
     return 0;
 }

Modified: branches/release/libs/geometry/example/07_b_graph_route_example.cpp
==============================================================================
--- branches/release/libs/geometry/example/07_b_graph_route_example.cpp (original)
+++ branches/release/libs/geometry/example/07_b_graph_route_example.cpp 2011-04-03 03:55:46 EDT (Sun, 03 Apr 2011)
@@ -34,10 +34,12 @@
 // Yes, this example currently uses some extensions:
 
     // For output:
- #include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+ #if defined(HAVE_SVG)
+ # include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+ #endif
 
     // For distance-calculations over the Earth:
- #include <boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp>
+ //#include <boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp>
 
 
 
@@ -246,10 +248,11 @@
 
 int main()
 {
- // Define a point in the Geographic coordinate system
+ // Define a point in the Geographic coordinate system (currently Spherical)
+ // (geographic calculations are in an extension; for sample it makes no difference)
     typedef boost::geometry::model::point
         <
- double, 2, boost::geometry::cs::geographic<boost::geometry::degree>
+ double, 2, boost::geometry::cs::spherical<boost::geometry::degree>
> point_type;
 
     typedef boost::geometry::model::linestring<point_type> line_type;
@@ -291,6 +294,9 @@
     std::cout << "distances, all in KM" << std::endl
         << std::fixed << std::setprecision(0);
 
+ // To calculate distance, declare and construct a strategy with average earth radius
+ boost::geometry::strategy::distance::haversine<point_type> haversine(6372795.0);
+
     // Main functionality: calculate shortest routes from/to all cities
 
     // For the first one, the complete route is stored as a linestring
@@ -317,7 +323,7 @@
             if (! boost::equals(city1.get<1>(), city2.get<1>()))
             {
                 double distance = costs[city2.get<2>()] / km;
- double acof = boost::geometry::distance(city1.get<0>(), city2.get<0>()) / km;
+ double acof = boost::geometry::distance(city1.get<0>(), city2.get<0>(), haversine) / km;
 
                 std::cout
                     << std::setiosflags (std::ios_base::left) << std::setw(15)
@@ -339,6 +345,7 @@
         }
     }
 
+#if defined(HAVE_SVG)
     // Create the SVG
     std::ofstream stream("routes.svg");
     boost::geometry::svg_mapper<point_type> mapper(stream, 600, 600);
@@ -366,6 +373,7 @@
         mapper.text(city.get<0>(), city.get<1>(),
                 "fill:rgb(0,0,0);font-family:Arial;font-size:10px", 5, 5);
     }
+#endif
 
     return 0;
 }

Modified: branches/release/libs/geometry/example/Jamfile.v2
==============================================================================
--- branches/release/libs/geometry/example/Jamfile.v2 (original)
+++ branches/release/libs/geometry/example/Jamfile.v2 2011-04-03 03:55:46 EDT (Sun, 03 Apr 2011)
@@ -26,7 +26,7 @@
 
 exe c01_custom_point_example : c01_custom_point_example.cpp ;
 exe c02_custom_box_example : c02_custom_box_example.cpp ;
-exe c03_custom_linestring_example : c03_custom_linestring_example.cpp ;
+# exe c03_custom_linestring_example : c03_custom_linestring_example.cpp ;
 exe c04_a_custom_triangle_example : c04_a_custom_triangle_example.cpp ;
 exe c04_b_custom_triangle_example : c04_b_custom_triangle_example.cpp ;
 exe c06_custom_polygon_example : c06_custom_polygon_example.cpp ;

Deleted: branches/release/libs/geometry/example/c03_custom_linestring_example.cpp
==============================================================================
--- branches/release/libs/geometry/example/c03_custom_linestring_example.cpp 2011-04-03 03:55:46 EDT (Sun, 03 Apr 2011)
+++ (empty file)
@@ -1,88 +0,0 @@
-// Boost.Geometry (aka GGL, Generic Geometry Library)
-
-// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
-// Copyright (c) 2008-2011 Bruno Lalande, Paris, France.
-// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
-
-// Use, modification and distribution is subject to the Boost Software License,
-// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-//
-// Custom Linestring Example
-
-#include <iostream>
-#include <string>
-#include <vector>
-
-#include <boost/geometry/geometry.hpp>
-#include <boost/geometry/geometries/register/point.hpp>
-#include <boost/geometry/geometries/register/linestring.hpp>
-
-// To register the 'geographic' distance function to calculate distance over the earth:
-#include <boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp>
-#include <boost/geometry/extensions/algorithms/parse.hpp>
-
-// Define a GPS point with coordinates in latitude/longitude and some additional values
-struct gps_point
-{
- double latitude, longitude, height;
- double speed;
- // Date/time, heading, etc could be added
-
- // The default constructor is required if being used in a vector
- gps_point() {}
-
- // Define a constructor to create the point in one line. Order of latitude/longitude
- // does not matter as long as "E", "N", etc are included
- gps_point(std::string const& c1, std::string const& c2, double h, double s)
- : height(h)
- , speed(s)
- {
- boost::geometry::parse(*this, c1, c2);
- }
-};
-
-// Declare a custom linestring which will have the GPS points
-struct gps_track : std::vector<gps_point>
-{
- std::string owner;
- int route_identifier;
- // etc
-
- gps_track(int i, std::string const& o)
- : owner(o)
- , route_identifier(i)
- {}
-};
-
-
-// Register this point as being a recognizable point by Boost.Geometry
-BOOST_GEOMETRY_REGISTER_POINT_2D(gps_point, double, cs::geographic<degree>, longitude, latitude)
-
-
-// Register the track as well, as being a "linestring"
-BOOST_GEOMETRY_REGISTER_LINESTRING(gps_track)
-
-
-int main()
-{
- // Declare a "GPS Track" and add some GPS points
- gps_track track(23, "Mister G");
- track.push_back(gps_point("52 22 23 N", "4 53 32 E", 50, 180));
- track.push_back(gps_point("52 10 00 N", "4 59 59 E", 110, 170));
- track.push_back(gps_point("52 5 20 N", "5 6 56 E", 0, 90));
-
- std::cout
- << "track: " << track.route_identifier << std::endl
- << "from: " << track.owner << std::endl
- << "as wkt: " << boost::geometry::dsv(track) << std::endl
- << "length: " << boost::geometry::length(track)/1000.0 << " km" << std::endl;
-
- // Above gives the idea, shows that custom linestrings can be useful.
- // We could of course do anything with this track which the library can handle, e.g.:
- // - simplify it
- // - calculate distance of point-to-line
- // - project it to UTM, then transform it to a GIF image (see p03_example)
-
- return 0;
-}

Deleted: branches/release/libs/geometry/example/with_external_libs/x02_gd_example.cpp
==============================================================================
--- branches/release/libs/geometry/example/with_external_libs/x02_gd_example.cpp 2011-04-03 03:55:46 EDT (Sun, 03 Apr 2011)
+++ (empty file)
@@ -1,146 +0,0 @@
-// Boost.Geometry (aka GGL, Generic Geometry Library)
-//
-// Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands.
-// Use, modification and distribution is subject to the Boost Software License,
-// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-//
-// GD example
-
-// GD is a well-known and often used graphic library to write GIF (and other formats)
-
-// To build and run this example:
-// 1) download GD from http://www.libgd.org (currently gd-2.0.35 is assumed)
-// 2) add 11 files
-// gd.c, gd_gd.c, gd_gif_out.c, gd_io*.c, gd_security.c, gd_topal.c, gdhelpers.c, gdtables.c
-// to the project or makefile or jamfile
-// 3) for windows, add define NONDLL to indicate GD is not used as a DLL
-// (Note that steps 2 and 3 are done in the MSVC gd_example project file and property sheets)
-
-#include <cmath>
-#include <cstdio>
-#include <vector>
-
-#include <fstream>
-#include <sstream>
-
-
-#include <boost/foreach.hpp>
-
-#include <boost/geometry/geometry.hpp>
-#include <boost/geometry/multi/multi.hpp>
-#include <boost/geometry/algorithms/area.hpp>
-#include <boost/geometry/extensions/gis/latlong/latlong.hpp>
-#include <boost/geometry/extensions/gis/geographic/strategies/area_huiller_earth.hpp>
-
-#include <boost/geometry/domains/gis/io/wkt/wkt.hpp>
-
-
-#include <gd.h>
-
-namespace bg = boost::geometry;
-
-
-// ----------------------------------------------------------------------------
-// Read an ASCII file containing WKT's
-// (note this function is shared by various examples)
-// ----------------------------------------------------------------------------
-template <typename Geometry>
-inline void read_wkt(std::string const& filename, std::vector<Geometry>& geometries)
-{
- std::ifstream cpp_file(filename.c_str());
- if (cpp_file.is_open())
- {
- while (! cpp_file.eof() )
- {
- std::string line;
- std::getline(cpp_file, line);
- if (! line.empty())
- {
- Geometry geometry;
- bg::read_wkt(line, geometry);
- geometries.push_back(geometry);
- }
- }
- }
-}
-
-
-int main()
-{
- // Adapt if necessary
- std::string filename = "../data/world.wkt";
-
-
- // The world is measured in latlong (degrees), so latlong is appropriate.
- // We ignore holes in this sample (below)
- typedef bg::model::ll::point<bg::degree> point_type;
- typedef bg::model::polygon<point_type> polygon_type;
- typedef bg::model::multi_polygon<polygon_type> country_type;
-
- std::vector<country_type> countries;
-
- // Read (for example) world countries
- read_wkt(filename, countries);
-
-
- // Create a GD image.
- // A world map, as world.shp, is usually mapped in latitude-longitude (-180..180 and -90..90)
- // For this example we use a very simple "transformation"
- // mapping to 0..720 and 0..360
- const double factor = 2.0;
- gdImagePtr im = gdImageCreateTrueColor(int(360 * factor), int(180 * factor));
-
- // Allocate three colors
- int blue = gdImageColorResolve(im, 0, 52, 255);
- int green = gdImageColorResolve(im, 0, 255, 0);
- int black = gdImageColorResolve(im, 0, 0, 0);
-
- // Paint background in blue
- gdImageFilledRectangle(im, 0, 0, im->sx, im->sy, blue);
-
- // Paint all countries in green
- BOOST_FOREACH(country_type const& country, countries)
- {
- BOOST_FOREACH(polygon_type const& polygon, country)
- {
- // Ignore holes, so take only exterior ring
- bg::model::ring<point_type> const& ring = bg::exterior_ring(polygon);
-
- // If wished, suppress too small polygons.
- // (Note that even in latlong, area is calculated in square meters)
- double const a = bg::area(ring);
- if (std::fabs(a) > 5000.0e6)
- {
- int const n = ring.size();
- gdPoint* points = new gdPoint[n];
-
- for (int i = 0; i < n; i++)
- {
- // Translate lon/lat or x/y to GD x/y points
- points[i].x = int(factor * (bg::get<0>(ring[i]) + 180.0));
- points[i].y = im->sy - int(factor * (bg::get<1>(ring[i]) + 90.0));
- }
-
- // Draw the polygon...
- gdImageFilledPolygon(im, points, n, green);
- // .. and the outline in black...
- gdImagePolygon(im, points, n, black);
-
- delete[] points;
- }
- }
- }
-
- // Use GD to create a GIF file
- std::FILE* out = std::fopen("world.gif", "wb");
- if (out != NULL)
- {
- gdImageGif(im, out);
- std::fclose(out);
- }
-
- gdImageDestroy(im);
-
- return 0;
-}

Deleted: branches/release/libs/geometry/example/with_external_libs/x03_c_soci_example.cpp
==============================================================================
--- branches/release/libs/geometry/example/with_external_libs/x03_c_soci_example.cpp 2011-04-03 03:55:46 EDT (Sun, 03 Apr 2011)
+++ (empty file)
@@ -1,118 +0,0 @@
-// Boost.Geometry (aka GGL, Generic Geometry Library)
-//
-// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
-//
-// Use, modification and distribution is subject to the Boost Software License,
-// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-// Boost.Geometry (aka GGL, Generic Geometry Library)
-// SOCI example
-
-// c: using WKB to retrieve geometries
-
-// SOCI is a generic C++ template interface to access relational databases
-
-// To build and run this example, see comments in example a
-// Alternatively compile composing and executing compiler command directoy in examples directory,
-// for example using GCC compiler:
-// g++ -I../../../boost -I/home/mloskot/usr/include/soci \
-// -I /home/mloskot/usr/include/soci/postgresql -I/usr/include/postgresql \
-// -L/home/mloskot/usr/lib -lsoci_core-gcc-3_0 -lsoci_postgresql-gcc-3_0 x03_c_soci_example.cpp
-
-#include <soci.h>
-#include <soci-postgresql.h>
-
-#include <exception>
-#include <iostream>
-#include <iterator>
-#include <string>
-#include <vector>
-
-#include <boost/geometry/geometry.hpp>
-#include <boost/geometry/geometries/geometries.hpp>
-#include <boost/geometry/extensions/gis/io/wkb/read_wkb.hpp>
-#include <boost/geometry/extensions/gis/io/wkb/utility.hpp>
-#include <boost/geometry/domains/gis/io/wkt/wkt.hpp>
-
-// user-defined type with GGL geometry
-struct tree
-{
- int id;
- boost::geometry::model::point<float, 2, boost::geometry::cs::geographic<boost::geometry::degree> > location;
-};
-
-// conversion of row of result to user-defined type - performs WKB parsing
-namespace soci
-{
- template <>
- struct type_conversion<tree>
- {
- typedef soci::values base_type;
-
- static void from_base(base_type const& v, soci::indicator ind, tree& value)
- {
- try
- {
- value.id = v.get<int>("id");
-
- // intermediate step: hex-encoded binary string to raw WKB
- std::string const& hex = v.get<std::string>("wkb");
- std::vector<unsigned char> wkb;
- if (!boost::geometry::hex2wkb(hex, std::back_inserter(wkb)))
- throw std::runtime_error("hex2wkb translation failed");
-
- // parse WKB and construct point geometry
- if (!boost::geometry::read_wkb(wkb.begin(), wkb.end(), value.location))
- throw std::runtime_error("read_wkb failed");
- }
- catch(const std::exception& e)
- {
- std::cout << e.what() << std::endl;
- }
- }
-
- static void to_base(tree const& value, base_type& v, soci::indicator& ind)
- {
- throw std::runtime_error("todo: wkb writer not yet implemented");
- }
- };
-}
-
-int main()
-{
- try
- {
- // establish database connection
- soci::session sql(soci::postgresql, "dbname=ggl user=ggl password=ggl");
-
- // construct schema of table for trees (point geometries)
- sql << "DELETE FROM geometry_columns WHERE f_table_name = 'trees'";
- sql << "DROP TABLE IF EXISTS trees CASCADE";
- sql << "CREATE TABLE trees (id INTEGER)";
- sql << "SELECT AddGeometryColumn('trees', 'geom', -1, 'POINT', 2)";
-
- // insert sample data using plain WKT input
- sql << "INSERT INTO trees VALUES(1, ST_GeomFromText('POINT(1.23 2.34)', -1))";
- sql << "INSERT INTO trees VALUES(2, ST_GeomFromText('POINT(3.45 4.56)', -1))";
- sql << "INSERT INTO trees VALUES(3, ST_GeomFromText('POINT(5.67 6.78)', -1))";
- sql << "INSERT INTO trees VALUES(4, ST_GeomFromText('POINT(7.89 9.01)', -1))";
-
- // query data in WKB form and read to geometry object
- typedef std::vector<tree> trees_t;
- soci::rowset<tree> rows = (sql.prepare << "SELECT id, encode(ST_AsBinary(geom), 'hex') AS wkb FROM trees");
- trees_t trees;
- std::copy(rows.begin(), rows.end(), std::back_inserter(trees));
-
- // print trees output
- for (trees_t::const_iterator it = trees.begin(); it != trees.end(); ++it)
- {
- std::cout << "Tree #" << it->id << " located at\t" << boost::geometry::wkt(it->location) << std::endl;
- }
- }
- catch (std::exception const &e)
- {
- std::cerr << "Error: " << e.what() << '\n';
- }
- return 0;
-}
-

Deleted: branches/release/libs/geometry/example/with_external_libs/x03_d_soci_example.cpp
==============================================================================
--- branches/release/libs/geometry/example/with_external_libs/x03_d_soci_example.cpp 2011-04-03 03:55:46 EDT (Sun, 03 Apr 2011)
+++ (empty file)
@@ -1,83 +0,0 @@
-// Boost.Geometry (aka GGL, Generic Geometry Library)
-//
-// Copyright (c) 2009-2011 Mateusz Loskot, London, UK.
-//
-// Use, modification and distribution is subject to the Boost Software License,
-// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-// Boost.Geometry (aka GGL, Generic Geometry Library)
-// SOCI example
-
-// d: using WKB to retrieve geometries
-
-// SOCI is a generic C++ template interface to access relational databases
-
-// To build and run this example, see comments in example a
-// Alternatively compile composing and executing compiler command directoy in examples directory,
-// for example using GCC compiler:
-// g++ -I../../../boost -I/home/mloskot/usr/include/soci \
-// -I /home/mloskot/usr/include/soci/postgresql -I/usr/include/postgresql \
-// -L/home/mloskot/usr/lib -lsoci_core-gcc-3_0 -lsoci_postgresql-gcc-3_0 x03_c_soci_example.cpp
-
-#include <soci.h>
-#include <soci-postgresql.h>
-
-#include <exception>
-#include <iostream>
-#include <iterator>
-#include <string>
-#include <vector>
-
-#include <boost/geometry/geometry.hpp>
-#include <boost/geometry/algorithms/area.hpp>
-#include <boost/geometry/geometries/geometries.hpp>
-#include <boost/geometry/extensions/gis/io/wkb/read_wkb.hpp>
-#include <boost/geometry/extensions/gis/io/wkb/utility.hpp>
-#include <boost/geometry/domains/gis/io/wkt/wkt.hpp>
-
-int main()
-{
- try
- {
- // establish database connection
- soci::session sql(soci::postgresql, "dbname=ggl user=ggl password=ggl");
-
- // construct schema of table for trees (point geometries)
- sql << "DELETE FROM geometry_columns WHERE f_table_name = 'parcels'";
- sql << "DROP TABLE IF EXISTS parcels CASCADE";
- sql << "CREATE TABLE parcels (id INTEGER)";
- sql << "SELECT AddGeometryColumn('parcels', 'geom', -1, 'GEOMETRY', 2)";
-
- // insert sample data using plain WKT input
- sql << "INSERT INTO parcels VALUES(1, ST_GeomFromText('POLYGON ((10 10, 10 20, 20 20, 20 15, 10 10))', -1))";
- sql << "INSERT INTO parcels VALUES(2, ST_GeomFromText('POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0))', -1))";
- sql << "INSERT INTO parcels VALUES(3, ST_GeomFromText('POLYGON((1 1,2 1,2 2,1 2,1 1))', -1))";
-
- // query data in WKB form and read to geometry object
- soci::rowset<std::string> rows = (sql.prepare << "SELECT encode(ST_AsBinary(geom), 'hex') AS wkb FROM parcels");
-
- // calculate area of each parcel
- for (soci::rowset<std::string>::iterator it = rows.begin(); it != rows.end(); ++it)
- {
- // parse WKB and construct geometry object
- std::string const& hex = *it;
- std::vector<unsigned char> wkb;
- if (!boost::geometry::hex2wkb(*it, std::back_inserter(wkb)))
- throw std::runtime_error("hex2wkb translation failed");
-
- boost::geometry::model::d2::polygon parcel;
- if (!boost::geometry::read_wkb(wkb.begin(), wkb.end(), parcel))
- throw std::runtime_error("read_wkb failed");
-
- double a = boost::geometry::area(parcel);
- std::cout << "Parcel geometry: " << boost::geometry::wkt(parcel) << std::endl
- << "\thas area is " << a << " in coordinate units" << std::endl;
- }
- }
- catch (std::exception const &e)
- {
- std::cerr << "Error: " << e.what() << '\n';
- }
- return 0;
-}
-


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk