Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64594 - in sandbox/geometry: boost/geometry/extensions/gis/io/shapelib libs/geometry/example/extensions/gis/io libs/geometry/example/extensions/gis/io/shapelib libs/geometry/example/extensions/gis/io/shapelib/contrib libs/geometry/example/extensions/gis/io/shapelib/contrib/shapelib-1.3.0b2 libs/geometry/example/extensions/gis/io/shapelib/out
From: barend.gehrels_at_[hidden]
Date: 2010-08-04 08:35:22


Author: barendgehrels
Date: 2010-08-04 08:35:16 EDT (Wed, 04 Aug 2010)
New Revision: 64594
URL: http://svn.boost.org/trac/boost/changeset/64594

Log:
Added shapelib extension to create shapefiles using shapelib
(shameless plug: writing shapefiles has never been easier)
Added:
   sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/
   sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/dbf_write_attribute.hpp (contents, props changed)
   sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shape_creator.hpp (contents, props changed)
   sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shp_create_object.hpp (contents, props changed)
   sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shp_create_object_multi.hpp (contents, props changed)
   sandbox/geometry/libs/geometry/example/extensions/gis/io/
   sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/
   sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/contrib/
   sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/contrib/shapelib-1.3.0b2/
   sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/contrib/shapelib-1.3.0b2/readme.txt (contents, props changed)
   sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/out/
   sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/shapelib.cpp (contents, props changed)
   sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/shapelib.vcproj (contents, props changed)
   sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/shapelib.vsprops (contents, props changed)

Added: sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/dbf_write_attribute.hpp
==============================================================================
--- (empty file)
+++ sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/dbf_write_attribute.hpp 2010-08-04 08:35:16 EDT (Wed, 04 Aug 2010)
@@ -0,0 +1,76 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Copyright Barend Gehrels 2010, Geodan, 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)
+
+#ifndef BOOST_GEOMETRY_EXT_GIS_IO_SHAPELIB_DBF_WRITE_ATTRIBUTE_HPP
+#define BOOST_GEOMETRY_EXT_GIS_IO_SHAPELIB_DBF_WRITE_ATTRIBUTE_HPP
+
+
+
+
+// Should be somewhere in your include path
+#include "shapefil.h"
+
+
+
+namespace boost { namespace geometry
+{
+
+
+template <typename T>
+struct DBFFieldType
+{
+ // IS integer etc.
+};
+
+template <> struct DBFFieldType<int> { static ::DBFFieldType const value = FTInteger; };
+template <> struct DBFFieldType<float> { static ::DBFFieldType const value = FTDouble; };
+template <> struct DBFFieldType<double> { static ::DBFFieldType const value = FTDouble; };
+template <> struct DBFFieldType<std::string> { static ::DBFFieldType const value = FTString; };
+
+
+template <typename T> struct DBFWriteAttribute
+{
+};
+
+template <> struct DBFWriteAttribute<int>
+{
+ template <typename T>
+ inline static void apply(DBFHandle dbf, int row_index, int field_index, T const& value)
+ {
+ DBFWriteIntegerAttribute(dbf, row_index, field_index, value);
+ }
+};
+
+template <> struct DBFWriteAttribute<double>
+{
+ template <typename T>
+ inline static void apply(DBFHandle dbf, int row_index, int field_index, T const& value)
+ {
+ DBFWriteDoubleAttribute(dbf, row_index, field_index, value);
+ }
+};
+
+template <> struct DBFWriteAttribute<std::string>
+{
+ template <typename T>
+ inline static void apply(DBFHandle dbf, int row_index, int field_index, T const& value)
+ {
+ DBFWriteStringAttribute(dbf, row_index, field_index, value);
+ }
+};
+
+template <int N>
+struct DBFWriteAttribute<char[N]> : DBFWriteAttribute<std::string> {};
+
+template <>
+struct DBFWriteAttribute<char*> : DBFWriteAttribute<std::string> {};
+
+
+}} // namespace boost::geometry
+
+
+#endif // BOOST_GEOMETRY_EXT_GIS_IO_SHAPELIB_DBF_WRITE_ATTRIBUTE_HPP

