Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67165 - in sandbox/geometry/boost/geometry: core extensions/gis/io/shapelib geometries/adapted util
From: barend.gehrels_at_[hidden]
Date: 2010-12-11 06:57:04


Author: barendgehrels
Date: 2010-12-11 06:57:02 EST (Sat, 11 Dec 2010)
New Revision: 67165
URL: http://svn.boost.org/trac/boost/changeset/67165

Log:
Committed added files for concept-change to include reference to ring_type and interior_type.
For interior_type.hpp, this is split off from interior_rings.hpp
Changed comment in add_const_if_c
Added:
   sandbox/geometry/boost/geometry/core/interior_type.hpp (contents, props changed)
   sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shape_reader.hpp (contents, props changed)
   sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shp_read_object.hpp (contents, props changed)
   sandbox/geometry/boost/geometry/geometries/adapted/boost_polygon_polygon.hpp (contents, props changed)
   sandbox/geometry/boost/geometry/util/ensure_const_reference.hpp (contents, props changed)
Text files modified:
   sandbox/geometry/boost/geometry/util/add_const_if_c.hpp | 4 ++--
   1 files changed, 2 insertions(+), 2 deletions(-)

Added: sandbox/geometry/boost/geometry/core/interior_type.hpp
==============================================================================
--- (empty file)
+++ sandbox/geometry/boost/geometry/core/interior_type.hpp 2010-12-11 06:57:02 EST (Sat, 11 Dec 2010)
@@ -0,0 +1,149 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Copyright Barend Gehrels 2007-2009, Geodan, Amsterdam, the Netherlands.
+// Copyright Bruno Lalande 2008, 2009
+// 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_CORE_INTERIOR_TYPE_HPP
+#define BOOST_GEOMETRY_CORE_INTERIOR_TYPE_HPP
+
+
+#include <boost/mpl/assert.hpp>
+#include <boost/type_traits/remove_const.hpp>
+
+#include <boost/geometry/core/tag.hpp>
+#include <boost/geometry/core/tags.hpp>
+#include <boost/geometry/util/add_const_if_c.hpp>
+#include <boost/geometry/util/ensure_const_reference.hpp>
+
+namespace boost { namespace geometry
+{
+
+namespace traits
+{
+
+/*!
+ \brief Traits class indicating interior container type of a polygon
+ \details defines inner container type, so the container containing
+ the interior rings
+ \ingroup traits
+ \par Geometries:
+ - polygon
+ \par Specializations should provide:
+ - typedef X type ( e.g. std::vector&lt;myring&lt;P&gt;&gt; )
+ \tparam Geometry geometry
+*/
+template <typename Geometry>
+struct interior_type
+{
+ BOOST_MPL_ASSERT_MSG
+ (
+ false, NOT_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
+ , (types<Geometry>)
+ );
+};
+
+
+} // namespace traits
+
+
+
+
+#ifndef DOXYGEN_NO_DISPATCH
+namespace core_dispatch
+{
+
+
+template <typename GeometryTag, typename Geometry>
+struct interior_type
+{
+ BOOST_MPL_ASSERT_MSG
+ (
+ false, NOT_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
+ , (types<Geometry>)
+ );
+};
+
+
+template <typename Polygon>
+struct interior_type<polygon_tag, Polygon>
+{
+ typedef typename boost::remove_reference
+ <
+ typename traits::interior_type
+ <
+ typename boost::remove_const<Polygon>::type
+ >::type
+ > type;
+};
+
+
+template <typename GeometryTag, typename Geometry>
+struct interior_return_type
+{
+ BOOST_MPL_ASSERT_MSG
+ (
+ false, NOT_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
+ , (types<Geometry>)
+ );
+};
+
+
+template <typename Polygon>
+struct interior_return_type<polygon_tag, Polygon>
+{
+ typedef typename traits::interior_type
+ <
+ typename boost::remove_const<Polygon>::type
+ >::type type;
+};
+
+
+} // namespace core_dispatch
+#endif
+
+
+/*!
+ \brief Meta-function defining container type
+ of inner rings of (multi)polygon geometriy
+ \details the interior rings should be organized as a container
+ (std::vector, std::deque, boost::array) with
+ boost range support. This meta function defines the type
+ of that container.
+ \ingroup core
+*/
+template <typename Geometry>
+struct interior_type
+{
+ typedef typename core_dispatch::interior_type
+ <
+ typename tag<Geometry>::type,
+ Geometry
+ >::type type;
+};
+
+template <typename Geometry, bool IsConst>
+struct interior_return_type
+{
+ typedef typename core_dispatch::interior_return_type
+ <
+ typename tag<Geometry>::type,
+ Geometry
+ >::type ir_type;
+
+ typedef typename mpl::if_c
+ <
+ IsConst,
+ typename ensure_const_reference<ir_type>::type,
+ ir_type
+ >::type type;
+};
+
+
+}} // namespace boost::geometry
+
+
+#endif // BOOST_GEOMETRY_CORE_INTERIOR_TYPE_HPP

