$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r76366 - in branches/release/libs/geometry: example example/with_external_libs test/domains test/geometries test/ranges
From: barend.gehrels_at_[hidden]
Date: 2012-01-08 06:46:36
Author: barendgehrels
Date: 2012-01-08 06:46:35 EST (Sun, 08 Jan 2012)
New Revision: 76366
URL: http://svn.boost.org/trac/boost/changeset/76366
Log:
Manually synchronized 6 more files and deleted ranges/domains
Added:
   branches/release/libs/geometry/example/c03_custom_linestring_example.cpp   (contents, props changed)
   branches/release/libs/geometry/example/with_external_libs/x02_gd_example.cpp   (contents, props changed)
   branches/release/libs/geometry/example/with_external_libs/x03_c_soci_example.cpp   (contents, props changed)
   branches/release/libs/geometry/example/with_external_libs/x03_d_soci_example.cpp   (contents, props changed)
Removed:
   branches/release/libs/geometry/test/domains/
   branches/release/libs/geometry/test/ranges/
Text files modified: 
   branches/release/libs/geometry/example/Jamfile.v2          |     2 +-                                      
   branches/release/libs/geometry/test/geometries/adapted.cpp |     9 ++++++---                               
   2 files changed, 7 insertions(+), 4 deletions(-)
Modified: branches/release/libs/geometry/example/Jamfile.v2
==============================================================================
--- branches/release/libs/geometry/example/Jamfile.v2	(original)
+++ branches/release/libs/geometry/example/Jamfile.v2	2012-01-08 06:46:35 EST (Sun, 08 Jan 2012)
@@ -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  ;
Added: branches/release/libs/geometry/example/c03_custom_linestring_example.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/geometry/example/c03_custom_linestring_example.cpp	2012-01-08 06:46:35 EST (Sun, 08 Jan 2012)
@@ -0,0 +1,87 @@
+// 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;
+}
Added: branches/release/libs/geometry/example/with_external_libs/x02_gd_example.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/geometry/example/with_external_libs/x02_gd_example.cpp	2012-01-08 06:46:35 EST (Sun, 08 Jan 2012)
@@ -0,0 +1,146 @@
+// 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/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;
+}
Added: branches/release/libs/geometry/example/with_external_libs/x03_c_soci_example.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/geometry/example/with_external_libs/x03_c_soci_example.cpp	2012-01-08 06:46:35 EST (Sun, 08 Jan 2012)
@@ -0,0 +1,118 @@
+// 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/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;
+}
+
Added: branches/release/libs/geometry/example/with_external_libs/x03_d_soci_example.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/geometry/example/with_external_libs/x03_d_soci_example.cpp	2012-01-08 06:46:35 EST (Sun, 08 Jan 2012)
@@ -0,0 +1,83 @@
+// 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/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;
+}
+
Modified: branches/release/libs/geometry/test/geometries/adapted.cpp
==============================================================================
--- branches/release/libs/geometry/test/geometries/adapted.cpp	(original)
+++ branches/release/libs/geometry/test/geometries/adapted.cpp	2012-01-08 06:46:35 EST (Sun, 08 Jan 2012)
@@ -95,15 +95,18 @@
 
 int test_main(int, char* [])
 {
-/*    test_all<test::test_point>();
+    test_all<test::test_point>();
     test_all<boost::tuple<float, float> >();
     test_all<bg::model::point<int, 2, bg::cs::cartesian> >();
     test_all<bg::model::point<float, 2, bg::cs::cartesian> >();
     test_all<bg::model::point<double, 2, bg::cs::cartesian> >();
     test_all<bg::model::point<long double, 2, bg::cs::cartesian> >();
-*/
+
+    test_all<boost::tuple<float, float, float> >();
     test_all<bg::model::point<double, 3, bg::cs::cartesian> >();
-    //test_all<bg::model::point<long double, 3, bg::cs::cartesian> >();
+    test_all<bg::model::point<long double, 3, bg::cs::cartesian> >();
+
+    test_all<boost::tuple<float, float, float, float, float> >();
 
     return 0;
 }