Added: sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shape_creator.hpp
==============================================================================
--- (empty file)
+++ sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shape_creator.hpp 2010-08-04 08:35:16 EDT (Wed, 04 Aug 2010)
@@ -0,0 +1,130 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Copyright Barend Gehrels 2010, Geodan, 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)
+
+#ifndef BOOST_GEOMETRY_EXT_GIS_IO_SHAPELIB_SHAPE_CREATOR_HPP
+#define BOOST_GEOMETRY_EXT_GIS_IO_SHAPELIB_SHAPE_CREATOR_HPP
+
+
+#include "shapefil.h"
+
+#include <boost/noncopyable.hpp>
+#include <boost/type_traits/remove_const.hpp>
+
+#include <boost/geometry/extensions/gis/io/wkt/wkt.hpp>
+#include <boost/geometry/extensions/gis/io/shapelib/shp_create_object.hpp>
+#include <boost/geometry/extensions/gis/io/shapelib/shp_create_object_multi.hpp>
+#include <boost/geometry/extensions/gis/io/shapelib/dbf_write_attribute.hpp>
+
+
+namespace boost { namespace geometry
+{
+
+
+
+class shapelib_file_create_exception : public geometry::exception
+{
+public:
+
+ inline shapelib_file_create_exception(std::string const& filename)
+ : m_filename(filename)
+ {}
+
+ virtual char const* what() const throw()
+ {
+ return m_filename.c_str();
+ }
+private :
+ std::string m_filename;
+};
+
+
+namespace detail
+{
+
+template <typename Tag>
+struct SHPType
+{
+};
+
+template <> struct SHPType<point_tag> { static int const value = SHPT_POINT; };
+template <> struct SHPType<segment_tag> { static int const value = SHPT_ARC; };
+template <> struct SHPType<linestring_tag> { static int const value = SHPT_ARC; };
+template <> struct SHPType<polygon_tag> { static int const value = SHPT_POLYGON; };
+template <> struct SHPType<ring_tag> { static int const value = SHPT_POLYGON; };
+template <> struct SHPType<box_tag> { static int const value = SHPT_POLYGON; };
+
+template <> struct SHPType<multi_point_tag> { static int const value = SHPT_MULTIPOINT; };
+template <> struct SHPType<multi_linestring_tag> { static int const value = SHPT_ARC; };
+template <> struct SHPType<multi_polygon_tag> { static int const value = SHPT_POLYGON; };
+
+}
+
+template
+<
+ typename Geometry,
+ int ShapeType = detail::SHPType
+ <
+ typename geometry::tag<Geometry>::type
+ >::value
+>
+class shape_creator : public boost::noncopyable
+{
+public :
+ shape_creator(std::string const& name)
+ {
+ m_shp = ::SHPCreate((name + ".shp").c_str(), ShapeType);
+ m_dbf = ::DBFCreate((name + ".dbf").c_str());
+
+ if (m_shp == NULL || m_dbf == NULL)
+ {
+ throw shapelib_file_create_exception(name);
+ }
+ }
+ virtual ~shape_creator()
+ {
+ if (m_shp) ::SHPClose(m_shp);
+ if (m_dbf) ::DBFClose(m_dbf);
+ }
+
+
+ // Returns: index in shapefile
+ inline int AddShape(Geometry const& geometry)
+ {
+ // Note: we MIGHT design a small wrapper class which destroys in destructor
+ ::SHPObject* obj = SHPCreateObject(geometry);
+ int result = SHPWriteObject(m_shp, -1, obj );
+ ::SHPDestroyObject( obj );
+ return result;
+ }
+
+
+ template <typename T>
+ inline void AddField(std::string const& name, int width = 16, int decimals = 0)
+ {
+ ::DBFAddField(m_dbf, name.c_str(), DBFFieldType<T>::value, width, decimals);
+ }
+
+ template <typename T>
+ inline void WriteField(int row_index, int field_index, T const& value)
+ {
+ DBFWriteAttribute
+ <
+ typename boost::remove_const<T>::type
+ >::apply(m_dbf, row_index, field_index, value);
+ }
+
+
+private :
+ ::SHPHandle m_shp;
+ ::DBFHandle m_dbf;
+};
+
+
+}} // namespace boost::geometry
+
+
+#endif // BOOST_GEOMETRY_EXT_GIS_IO_SHAPELIB_SHAPE_CREATOR_HPP