Added: sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shape_reader.hpp
==============================================================================
--- (empty file)
+++ sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shape_reader.hpp 2010-12-11 06:57:02 EST (Sat, 11 Dec 2010)
@@ -0,0 +1,71 @@
+// 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_READER_HPP
+#define BOOST_GEOMETRY_EXT_GIS_IO_SHAPELIB_SHAPE_READER_HPP
+
+#include <fstream>
+#include "shapefil.h"
+
+
+#include <boost/noncopyable.hpp>
+#include <boost/type_traits/promote.hpp>
+
+#include <boost/geometry/extensions/gis/io/shapelib/shp_read_object.hpp>
+
+
+namespace boost { namespace geometry
+{
+
+
+
+namespace detail
+{
+
+
+template<typename Geometry>
+class shape_reader : public boost::noncopyable
+{
+public :
+ shape_reader(std::string const& name)
+ {
+ m_shp = ::SHPOpen((name + ".shp").c_str(), "rb");
+ m_dbf = ::DBFOpen((name + ".dbf").c_str(), "rb");
+
+ if (m_shp == NULL || m_dbf == NULL)
+ {
+ throw shapelib_file_open_exception(name);
+ }
+
+ double adfMinBound[4], adfMaxBound[4];
+ SHPGetInfo(m_shp, &m_count, &m_shape_type, adfMinBound, adfMaxBound );
+
+ }
+ virtual ~shape_reader()
+ {
+ if (m_shp) ::SHPClose(m_shp);
+ if (m_dbf) ::DBFClose(m_dbf);
+ }
+
+ inline int count() const { return m_count; }
+
+
+
+
+private :
+ ::SHPHandle m_shp;
+ ::DBFHandle m_dbf;
+ int m_count;
+ int m_shape_type;
+
+};
+
+
+}} // namespace boost::geometry
+
+
+#endif // BOOST_GEOMETRY_EXT_GIS_IO_SHAPELIB_SHAPE_READER_HPP

Added: sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shp_read_object.hpp
==============================================================================
--- (empty file)
+++ sandbox/geometry/boost/geometry/extensions/gis/io/shapelib/shp_read_object.hpp 2010-12-11 06:57:02 EST (Sat, 11 Dec 2010)
@@ -0,0 +1,226 @@
+// 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_READ_OBJECT_HPP
+#define BOOST_GEOMETRY_EXT_GIS_IO_SHAPELIB_SHP_READ_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_read_object
+{
+
+
+template <typename Pair>
+struct sort_on_area_desc
+{
+ inline bool operator()(Pair const& left, Pair const& right)
+ {
+ return left.second > right.second;
+ }
+};
+
+
+
+template <typename LineString>
+struct read_linestring
+{
+ static inline SHPObject* apply(LineString const& linestring)
+ {
+ typedef typename bg::point_type<Linestring>::type point_type;
+
+ if (shape.nSHPType == SHPT_ARCZ && shape.nParts == 1)
+ {
+ double* const x = shape.padfX;
+ double* const y = shape.padfY;
+
+ for (int i = 0; i < shape.nVertices; i++)
+ {
+ point_type point;
+ bg::set<0>(point, x[i]);
+ bg::set<1>(point, y[i]);
+
+ linestring.push_back(point);
+ }
+ return true;
+ }
+ return false;
+
+ }
+};
+
+
+template <typename Polygon>
+struct read_polygon
+{
+ static inline SHPObject* apply(Polygon const& polygon)
+ {
+ typedef typename bg::point_type<Polygon>::type point_type;
+ typedef typename bg::ring_type<Polygon>::type ring_type;
+
+ if (shape.nSHPType == SHPT_POLYGON)
+ {
+ //std::cout << shape.nParts << " " << shape.nVertices << std::endl;
+
+ double* const x = shape.padfX;
+ double* const y = shape.padfY;
+
+ typedef std::pair<ring_type, double> ring_plus_area;
+ std::vector<ring_plus_area> rings;
+ rings.resize(shape.nParts);
+
+ int v = 0;
+ for (int p = 0; p < shape.nParts; p++)
+ {
+ int const first = shape.panPartStart[p];
+ int const last = p + 1 < shape.nParts
+ ? shape.panPartStart[p + 1]
+ : shape.nVertices;
+
+ for (v = first; v < last; v++)
+ {
+ point_type point;
+ bg::set<0>(point, x[v]);
+ bg::set<1>(point, y[v]);
+ rings[p].first.push_back(point);
+ }
+ rings[p].second = bg::math::abs(bg::area(rings[p].first));
+ }
+
+ if (rings.size() > 1)
+ {
+ // Sort rings on area
+ std::sort(rings.begin(), rings.end(),
+ sort_on_area_desc<ring_plus_area>());
+ // Largest area (either positive or negative) is outer ring
+ // Rest of the rings are holes
+ bg::exterior_ring(polygon) = rings.front().first;
+ for (int i = 1; i < rings.size(); i++)
+ {
+ bg::interior_rings(polygon).push_back(rings[i].first);
+ if (! bg::within(rings[i].first.front(), bg::exterior_ring(polygon))
+ && ! bg::within(rings[i].first.at(1), bg::exterior_ring(polygon))
+ )
+ {
+ #if ! defined(NDEBUG)
+ std::cout << "Error: inconsistent ring!" << std::endl;
+ BOOST_FOREACH(ring_plus_area const& r, rings)
+ {
+ std::cout << bg::area(r.first) << " "
+ << bg::wkt(r.first.front()) << " "
+ << std::endl;
+ }
+ #endif
+ }
+ }
+ }
+ else if (rings.size() == 1)
+ {
+ bg::exterior_ring(polygon) = rings.front().first;
+ }
+ return true;
+ }
+ return false;
+ }
+};
+
+
+
+}} // namespace detail::shp_read_object
+#endif // DOXYGEN_NO_DETAIL
+
+
+#ifndef DOXYGEN_NO_DISPATCH
+namespace dispatch
+{
+
+
+template <typename Tag, typename Geometry>
+struct shp_read_object
+{
+ BOOST_MPL_ASSERT_MSG
+ (
+ false, NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
+ , (Geometry)
+ );
+};
+
+
+template <typename LineString>
+struct shp_read_object<linestring_tag, LineString>
+ : detail::shp_read_object::read_linestring<LineString>
+{};
+
+
+
+
+template <typename Polygon>
+struct shp_read_object<polygon_tag, Polygon>
+ : detail::shp_read_object::read_polygon<Polygon>
+{};
+
+
+
+} // namespace dispatch
+#endif // DOXYGEN_NO_DISPATCH
+
+
+template <typename Geometry>
+inline void read_shapefile(std::string const& filename,
+ std::vector<Geometry>& geometries)
+{
+
+ try
+ {
+ // create shape_reader
+
+ for (int i = 0; i < shape_reader.Count(); i++)
+ {
+ SHPObject* psShape = SHPReadObject(shp_handle, i);
+ Geometry geometry;
+ if (dispatch::shp_read_object<Geometry>(*psShape, geometry))
+ {
+ geometries.push_back(geometry);
+ }
+ SHPDestroyObject( psShape );
+ }
+
+ }
+ catch(std::string s)
+ {
+ throw s;
+ }
+ catch(...)
+ {
+ throw std::string("Other exception");
+ }
+}
+
+
+}} // namespace boost::geometry
+
+
+#endif // BOOST_GEOMETRY_EXT_GIS_IO_SHAPELIB_SHP_READ_OBJECT_HPP