Added: sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shp_create_object.hpp
==============================================================================
--- (empty file)
+++ sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shp_create_object.hpp 2010-08-04 08:35:16 EDT (Wed, 04 Aug 2010)
@@ -0,0 +1,229 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Copyright Barend Gehrels 2010, Geodan, 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)
+
+#ifndef BOOST_GEOMETRY_EXT_GIS_IO_SHAPELIB_SHP_CREATE_OBJECT_HPP
+#define BOOST_GEOMETRY_EXT_GIS_IO_SHAPELIB_SHP_CREATE_OBJECT_HPP
+
+
+#include <boost/mpl/assert.hpp>
+#include <boost/range.hpp>
+#include <boost/scoped_array.hpp>
+
+#include <boost/geometry/core/exterior_ring.hpp>
+#include <boost/geometry/core/interior_rings.hpp>
+#include <boost/geometry/core/ring_type.hpp>
+#include <boost/geometry/algorithms/num_points.hpp>
+#include <boost/geometry/ranges/box_range.hpp>
+#include <boost/geometry/ranges/segment_range.hpp>
+
+
+// Should be somewhere in your include path
+#include "shapefil.h"
+
+
+
+namespace boost { namespace geometry
+{
+
+#ifndef DOXYGEN_NO_DETAIL
+namespace detail { namespace shp_create_object
+{
+
+template <typename Point>
+struct shape_create_point
+{
+
+ static inline SHPObject* apply(Point const& point)
+ {
+ double x = get<0>(point);
+ double y = get<1>(point);
+
+ int const parts = 0;
+
+ return ::SHPCreateObject(SHPT_POINT, -1, 1, &parts, NULL,
+ 1, &x, &y, NULL, NULL);
+ }
+};
+
+
+template <typename Range>
+static inline int range_to_part(Range const& range, double* x, double* y, int offset = 0)
+{
+ x += offset;
+ y += offset;
+
+ for (typename boost::range_iterator<Range const>::type
+ it = boost::begin(range);
+ it != boost::end(range);
+ ++it, ++x, ++y)
+ {
+ *x = get<0>(*it);
+ *y = get<1>(*it);
+ offset++;
+ }
+ return offset;
+}
+
+
+template <typename Range, int ShapeType>
+struct shape_create_range
+{
+ static inline SHPObject* apply(Range const& range)
+ {
+ int const n = boost::size(range);
+
+ boost::scoped_array<double> x(new double[n]);
+ boost::scoped_array<double> y(new double[n]);
+
+ range_to_part(range, x.get(), y.get());
+
+ int const parts = 0;
+
+ return ::SHPCreateObject(ShapeType, -1, 1, &parts, NULL,
+ n, x.get(), y.get(), NULL, NULL);
+ }
+};
+
+
+template <typename Polygon>
+struct shape_create_polygon
+{
+ static inline void process_polygon(Polygon const& polygon,
+ double* xp, double* yp, int* parts,
+ int& offset, int& ring)
+ {
+ parts[ring++] = offset;
+ offset = range_to_part(geometry::exterior_ring(polygon), xp, yp, offset);
+
+ typedef typename boost::range_iterator
+ <
+ typename interior_type<Polygon>::type const
+ >::type iterator;
+
+ for (iterator it = boost::begin(geometry::interior_rings(polygon));
+ it != boost::end(interior_rings(polygon));
+ ++it)
+ {
+ parts[ring++] = offset;
+ offset = range_to_part(*it, xp, yp, offset);
+ }
+ }
+
+ static inline SHPObject* apply(Polygon const& polygon)
+ {
+ int const n = geometry::num_points(polygon);
+ int const ring_count = 1 + geometry::num_interior_rings(polygon);
+
+ boost::scoped_array<double> x(new double[n]);
+ boost::scoped_array<double> y(new double[n]);
+ boost::scoped_array<int> parts(new int[ring_count]);
+
+ int ring = 0;
+ int offset = 0;
+
+ process_polygon(polygon, x.get(), y.get(), parts.get(), offset, ring);
+
+ return ::SHPCreateObject(SHPT_POLYGON, -1, ring_count, parts.get(), NULL,
+ n, x.get(), y.get(), NULL, NULL);
+ }
+};
+
+template <typename Geometry, typename AdaptedRange, int ShapeType>
+struct shape_create_adapted_range
+{
+ static inline SHPObject* apply(Geometry const& geometry)
+ {
+ return shape_create_range<AdaptedRange, ShapeType>::apply(AdaptedRange(geometry));
+ }
+};
+
+
+
+}} // namespace detail::shp_create_object
+#endif // DOXYGEN_NO_DETAIL
+
+
+#ifndef DOXYGEN_NO_DISPATCH
+namespace dispatch
+{
+
+
+template <typename Tag, typename Geometry>
+struct shp_create_object
+{
+ BOOST_MPL_ASSERT_MSG
+ (
+ false, NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
+ , (Geometry)
+ );
+};
+
+
+template <typename Point>
+struct shp_create_object<point_tag, Point>
+ : detail::shp_create_object::shape_create_point<Point>
+{};
+
+
+template <typename LineString>
+struct shp_create_object<linestring_tag, LineString>
+ : detail::shp_create_object::shape_create_range<LineString, SHPT_ARC>
+{};
+
+
+template <typename Ring>
+struct shp_create_object<ring_tag, Ring>
+ : detail::shp_create_object::shape_create_range<Ring, SHPT_POLYGON>
+{};
+
+
+template <typename Polygon>
+struct shp_create_object<polygon_tag, Polygon>
+ : detail::shp_create_object::shape_create_polygon<Polygon>
+{};
+
+template <typename Box>
+struct shp_create_object<box_tag, Box>
+ : detail::shp_create_object::shape_create_adapted_range
+ <
+ Box,
+ box_range<Box>,
+ SHPT_POLYGON
+ >
+{};
+
+template <typename Segment>
+struct shp_create_object<segment_tag, Segment>
+ : detail::shp_create_object::shape_create_adapted_range
+ <
+ Segment,
+ segment_range<Segment>,
+ SHPT_ARC
+ >
+{};
+
+
+} // namespace dispatch
+#endif // DOXYGEN_NO_DISPATCH
+
+
+// Redirect shapelib's SHPCreateObject to this boost::geometry::SHPCreateObject.
+// The only difference is their parameters, one just accepts a geometry
+template <typename Geometry>
+inline SHPObject* SHPCreateObject(Geometry const& geometry)
+{
+ return dispatch::shp_create_object
+ <
+ typename tag<Geometry>::type, Geometry
+ >::apply(geometry);
+}
+
+
+}} // namespace boost::geometry
+
+
+#endif // BOOST_GEOMETRY_EXT_GIS_IO_SHAPELIB_SHP_CREATE_OBJECT_HPP