Added: sandbox/geometry/boost/geometry/geometries/adapted/boost_polygon_polygon.hpp
==============================================================================
--- (empty file)
+++ sandbox/geometry/boost/geometry/geometries/adapted/boost_polygon_polygon.hpp 2010-12-11 06:57:02 EST (Sat, 11 Dec 2010)
@@ -0,0 +1,107 @@
+// 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_GEOMETRIES_ADAPTED_BOOST_POLYGON_POLYGON_HPP
+#define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_POLYGON_HPP
+
+// Adapts Geometries from Boost.Polygon for usage in Boost.Geometry
+// boost::polygon::polygon_with_holes_data -> boost::geometry::polygon
+
+
+#include <cstddef>
+
+
+
+#include <boost/geometry/core/tags.hpp>
+#include <boost/geometry/core/ring_type.hpp>
+#include <boost/geometry/core/exterior_ring.hpp>
+#include <boost/geometry/core/interior_rings.hpp>
+
+#include <boost/polygon/polygon.hpp>
+
+
+#include <boost/geometry/geometries/adapted/boost_polygon_polygon_ring.hpp>
+#include <boost/geometry/geometries/adapted/boost_polygon_polygon_iterator.hpp>
+#include <boost/geometry/geometries/adapted/boost_polygon_polygon_interiors.hpp>
+
+
+namespace boost { namespace geometry
+{
+
+
+#ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
+namespace traits
+{
+
+template <typename CoordinateType>
+struct tag<boost::polygon::polygon_with_holes_data<CoordinateType> >
+{
+ typedef polygon_tag type;
+};
+
+
+
+template <typename CoordinateType>
+struct ring_type<boost::polygon::polygon_with_holes_data<CoordinateType> >
+{
+ typedef typename bp_ring<boost::polygon::polygon_data<CoordinateType> > type;
+};
+
+
+template <typename CoordinateType>
+struct interior_type<boost::polygon::polygon_with_holes_data<CoordinateType> >
+{
+ // TEMPORARY! This meta-function will be removed, because it is always used in
+ // the concept of "range-iterator<interior_type>" so it should define the range-iterator
+ typedef typename bp_interiors<boost::polygon::polygon_with_holes_data<CoordinateType> > type;
+};
+
+
+template <typename CoordinateType>
+struct exterior_ring<boost::polygon::polygon_with_holes_data<CoordinateType> >
+{
+ typedef boost::polygon::polygon_with_holes_data<CoordinateType> polygon_type;
+ typedef bp_ring<boost::polygon::polygon_data<CoordinateType> > r_type;
+
+ static inline r_type get(polygon_type& p)
+ {
+ return r_type(p);
+ }
+
+ static inline r_type get(polygon_type const& p)
+ {
+ return r_type(p);
+ }
+};
+
+template <typename CoordinateType>
+struct interior_rings<boost::polygon::polygon_with_holes_data<CoordinateType> >
+{
+ typedef boost::polygon::polygon_with_holes_data<CoordinateType> polygon_type;
+ typedef typename bp_interiors<polygon_type> itype;
+
+ static inline itype get(polygon_type& p)
+ {
+ return bp_interiors<polygon_type>(p);
+ }
+
+ static inline typename itype const get(polygon_type const& p)
+ {
+ return bp_interiors<polygon_type>(p);
+ }
+};
+
+
+
+} // namespace traits
+#endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
+
+}} // namespace boost::geometry
+
+
+#endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_POLYGON_HPP
+