Added: sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shp_create_object_multi.hpp
==============================================================================
--- (empty file)
+++ sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shp_create_object_multi.hpp 2010-08-04 08:35:16 EDT (Wed, 04 Aug 2010)
@@ -0,0 +1,145 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Copyright Barend Gehrels 2010, Geodan, 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)
+
+#ifndef BOOST_GEOMETRY_EXT_GIS_IO_SHAPELIB_SHP_CREATE_OBJECT_MULTI_HPP
+#define BOOST_GEOMETRY_EXT_GIS_IO_SHAPELIB_SHP_CREATE_OBJECT_MULTI_HPP
+
+
+#include <boost/range.hpp>
+
+#include <boost/scoped_array.hpp>
+
+#include <boost/geometry/multi/core/tags.hpp>
+#include <boost/geometry/multi/core/point_type.hpp>
+
+#include <boost/geometry/extensions/gis/io/shapelib/shp_create_object.hpp>
+
+
+
+
+namespace boost { namespace geometry
+{
+
+#ifndef DOXYGEN_NO_DETAIL
+namespace detail { namespace shp_create_object
+{
+
+
+template <typename MultiPoint>
+struct shape_create_multi_point
+{
+ static inline SHPObject* apply(MultiPoint const& multi)
+ {
+ int const n = boost::size(multi);
+ boost::scoped_array<double> x(new double[n]);
+ boost::scoped_array<double> y(new double[n]);
+
+ range_to_part(multi, x.get(), y.get());
+
+ int const parts = 0;
+ return ::SHPCreateObject(SHPT_MULTIPOINT, -1, 1, &parts, NULL,
+ n, x.get(), y.get(), NULL, NULL);
+ }
+};
+
+
+
+template <typename MultiLinestring>
+struct shape_create_multi_linestring
+{
+ static inline SHPObject* apply(MultiLinestring const& multi)
+ {
+ int const n = geometry::num_points(multi);
+ int const part_count = boost::size(multi);
+
+ boost::scoped_array<double> x(new double[n]);
+ boost::scoped_array<double> y(new double[n]);
+ boost::scoped_array<int> parts(new int[part_count]);
+
+ int ring = 0;
+ int offset = 0;
+
+ for (typename boost::range_iterator<MultiLinestring const>::type
+ it = boost::begin(multi);
+ it != boost::end(multi);
+ ++it)
+ {
+ parts[ring++] = offset;
+ offset = range_to_part(*it, x.get(), y.get(), offset);
+ }
+
+ return ::SHPCreateObject(SHPT_ARC, -1, part_count, parts.get(), NULL,
+ n, x.get(), y.get(), NULL, NULL);
+ }
+};
+
+
+template <typename MultiPolygon>
+struct shape_create_multi_polygon
+{
+ static inline SHPObject* apply(MultiPolygon const& multi)
+ {
+ int const n = geometry::num_points(multi);
+ int const ring_count = boost::size(multi) + geometry::num_interior_rings(multi);
+
+ boost::scoped_array<double> x(new double[n]);
+ boost::scoped_array<double> y(new double[n]);
+ boost::scoped_array<int> parts(new int[ring_count]);
+
+ int ring = 0;
+ int offset = 0;
+
+ typedef typename boost::range_value<MultiPolygon>::type polygon_type;
+ for (typename boost::range_iterator<MultiPolygon const>::type
+ it = boost::begin(multi);
+ it != boost::end(multi);
+ ++it)
+ {
+ shape_create_polygon<polygon_type>::process_polygon(*it, x.get(), y.get(), parts.get(),
+ offset, ring);
+ }
+
+ return ::SHPCreateObject(SHPT_POLYGON, -1, ring_count, parts.get(), NULL,
+ n, x.get(), y.get(), NULL, NULL);
+ }
+};
+
+
+}} // namespace detail::shp_create_object
+#endif // DOXYGEN_NO_DETAIL
+
+
+#ifndef DOXYGEN_NO_DISPATCH
+namespace dispatch
+{
+
+template <typename MultiPoint>
+struct shp_create_object<multi_point_tag, MultiPoint>
+ : detail::shp_create_object::shape_create_multi_point<MultiPoint>
+{};
+
+
+template <typename MultiLinestring>
+struct shp_create_object<multi_linestring_tag, MultiLinestring>
+ : detail::shp_create_object::shape_create_multi_linestring<MultiLinestring>
+{};
+
+
+template <typename MultiPolygon>
+struct shp_create_object<multi_polygon_tag, MultiPolygon>
+ : detail::shp_create_object::shape_create_multi_polygon<MultiPolygon>
+{};
+
+
+} // namespace dispatch
+#endif // DOXYGEN_NO_DISPATCH
+
+
+}} // namespace boost::geometry
+
+
+#endif // BOOST_GEOMETRY_EXT_GIS_IO_SHAPELIB_SHP_CREATE_OBJECT_MULTI_HPP

Added: sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/contrib/shapelib-1.3.0b2/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/contrib/shapelib-1.3.0b2/readme.txt 2010-08-04 08:35:16 EDT (Wed, 04 Aug 2010)
@@ -0,0 +1,24 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library) test file
+//
+// Copyright Barend Gehrels 2010, Geodan, 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)
+
+
+
+Download shapelib from
+http://shapelib.maptools.org/
+or http://download.osgeo.org/shapelib/
+
+and extract to this folder.
+
+
+Install at least the following files:
+- dbfopen.c
+- dbfopen.c
+- shapefil.h
+
+For new shapelibs:
+- safileio.c
+

Added: sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/shapelib.cpp
==============================================================================
--- (empty file)
+++ sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/shapelib.cpp 2010-08-04 08:35:16 EDT (Wed, 04 Aug 2010)
@@ -0,0 +1,130 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library) test file
+//
+// Copyright Barend Gehrels 2010, Geodan, 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)
+
+
+#include "shapefil.h"
+
+#include <boost/noncopyable.hpp>
+#include <boost/geometry/geometry.hpp>
+#include <boost/geometry/multi/multi.hpp>
+
+#include <boost/geometry/extensions/gis/io/shapelib/shape_creator.hpp>
+#include <boost/geometry/extensions/gis/io/shapelib/shp_create_object.hpp>
+#include <boost/geometry/extensions/gis/io/shapelib/shp_create_object_multi.hpp>
+#include <boost/geometry/extensions/gis/io/shapelib/dbf_write_attribute.hpp>
+
+#include <boost/geometry/extensions/gis/io/wkt/wkt.hpp>
+
+
+// Writing shapefiles has never been easier.
+
+// Small derived class to be able to write shapes by WKT
+template<typename Geometry>
+class shape_creator : public boost::geometry::shape_creator<Geometry>
+{
+public :
+ shape_creator(std::string const& name)
+ : boost::geometry::shape_creator<Geometry>(name)
+ {}
+
+ // Name inspired on OGC "STGeomFromText"
+ int AddGeomFromText(std::string const& wkt)
+ {
+ Geometry geometry;
+ boost::geometry::read_wkt(wkt, geometry);
+ return AddShape(geometry);
+ }
+};
+
+
+// Next ~80 lines write 8 shapefiles including one or two features
+// complete with a DBF with one attribute
+int main()
+{
+ namespace bg = boost::geometry;
+ typedef bg::point<double, 2, bg::cs::cartesian> point_type;
+ try
+ {
+ {
+ shape_creator<bg::linear_ring<point_type> > sc("out/pol");
+ sc.AddField<int>("dummy", 10);
+ int r = sc.AddGeomFromText("POLYGON((0 0,0 1,1 1,1 0,0 0))");
+ sc.WriteField(r, 0, 10);
+ }
+
+ {
+ shape_creator<bg::polygon<point_type> > sc("out/donut");
+ sc.AddField<int>("dummy", 10);
+ int r = sc.AddGeomFromText("POLYGON((0 0,0 7,4 2,2 0,0 0),(1 1,2 1,1 2,1 1))");
+ sc.WriteField(r, 0, 10);
+ }
+
+ {
+ shape_creator<bg::linestring<point_type> > sc("out/ls");
+ sc.AddField<int>("dummy", 10);
+ int r = sc.AddGeomFromText("LINESTRING(0 0,3 3,5 4,7 1)");
+ sc.WriteField(r, 0, 10);
+ }
+
+ {
+ shape_creator<point_type> sc("out/pnt");
+ sc.AddField<int>("dummy", 10);
+ // Write three points including attribute
+ int r = sc.AddGeomFromText("POINT(2 2)"); sc.WriteField(r, 0, 22);
+ r = sc.AddGeomFromText("POINT(3 2)"); sc.WriteField(r, 0, 32);
+ r = sc.AddGeomFromText("POINT(2 3)"); sc.WriteField(r, 0, 23);
+ }
+
+ {
+ shape_creator<bg::box<point_type> > sc("out/box");
+ sc.AddField<int>("dummy", 10);
+ int r = sc.AddGeomFromText("POLYGON((1 1,2 2))");
+ }
+
+ {
+ shape_creator<bg::segment<point_type const> > sc("out/seg");
+ sc.AddField<int>("dummy", 10);
+
+ // This time, write to shape as geometry and not as WKT
+ // (because bg::segment is currently const -> no WKT support)
+ point_type p1, p2;
+ bg::read_wkt("POINT(1 1)", p1);
+ bg::read_wkt("POINT(2 2)", p2);
+ bg::segment<point_type const> s(p1, p2);
+
+ int r = sc.AddShape(s);
+ sc.WriteField(r, 0, 10);
+ }
+
+ {
+ shape_creator<bg::multi_point<point_type> > sc("out/mpnt");
+ sc.AddField<int>("dummy", 10);
+ int r = sc.AddGeomFromText("MULTIPOINT((0 0),(1 1),(5 2),(7 3))");
+ sc.WriteField(r, 0, 10);
+ }
+
+ {
+ shape_creator<bg::multi_linestring<bg::linestring<point_type> > > sc("out/ml");
+ sc.AddField<int>("dummy", 10);
+ int r = sc.AddGeomFromText("MULTILINESTRING((0 0,1 1,2 0,3 1),(4 4,5 3,6 5))");
+ sc.WriteField(r, 0, 10);
+ }
+
+ {
+ shape_creator<bg::multi_polygon<bg::polygon<point_type> > > sc("out/mp");
+ sc.AddField<std::string>("dummy", 10);
+ int r = sc.AddGeomFromText("MULTIPOLYGON(((0 0,0 7,4 2,2 0,0 0),(1 1,2 1,1 2,1 1)),((10 10,10 11,11 11,11 10,10 10)))");
+ sc.WriteField(r, 0, "test");
+ }
+ }
+ catch(std::exception const& e)
+ {
+ std::cerr << e.what() << std::endl;
+ }
+
+ return 0;
+}
\ No newline at end of file