Modified: sandbox/geometry/boost/geometry/util/add_const_if_c.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/util/add_const_if_c.hpp (original)
+++ sandbox/geometry/boost/geometry/util/add_const_if_c.hpp 2010-12-11 06:57:02 EST (Sat, 11 Dec 2010)
@@ -23,8 +23,8 @@
         will be defined as const, otherwise it will be defined as it was.
         This meta-function is used to have one implementation for both
         const and non const references
- \note This traits class is completely independant from GGL and might be a
- separate addition to Boost
+ \note This traits class is completely independant from Boost.Geometry
+ and might be a separate addition to Boost
     \note Used in a.o. for_each, interior_rings, exterior_ring
     \par Example
     \code

Added: sandbox/geometry/boost/geometry/util/ensure_const_reference.hpp
==============================================================================
--- (empty file)
+++ sandbox/geometry/boost/geometry/util/ensure_const_reference.hpp 2010-12-11 06:57:02 EST (Sat, 11 Dec 2010)
@@ -0,0 +1,49 @@
+// 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_UTIL_ENSURE_CONST_REFERENCE_HPP
+#define BOOST_GEOMETRY_UTIL_ENSURE_CONST_REFERENCE_HPP
+
+
+#include <boost/mpl/if.hpp>
+#include <boost/type_traits.hpp>
+
+
+namespace boost { namespace geometry
+{
+
+
+/*!
+ \brief Meta-function to change a & into a const&, if it is a reference,
+ otherwise it is the original
+ \ingroup utility
+ \note This traits class is completely independant from Boost.Geometry
+ and might be a separate addition to Boost
+ \note Used in a.o. interior_rings, exterior_ring
+*/
+template <typename T>
+struct ensure_const_reference
+{
+ typedef typename mpl::if_
+ <
+ typename boost::is_reference<T>::type,
+ typename boost::add_reference
+ <
+ typename boost::add_const
+ <
+ typename boost::remove_reference<T>::type
+ >::type
+ >::type,
+ T
+ >::type type;
+};
+
+
+}} // namespace boost::geometry
+
+
+#endif // BOOST_GEOMETRY_UTIL_ENSURE_CONST_REFERENCE_HPP


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