Added: sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/shapelib.vcproj
==============================================================================
--- (empty file)
+++ sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/shapelib.vcproj 2010-08-04 08:35:16 EDT (Wed, 04 Aug 2010)
@@ -0,0 +1,190 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="shapelib"
+ ProjectGUID="{1FA2ADE2-F649-4245-951E-A8F5935E7127}"
+ RootNamespace="shapelib"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)\shapelib"
+ ConfigurationType="1"
+ InheritedPropertySheets="..\..\..\..\boost.vsprops;.\shapelib.vsprops"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="../../../../../../..;../../../.."
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ ExceptionHandling="2"
+ RuntimeLibrary="1"
+ UsePrecompiledHeader="0"
+ DebugInformationFormat="1"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)\shapelib"
+ ConfigurationType="1"
+ InheritedPropertySheets="..\..\..\..\boost.vsprops;.\shapelib.vsprops"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories="../../../../../../..;../../../.."
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ ExceptionHandling="2"
+ UsePrecompiledHeader="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="SHAPELIB"
+ >
+ <File
+ RelativePath=".\contrib\shapelib-1.3.0b2\dbfopen.c"
+ >
+ </File>
+ <File
+ RelativePath=".\contrib\shapelib-1.3.0b2\safileio.c"
+ >
+ </File>
+ <File
+ RelativePath=".\contrib\shapelib-1.3.0b2\shpopen.c"
+ >
+ </File>
+ </Filter>
+ <File
+ RelativePath=".\shapelib.cpp"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>

Added: sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/shapelib.vsprops
==============================================================================
--- (empty file)
+++ sandbox/geometry/libs/geometry/example/extensions/gis/io/shapelib/shapelib.vsprops 2010-08-04 08:35:16 EDT (Wed, 04 Aug 2010)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioPropertySheet
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="shapelib"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories="contrib/shapelib-1.3.0b2 "
+ />
+</VisualStudioPropertySheet>


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