stabilize build system: depends, installer, boost/bdb fixes, cross targets groundwork

This commit is contained in:
2026-02-24 18:38:47 +00:00
parent da8c28aaeb
commit 65cb2619a7
13106 changed files with 2484322 additions and 1804 deletions
@@ -0,0 +1,431 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-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_IO_DSV_WRITE_HPP
#define BOOST_GEOMETRY_IO_DSV_WRITE_HPP
#include <cstddef>
#include <ostream>
#include <string>
#include <boost/concept_check.hpp>
#include <boost/range.hpp>
#include <boost/geometry/algorithms/detail/interior_iterator.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/core/tag_cast.hpp>
#include <boost/geometry/core/tags.hpp>
#include <boost/geometry/geometries/concepts/check.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace dsv
{
struct dsv_settings
{
std::string coordinate_separator;
std::string point_open;
std::string point_close;
std::string point_separator;
std::string list_open;
std::string list_close;
std::string list_separator;
dsv_settings(std::string const& sep
, std::string const& open
, std::string const& close
, std::string const& psep
, std::string const& lopen
, std::string const& lclose
, std::string const& lsep
)
: coordinate_separator(sep)
, point_open(open)
, point_close(close)
, point_separator(psep)
, list_open(lopen)
, list_close(lclose)
, list_separator(lsep)
{}
};
/*!
\brief Stream coordinate of a point as \ref DSV
*/
template <typename Point, std::size_t Dimension, std::size_t Count>
struct stream_coordinate
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Point const& point,
dsv_settings const& settings)
{
os << (Dimension > 0 ? settings.coordinate_separator : "")
<< get<Dimension>(point);
stream_coordinate
<
Point, Dimension + 1, Count
>::apply(os, point, settings);
}
};
template <typename Point, std::size_t Count>
struct stream_coordinate<Point, Count, Count>
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>&,
Point const&,
dsv_settings const& )
{
}
};
/*!
\brief Stream indexed coordinate of a box/segment as \ref DSV
*/
template
<
typename Geometry,
std::size_t Index,
std::size_t Dimension,
std::size_t Count
>
struct stream_indexed
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Geometry const& geometry,
dsv_settings const& settings)
{
os << (Dimension > 0 ? settings.coordinate_separator : "")
<< get<Index, Dimension>(geometry);
stream_indexed
<
Geometry, Index, Dimension + 1, Count
>::apply(os, geometry, settings);
}
};
template <typename Geometry, std::size_t Index, std::size_t Count>
struct stream_indexed<Geometry, Index, Count, Count>
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>&, Geometry const&,
dsv_settings const& )
{
}
};
/*!
\brief Stream points as \ref DSV
*/
template <typename Point>
struct dsv_point
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Point const& p,
dsv_settings const& settings)
{
os << settings.point_open;
stream_coordinate<Point, 0, dimension<Point>::type::value>::apply(os, p, settings);
os << settings.point_close;
}
};
/*!
\brief Stream ranges as DSV
\note policy is used to stream prefix/postfix, enabling derived classes to override this
*/
template <typename Range>
struct dsv_range
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Range const& range,
dsv_settings const& settings)
{
typedef typename boost::range_iterator<Range const>::type iterator_type;
bool first = true;
os << settings.list_open;
for (iterator_type it = boost::begin(range);
it != boost::end(range);
++it)
{
os << (first ? "" : settings.point_separator)
<< settings.point_open;
stream_coordinate
<
point_type, 0, dimension<point_type>::type::value
>::apply(os, *it, settings);
os << settings.point_close;
first = false;
}
os << settings.list_close;
}
private:
typedef typename boost::range_value<Range>::type point_type;
};
/*!
\brief Stream sequence of points as DSV-part, e.g. (1 2),(3 4)
\note Used in polygon, all multi-geometries
*/
template <typename Polygon>
struct dsv_poly
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Polygon const& poly,
dsv_settings const& settings)
{
typedef typename ring_type<Polygon>::type ring;
os << settings.list_open;
dsv_range<ring>::apply(os, exterior_ring(poly), settings);
typename interior_return_type<Polygon const>::type
rings = interior_rings(poly);
for (typename detail::interior_iterator<Polygon const>::type
it = boost::begin(rings); it != boost::end(rings); ++it)
{
os << settings.list_separator;
dsv_range<ring>::apply(os, *it, settings);
}
os << settings.list_close;
}
};
template <typename Geometry, std::size_t Index>
struct dsv_per_index
{
typedef typename point_type<Geometry>::type point_type;
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Geometry const& geometry,
dsv_settings const& settings)
{
os << settings.point_open;
stream_indexed
<
Geometry, Index, 0, dimension<Geometry>::type::value
>::apply(os, geometry, settings);
os << settings.point_close;
}
};
template <typename Geometry>
struct dsv_indexed
{
typedef typename point_type<Geometry>::type point_type;
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Geometry const& geometry,
dsv_settings const& settings)
{
os << settings.list_open;
dsv_per_index<Geometry, 0>::apply(os, geometry, settings);
os << settings.point_separator;
dsv_per_index<Geometry, 1>::apply(os, geometry, settings);
os << settings.list_close;
}
};
}} // namespace detail::dsv
#endif // DOXYGEN_NO_DETAIL
#ifndef DOXYGEN_NO_DISPATCH
namespace dispatch
{
template <typename Tag, typename Geometry>
struct dsv {};
template <typename Point>
struct dsv<point_tag, Point>
: detail::dsv::dsv_point<Point>
{};
template <typename Linestring>
struct dsv<linestring_tag, Linestring>
: detail::dsv::dsv_range<Linestring>
{};
template <typename Box>
struct dsv<box_tag, Box>
: detail::dsv::dsv_indexed<Box>
{};
template <typename Segment>
struct dsv<segment_tag, Segment>
: detail::dsv::dsv_indexed<Segment>
{};
template <typename Ring>
struct dsv<ring_tag, Ring>
: detail::dsv::dsv_range<Ring>
{};
template <typename Polygon>
struct dsv<polygon_tag, Polygon>
: detail::dsv::dsv_poly<Polygon>
{};
} // namespace dispatch
#endif // DOXYGEN_NO_DISPATCH
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace dsv
{
// FIXME: This class is not copyable/assignable but it is used as such --mloskot
template <typename Geometry>
class dsv_manipulator
{
public:
inline dsv_manipulator(Geometry const& g,
dsv_settings const& settings)
: m_geometry(g)
, m_settings(settings)
{}
template <typename Char, typename Traits>
inline friend std::basic_ostream<Char, Traits>& operator<<(
std::basic_ostream<Char, Traits>& os,
dsv_manipulator const& m)
{
dispatch::dsv
<
typename tag_cast
<
typename tag<Geometry>::type,
multi_tag
>::type,
Geometry
>::apply(os, m.m_geometry, m.m_settings);
os.flush();
return os;
}
private:
Geometry const& m_geometry;
dsv_settings m_settings;
};
template <typename MultiGeometry>
struct dsv_multi
{
typedef dispatch::dsv
<
typename single_tag_of
<
typename tag<MultiGeometry>::type
>::type,
typename boost::range_value<MultiGeometry>::type
> dispatch_one;
typedef typename boost::range_iterator
<
MultiGeometry const
>::type iterator;
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
MultiGeometry const& multi,
dsv_settings const& settings)
{
os << settings.list_open;
bool first = true;
for(iterator it = boost::begin(multi);
it != boost::end(multi);
++it, first = false)
{
os << (first ? "" : settings.list_separator);
dispatch_one::apply(os, *it, settings);
}
os << settings.list_close;
}
};
}} // namespace detail::dsv
#endif // DOXYGEN_NO_DETAIL
// TODO: The alternative to this could be a forward declaration of dispatch::dsv<>
// or braking the code into the interface and implementation part
#ifndef DOXYGEN_NO_DISPATCH
namespace dispatch
{
template <typename Geometry>
struct dsv<multi_tag, Geometry>
: detail::dsv::dsv_multi<Geometry>
{};
} // namespace dispatch
#endif // DOXYGEN_NO_DISPATCH
/*!
\brief Main DSV-streaming function
\details DSV stands for Delimiter Separated Values. Geometries can be streamed
as DSV. There are defaults for all separators.
\note Useful for examples and testing purposes
\note With this function GeoJSON objects can be created, using the right
delimiters
\ingroup utility
*/
template <typename Geometry>
inline detail::dsv::dsv_manipulator<Geometry> dsv(Geometry const& geometry
, std::string const& coordinate_separator = ", "
, std::string const& point_open = "("
, std::string const& point_close = ")"
, std::string const& point_separator = ", "
, std::string const& list_open = "("
, std::string const& list_close = ")"
, std::string const& list_separator = ", "
)
{
concepts::check<Geometry const>();
return detail::dsv::dsv_manipulator<Geometry>(geometry,
detail::dsv::dsv_settings(coordinate_separator,
point_open, point_close, point_separator,
list_open, list_close, list_separator));
}
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_IO_DSV_WRITE_HPP
@@ -0,0 +1,58 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-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_IO_HPP
#define BOOST_GEOMETRY_IO_HPP
#include <boost/geometry/io/wkt/read.hpp>
#include <boost/geometry/io/wkt/write.hpp>
namespace boost { namespace geometry
{
struct format_wkt {};
struct format_wkb {}; // TODO
struct format_dsv {}; // TODO
#ifndef DOXYGEN_NO_DISPATCH
namespace dispatch
{
template <typename Tag, typename Geometry>
struct read
{
};
template <typename Geometry>
struct read<format_wkt, Geometry>
{
static inline void apply(Geometry& geometry, std::string const& wkt)
{
read_wkt<typename tag<Geometry>::type, Geometry>::apply(wkt, geometry);
}
};
} // namespace dispatch
#endif // DOXYGEN_NO_DISPATCH
template <typename Format, typename Geometry>
inline void read(Geometry& geometry, std::string const& wkt)
{
geometry::concepts::check<Geometry>();
dispatch::read<Format, Geometry>::apply(geometry, wkt);
}
// TODO: wriite
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_IO_HPP
@@ -0,0 +1,450 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2009-2015 Barend Gehrels, Amsterdam, the Netherlands.
// This file was modified by Oracle on 2015, 2016.
// Modifications copyright (c) 2015-2016, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-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_IO_SVG_MAPPER_HPP
#define BOOST_GEOMETRY_IO_SVG_MAPPER_HPP
#include <cstdio>
#include <vector>
#include <boost/config.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/geometry/core/tags.hpp>
#include <boost/geometry/core/tag_cast.hpp>
#include <boost/geometry/algorithms/envelope.hpp>
#include <boost/geometry/algorithms/expand.hpp>
#include <boost/geometry/algorithms/is_empty.hpp>
#include <boost/geometry/algorithms/transform.hpp>
#include <boost/geometry/strategies/transform/map_transformer.hpp>
#include <boost/geometry/views/segment_view.hpp>
#include <boost/geometry/io/svg/write.hpp>
// Helper geometries (all points are transformed to svg-points)
#include <boost/geometry/geometries/geometries.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DISPATCH
namespace dispatch
{
template <typename GeometryTag, typename Geometry, typename SvgPoint>
struct svg_map
{
BOOST_MPL_ASSERT_MSG
(
false, NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
, (Geometry)
);
};
template <typename Point, typename SvgPoint>
struct svg_map<point_tag, Point, SvgPoint>
{
template <typename TransformStrategy>
static inline void apply(std::ostream& stream,
std::string const& style, double size,
Point const& point, TransformStrategy const& strategy)
{
SvgPoint ipoint;
geometry::transform(point, ipoint, strategy);
stream << geometry::svg(ipoint, style, size) << std::endl;
}
};
template <typename BoxSeg1, typename BoxSeg2, typename SvgPoint>
struct svg_map_box_seg
{
template <typename TransformStrategy>
static inline void apply(std::ostream& stream,
std::string const& style, double size,
BoxSeg1 const& box_seg, TransformStrategy const& strategy)
{
BoxSeg2 ibox_seg;
// Fix bug in gcc compiler warning for possible uninitialization
#if defined(BOOST_GCC)
geometry::assign_zero(ibox_seg);
#endif
geometry::transform(box_seg, ibox_seg, strategy);
stream << geometry::svg(ibox_seg, style, size) << std::endl;
}
};
template <typename Box, typename SvgPoint>
struct svg_map<box_tag, Box, SvgPoint>
: svg_map_box_seg<Box, model::box<SvgPoint>, SvgPoint>
{};
template <typename Segment, typename SvgPoint>
struct svg_map<segment_tag, Segment, SvgPoint>
: svg_map_box_seg<Segment, model::segment<SvgPoint>, SvgPoint>
{};
template <typename Range1, typename Range2, typename SvgPoint>
struct svg_map_range
{
template <typename TransformStrategy>
static inline void apply(std::ostream& stream,
std::string const& style, double size,
Range1 const& range, TransformStrategy const& strategy)
{
Range2 irange;
geometry::transform(range, irange, strategy);
stream << geometry::svg(irange, style, size) << std::endl;
}
};
template <typename Ring, typename SvgPoint>
struct svg_map<ring_tag, Ring, SvgPoint>
: svg_map_range<Ring, model::ring<SvgPoint>, SvgPoint>
{};
template <typename Linestring, typename SvgPoint>
struct svg_map<linestring_tag, Linestring, SvgPoint>
: svg_map_range<Linestring, model::linestring<SvgPoint>, SvgPoint>
{};
template <typename Polygon, typename SvgPoint>
struct svg_map<polygon_tag, Polygon, SvgPoint>
{
template <typename TransformStrategy>
static inline void apply(std::ostream& stream,
std::string const& style, double size,
Polygon const& polygon, TransformStrategy const& strategy)
{
model::polygon<SvgPoint> ipoly;
geometry::transform(polygon, ipoly, strategy);
stream << geometry::svg(ipoly, style, size) << std::endl;
}
};
template <typename Multi, typename SvgPoint>
struct svg_map<multi_tag, Multi, SvgPoint>
{
typedef typename single_tag_of
<
typename geometry::tag<Multi>::type
>::type stag;
template <typename TransformStrategy>
static inline void apply(std::ostream& stream,
std::string const& style, double size,
Multi const& multi, TransformStrategy const& strategy)
{
for (typename boost::range_iterator<Multi const>::type it
= boost::begin(multi);
it != boost::end(multi);
++it)
{
svg_map
<
stag,
typename boost::range_value<Multi>::type,
SvgPoint
>::apply(stream, style, size, *it, strategy);
}
}
};
template <typename SvgPoint, typename Geometry>
struct devarianted_svg_map
{
template <typename TransformStrategy>
static inline void apply(std::ostream& stream,
std::string const& style,
double size,
Geometry const& geometry,
TransformStrategy const& strategy)
{
svg_map
<
typename tag_cast
<
typename tag<Geometry>::type,
multi_tag
>::type,
typename boost::remove_const<Geometry>::type,
SvgPoint
>::apply(stream, style, size, geometry, strategy);
}
};
template <typename SvgPoint, BOOST_VARIANT_ENUM_PARAMS(typename T)>
struct devarianted_svg_map<SvgPoint, variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
{
template <typename TransformStrategy>
struct visitor: static_visitor<void>
{
std::ostream& m_os;
std::string const& m_style;
double m_size;
TransformStrategy const& m_strategy;
visitor(std::ostream& os,
std::string const& style,
double size,
TransformStrategy const& strategy)
: m_os(os)
, m_style(style)
, m_size(size)
, m_strategy(strategy)
{}
template <typename Geometry>
inline void operator()(Geometry const& geometry) const
{
devarianted_svg_map<SvgPoint, Geometry>::apply(m_os, m_style, m_size, geometry, m_strategy);
}
};
template <typename TransformStrategy>
static inline void apply(std::ostream& stream,
std::string const& style,
double size,
variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry,
TransformStrategy const& strategy)
{
boost::apply_visitor(visitor<TransformStrategy>(stream, style, size, strategy), geometry);
}
};
} // namespace dispatch
#endif
template <typename SvgPoint, typename Geometry, typename TransformStrategy>
inline void svg_map(std::ostream& stream,
std::string const& style, double size,
Geometry const& geometry, TransformStrategy const& strategy)
{
dispatch::devarianted_svg_map<SvgPoint, Geometry>::apply(stream,
style, size, geometry, strategy);
}
/*!
\brief Helper class to create SVG maps
\tparam Point Point type, for input geometries.
\tparam SameScale Boolean flag indicating if horizontal and vertical scale should
be the same. The default value is true
\tparam SvgCoordinateType Coordinate type of SVG points. SVG is capable to
use floating point coordinates. Therefore the default value is double
\ingroup svg
\qbk{[include reference/io/svg.qbk]}
*/
template
<
typename Point,
bool SameScale = true,
typename SvgCoordinateType = double
>
class svg_mapper : boost::noncopyable
{
typedef model::point<SvgCoordinateType, 2, cs::cartesian> svg_point_type;
typedef typename geometry::select_most_precise
<
typename coordinate_type<Point>::type,
double
>::type calculation_type;
typedef strategy::transform::map_transformer
<
calculation_type,
geometry::dimension<Point>::type::value,
geometry::dimension<Point>::type::value,
true,
SameScale
> transformer_type;
model::box<Point> m_bounding_box;
boost::scoped_ptr<transformer_type> m_matrix;
std::ostream& m_stream;
SvgCoordinateType m_width, m_height;
std::string m_width_height; // for <svg> tag only, defaults to 2x 100%
void init_matrix()
{
if (! m_matrix)
{
m_matrix.reset(new transformer_type(m_bounding_box,
m_width, m_height));
m_stream << "<?xml version=\"1.0\" standalone=\"no\"?>"
<< std::endl
<< "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\""
<< std::endl
<< "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">"
<< std::endl
<< "<svg " << m_width_height << " version=\"1.1\""
<< std::endl
<< "xmlns=\"http://www.w3.org/2000/svg\""
<< std::endl
<< "xmlns:xlink=\"http://www.w3.org/1999/xlink\""
<< ">"
<< std::endl;
}
}
public :
/*!
\brief Constructor, initializing the SVG map. Opens and initializes the SVG.
Should be called explicitly.
\param stream Output stream, should be a stream already open
\param width Width of the SVG map (in SVG pixels)
\param height Height of the SVG map (in SVG pixels)
\param width_height Optional information to increase width and/or height
*/
svg_mapper(std::ostream& stream
, SvgCoordinateType width
, SvgCoordinateType height
, std::string const& width_height = "width=\"100%\" height=\"100%\"")
: m_stream(stream)
, m_width(width)
, m_height(height)
, m_width_height(width_height)
{
assign_inverse(m_bounding_box);
}
/*!
\brief Destructor, called automatically. Closes the SVG by streaming <\/svg>
*/
virtual ~svg_mapper()
{
m_stream << "</svg>" << std::endl;
}
/*!
\brief Adds a geometry to the transformation matrix. After doing this,
the specified geometry can be mapped fully into the SVG map
\tparam Geometry \tparam_geometry
\param geometry \param_geometry
*/
template <typename Geometry>
void add(Geometry const& geometry)
{
if (! geometry::is_empty(geometry))
{
expand(m_bounding_box,
return_envelope
<
model::box<Point>
>(geometry));
}
}
/*!
\brief Maps a geometry into the SVG map using the specified style
\tparam Geometry \tparam_geometry
\param geometry \param_geometry
\param style String containing verbatim SVG style information
\param size Optional size (used for SVG points) in SVG pixels. For linestrings,
specify linewidth in the SVG style information
*/
template <typename Geometry>
void map(Geometry const& geometry, std::string const& style,
double size = -1.0)
{
init_matrix();
svg_map<svg_point_type>(m_stream, style, size, geometry, *m_matrix);
}
/*!
\brief Adds a text to the SVG map
\tparam TextPoint \tparam_point
\param point Location of the text (in map units)
\param s The text itself
\param style String containing verbatim SVG style information, of the text
\param offset_x Offset in SVG pixels, defaults to 0
\param offset_y Offset in SVG pixels, defaults to 0
\param lineheight Line height in SVG pixels, in case the text contains \n
*/
template <typename TextPoint>
void text(TextPoint const& point, std::string const& s,
std::string const& style,
double offset_x = 0.0, double offset_y = 0.0,
double lineheight = 10.0)
{
init_matrix();
svg_point_type map_point;
transform(point, map_point, *m_matrix);
m_stream
<< "<text style=\"" << style << "\""
<< " x=\"" << get<0>(map_point) + offset_x << "\""
<< " y=\"" << get<1>(map_point) + offset_y << "\""
<< ">";
if (s.find("\n") == std::string::npos)
{
m_stream << s;
}
else
{
// Multi-line modus
std::vector<std::string> splitted;
boost::split(splitted, s, boost::is_any_of("\n"));
for (std::vector<std::string>::const_iterator it
= splitted.begin();
it != splitted.end();
++it, offset_y += lineheight)
{
m_stream
<< "<tspan x=\"" << get<0>(map_point) + offset_x
<< "\""
<< " y=\"" << get<1>(map_point) + offset_y
<< "\""
<< ">" << *it << "</tspan>";
}
}
m_stream << "</text>" << std::endl;
}
};
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_IO_SVG_MAPPER_HPP
@@ -0,0 +1,418 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2009-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
// This file was modified by Oracle on 2016.
// Modifications copyright (c) 2016, Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-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_IO_SVG_WRITE_HPP
#define BOOST_GEOMETRY_IO_SVG_WRITE_HPP
#include <ostream>
#include <string>
#include <boost/config.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/range.hpp>
#include <boost/variant/apply_visitor.hpp>
#include <boost/variant/static_visitor.hpp>
#include <boost/variant/variant_fwd.hpp>
#include <boost/geometry/algorithms/detail/interior_iterator.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/geometries/concepts/check.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace svg
{
template <typename Point>
struct svg_point
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Point const& p, std::string const& style, double size)
{
os << "<circle cx=\"" << geometry::get<0>(p)
<< "\" cy=\"" << geometry::get<1>(p)
<< "\" r=\"" << (size < 0 ? 5 : size)
<< "\" style=\"" << style << "\"/>";
}
};
template <typename Box>
struct svg_box
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Box const& box, std::string const& style, double)
{
// Prevent invisible boxes, making them >=1, using "max"
BOOST_USING_STD_MAX();
typedef typename coordinate_type<Box>::type ct;
ct x = geometry::get<geometry::min_corner, 0>(box);
ct y = geometry::get<geometry::min_corner, 1>(box);
ct width = max BOOST_PREVENT_MACRO_SUBSTITUTION (ct(1),
geometry::get<geometry::max_corner, 0>(box) - x);
ct height = max BOOST_PREVENT_MACRO_SUBSTITUTION (ct(1),
geometry::get<geometry::max_corner, 1>(box) - y);
os << "<rect x=\"" << x << "\" y=\"" << y
<< "\" width=\"" << width << "\" height=\"" << height
<< "\" style=\"" << style << "\"/>";
}
};
template <typename Segment>
struct svg_segment
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Segment const& segment, std::string const& style, double)
{
typedef typename coordinate_type<Segment>::type ct;
ct x1 = geometry::get<0, 0>(segment);
ct y1 = geometry::get<0, 1>(segment);
ct x2 = geometry::get<1, 0>(segment);
ct y2 = geometry::get<1, 1>(segment);
os << "<line x1=\"" << x1 << "\" y1=\"" << y1
<< "\" x2=\"" << x2 << "\" y2=\"" << y2
<< "\" style=\"" << style << "\"/>";
}
};
/*!
\brief Stream ranges as SVG
\note policy is used to select type (polyline/polygon)
*/
template <typename Range, typename Policy>
struct svg_range
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Range const& range, std::string const& style, double)
{
typedef typename boost::range_iterator<Range const>::type iterator;
bool first = true;
os << "<" << Policy::prefix() << " points=\"";
for (iterator it = boost::begin(range);
it != boost::end(range);
++it, first = false)
{
os << (first ? "" : " " )
<< geometry::get<0>(*it)
<< ","
<< geometry::get<1>(*it);
}
os << "\" style=\"" << style << Policy::style() << "\"/>";
}
};
template <typename Polygon>
struct svg_poly
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Polygon const& polygon, std::string const& style, double)
{
typedef typename geometry::ring_type<Polygon>::type ring_type;
typedef typename boost::range_iterator<ring_type const>::type iterator_type;
bool first = true;
os << "<g fill-rule=\"evenodd\"><path d=\"";
ring_type const& ring = geometry::exterior_ring(polygon);
for (iterator_type it = boost::begin(ring);
it != boost::end(ring);
++it, first = false)
{
os << (first ? "M" : " L") << " "
<< geometry::get<0>(*it)
<< ","
<< geometry::get<1>(*it);
}
// Inner rings:
{
typename interior_return_type<Polygon const>::type
rings = interior_rings(polygon);
for (typename detail::interior_iterator<Polygon const>::type
rit = boost::begin(rings); rit != boost::end(rings); ++rit)
{
first = true;
for (typename detail::interior_ring_iterator<Polygon const>::type
it = boost::begin(*rit); it != boost::end(*rit);
++it, first = false)
{
os << (first ? "M" : " L") << " "
<< geometry::get<0>(*it)
<< ","
<< geometry::get<1>(*it);
}
}
}
os << " z \" style=\"" << style << "\"/></g>";
}
};
struct prefix_linestring
{
static inline const char* prefix() { return "polyline"; }
static inline const char* style() { return ";fill:none"; }
};
struct prefix_ring
{
static inline const char* prefix() { return "polygon"; }
static inline const char* style() { return ""; }
};
template <typename MultiGeometry, typename Policy>
struct svg_multi
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
MultiGeometry const& multi, std::string const& style, double size)
{
for (typename boost::range_iterator<MultiGeometry const>::type
it = boost::begin(multi);
it != boost::end(multi);
++it)
{
Policy::apply(os, *it, style, size);
}
}
};
}} // namespace detail::svg
#endif // DOXYGEN_NO_DETAIL
#ifndef DOXYGEN_NO_DISPATCH
namespace dispatch
{
/*!
\brief Dispatching base struct for SVG streaming, specialized below per geometry type
\details Specializations should implement a static method "stream" to stream a geometry
The static method should have the signature:
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os, G const& geometry)
*/
template <typename Geometry, typename Tag = typename tag<Geometry>::type>
struct svg
{
BOOST_MPL_ASSERT_MSG
(
false, NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
, (Geometry)
);
};
template <typename Point>
struct svg<Point, point_tag> : detail::svg::svg_point<Point> {};
template <typename Segment>
struct svg<Segment, segment_tag> : detail::svg::svg_segment<Segment> {};
template <typename Box>
struct svg<Box, box_tag> : detail::svg::svg_box<Box> {};
template <typename Linestring>
struct svg<Linestring, linestring_tag>
: detail::svg::svg_range<Linestring, detail::svg::prefix_linestring> {};
template <typename Ring>
struct svg<Ring, ring_tag>
: detail::svg::svg_range<Ring, detail::svg::prefix_ring> {};
template <typename Polygon>
struct svg<Polygon, polygon_tag>
: detail::svg::svg_poly<Polygon> {};
template <typename MultiPoint>
struct svg<MultiPoint, multi_point_tag>
: detail::svg::svg_multi
<
MultiPoint,
detail::svg::svg_point
<
typename boost::range_value<MultiPoint>::type
>
>
{};
template <typename MultiLinestring>
struct svg<MultiLinestring, multi_linestring_tag>
: detail::svg::svg_multi
<
MultiLinestring,
detail::svg::svg_range
<
typename boost::range_value<MultiLinestring>::type,
detail::svg::prefix_linestring
>
>
{};
template <typename MultiPolygon>
struct svg<MultiPolygon, multi_polygon_tag>
: detail::svg::svg_multi
<
MultiPolygon,
detail::svg::svg_poly
<
typename boost::range_value<MultiPolygon>::type
>
>
{};
template <typename Geometry>
struct devarianted_svg
{
template <typename OutputStream>
static inline void apply(OutputStream& os,
Geometry const& geometry,
std::string const& style,
double size)
{
svg<Geometry>::apply(os, geometry, style, size);
}
};
template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
struct devarianted_svg<variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
{
template <typename OutputStream>
struct visitor: static_visitor<void>
{
OutputStream& m_os;
std::string const& m_style;
double m_size;
visitor(OutputStream& os, std::string const& style, double size)
: m_os(os)
, m_style(style)
, m_size(size)
{}
template <typename Geometry>
inline void operator()(Geometry const& geometry) const
{
devarianted_svg<Geometry>::apply(m_os, geometry, m_style, m_size);
}
};
template <typename OutputStream>
static inline void apply(
OutputStream& os,
variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry,
std::string const& style,
double size
)
{
boost::apply_visitor(visitor<OutputStream>(os, style, size), geometry);
}
};
} // namespace dispatch
#endif // DOXYGEN_NO_DISPATCH
/*!
\brief Generic geometry template manipulator class, takes corresponding output class from traits class
\ingroup svg
\details Stream manipulator, streams geometry classes as SVG (Scalable Vector Graphics)
*/
template <typename Geometry>
class svg_manipulator
{
public:
inline svg_manipulator(Geometry const& g, std::string const& style, double size)
: m_geometry(g)
, m_style(style)
, m_size(size)
{}
template <typename Char, typename Traits>
inline friend std::basic_ostream<Char, Traits>& operator<<(
std::basic_ostream<Char, Traits>& os, svg_manipulator const& m)
{
dispatch::devarianted_svg<Geometry>::apply(os,
m.m_geometry,
m.m_style,
m.m_size);
os.flush();
return os;
}
private:
Geometry const& m_geometry;
std::string const& m_style;
double m_size;
};
/*!
\brief Manipulator to stream geometries as SVG
\tparam Geometry \tparam_geometry
\param geometry \param_geometry
\param style String containing verbatim SVG style information
\param size Optional size (used for SVG points) in SVG pixels. For linestrings,
specify linewidth in the SVG style information
\ingroup svg
*/
template <typename Geometry>
inline svg_manipulator<Geometry> svg(Geometry const& geometry,
std::string const& style, double size = -1.0)
{
concepts::check<Geometry const>();
return svg_manipulator<Geometry>(geometry, style, size);
}
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_IO_SVG_WRITE_HPP
@@ -0,0 +1,28 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2009-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
// This file was modified by Oracle on 2016.
// Modifications copyright (c) 2016, Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-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_IO_SVG_WRITE_SVG_HPP
#define BOOST_GEOMETRY_IO_SVG_WRITE_SVG_HPP
// THIS FILE WAS LEFT HERE FOR BACKWARD COMPATIBILITY
#include <boost/geometry/io/svg/write.hpp>
#endif // BOOST_GEOMETRY_IO_SVG_WRITE_SVG_HPP
@@ -0,0 +1,27 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2009-2012 Barend Gehrels, Amsterdam, the Netherlands.
// This file was modified by Oracle on 2016.
// Modifications copyright (c) 2016, Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-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_IO_SVG_WRITE_SVG_MULTI_HPP
#define BOOST_GEOMETRY_IO_SVG_WRITE_SVG_MULTI_HPP
// THIS FILE WAS LEFT HERE FOR BACKWARD COMPATIBILITY
#include <boost/geometry/io/svg/write.hpp>
#endif // BOOST_GEOMETRY_IO_SVG_WRITE_SVG_MULTI_HPP
@@ -0,0 +1,66 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-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_IO_WKT_DETAIL_PREFIX_HPP
#define BOOST_GEOMETRY_IO_WKT_DETAIL_PREFIX_HPP
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace wkt
{
struct prefix_null
{
static inline const char* apply() { return ""; }
};
struct prefix_point
{
static inline const char* apply() { return "POINT"; }
};
struct prefix_polygon
{
static inline const char* apply() { return "POLYGON"; }
};
struct prefix_linestring
{
static inline const char* apply() { return "LINESTRING"; }
};
struct prefix_multipoint
{
static inline const char* apply() { return "MULTIPOINT"; }
};
struct prefix_multilinestring
{
static inline const char* apply() { return "MULTILINESTRING"; }
};
struct prefix_multipolygon
{
static inline const char* apply() { return "MULTIPOLYGON"; }
};
}} // namespace wkt::impl
#endif
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_IO_WKT_DETAIL_PREFIX_HPP
@@ -0,0 +1,56 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-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_DOMAINS_GIS_IO_WKT_DETAIL_WKT_MULTI_HPP
#define BOOST_GEOMETRY_DOMAINS_GIS_IO_WKT_DETAIL_WKT_MULTI_HPP
#include <boost/geometry/core/tags.hpp>
#include <boost/geometry/domains/gis/io/wkt/write.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace wkt
{
struct prefix_null
{
static inline const char* apply() { return ""; }
};
struct prefix_multipoint
{
static inline const char* apply() { return "MULTIPOINT"; }
};
struct prefix_multilinestring
{
static inline const char* apply() { return "MULTILINESTRING"; }
};
struct prefix_multipolygon
{
static inline const char* apply() { return "MULTIPOLYGON"; }
};
}} // namespace wkt::impl
#endif
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_DOMAINS_GIS_IO_WKT_DETAIL_WKT_MULTI_HPP
@@ -0,0 +1,905 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
// Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
// This file was modified by Oracle on 2014, 2015.
// Modifications copyright (c) 2014-2015 Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-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_IO_WKT_READ_HPP
#define BOOST_GEOMETRY_IO_WKT_READ_HPP
#include <cstddef>
#include <string>
#include <boost/lexical_cast.hpp>
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/mpl/if.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/size.hpp>
#include <boost/range/value_type.hpp>
#include <boost/throw_exception.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/geometry/algorithms/assign.hpp>
#include <boost/geometry/algorithms/append.hpp>
#include <boost/geometry/algorithms/clear.hpp>
#include <boost/geometry/algorithms/detail/equals/point_point.hpp>
#include <boost/geometry/core/access.hpp>
#include <boost/geometry/core/coordinate_dimension.hpp>
#include <boost/geometry/core/exception.hpp>
#include <boost/geometry/core/exterior_ring.hpp>
#include <boost/geometry/core/geometry_id.hpp>
#include <boost/geometry/core/interior_rings.hpp>
#include <boost/geometry/core/mutable_range.hpp>
#include <boost/geometry/core/point_type.hpp>
#include <boost/geometry/core/tag_cast.hpp>
#include <boost/geometry/core/tags.hpp>
#include <boost/geometry/geometries/concepts/check.hpp>
#include <boost/geometry/util/coordinate_cast.hpp>
#include <boost/geometry/io/wkt/detail/prefix.hpp>
namespace boost { namespace geometry
{
/*!
\brief Exception showing things wrong with WKT parsing
\ingroup wkt
*/
struct read_wkt_exception : public geometry::exception
{
template <typename Iterator>
read_wkt_exception(std::string const& msg,
Iterator const& it,
Iterator const& end,
std::string const& wkt)
: message(msg)
, wkt(wkt)
{
if (it != end)
{
source = " at '";
source += it->c_str();
source += "'";
}
complete = message + source + " in '" + wkt.substr(0, 100) + "'";
}
read_wkt_exception(std::string const& msg, std::string const& wkt)
: message(msg)
, wkt(wkt)
{
complete = message + "' in (" + wkt.substr(0, 100) + ")";
}
virtual ~read_wkt_exception() throw() {}
virtual const char* what() const throw()
{
return complete.c_str();
}
private :
std::string source;
std::string message;
std::string wkt;
std::string complete;
};
#ifndef DOXYGEN_NO_DETAIL
// (wkt: Well Known Text, defined by OGC for all geometries and implemented by e.g. databases (MySQL, PostGIS))
namespace detail { namespace wkt
{
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
template <typename Point,
std::size_t Dimension = 0,
std::size_t DimensionCount = geometry::dimension<Point>::value>
struct parsing_assigner
{
static inline void apply(tokenizer::iterator& it,
tokenizer::iterator const& end,
Point& point,
std::string const& wkt)
{
typedef typename coordinate_type<Point>::type coordinate_type;
// Stop at end of tokens, or at "," ot ")"
bool finished = (it == end || *it == "," || *it == ")");
try
{
// Initialize missing coordinates to default constructor (zero)
// OR
// Use lexical_cast for conversion to double/int
// Note that it is much slower than atof. However, it is more standard
// and in parsing the change in performance falls probably away against
// the tokenizing
set<Dimension>(point, finished
? coordinate_type()
: coordinate_cast<coordinate_type>::apply(*it));
}
catch(boost::bad_lexical_cast const& blc)
{
BOOST_THROW_EXCEPTION(read_wkt_exception(blc.what(), it, end, wkt));
}
catch(std::exception const& e)
{
BOOST_THROW_EXCEPTION(read_wkt_exception(e.what(), it, end, wkt));
}
catch(...)
{
BOOST_THROW_EXCEPTION(read_wkt_exception("", it, end, wkt));
}
parsing_assigner<Point, Dimension + 1, DimensionCount>::apply(
(finished ? it : ++it), end, point, wkt);
}
};
template <typename Point, std::size_t DimensionCount>
struct parsing_assigner<Point, DimensionCount, DimensionCount>
{
static inline void apply(tokenizer::iterator&,
tokenizer::iterator const&,
Point&,
std::string const&)
{
}
};
template <typename Iterator>
inline void handle_open_parenthesis(Iterator& it,
Iterator const& end,
std::string const& wkt)
{
if (it == end || *it != "(")
{
BOOST_THROW_EXCEPTION(read_wkt_exception("Expected '('", it, end, wkt));
}
++it;
}
template <typename Iterator>
inline void handle_close_parenthesis(Iterator& it,
Iterator const& end,
std::string const& wkt)
{
if (it != end && *it == ")")
{
++it;
}
else
{
BOOST_THROW_EXCEPTION(read_wkt_exception("Expected ')'", it, end, wkt));
}
}
template <typename Iterator>
inline void check_end(Iterator& it,
Iterator const& end,
std::string const& wkt)
{
if (it != end)
{
BOOST_THROW_EXCEPTION(read_wkt_exception("Too many tokens", it, end, wkt));
}
}
/*!
\brief Internal, parses coordinate sequences, strings are formated like "(1 2,3 4,...)"
\param it token-iterator, should be pre-positioned at "(", is post-positions after last ")"
\param end end-token-iterator
\param out Output itererator receiving coordinates
*/
template <typename Point>
struct container_inserter
{
// Version with output iterator
template <typename OutputIterator>
static inline void apply(tokenizer::iterator& it,
tokenizer::iterator const& end,
std::string const& wkt,
OutputIterator out)
{
handle_open_parenthesis(it, end, wkt);
Point point;
// Parse points until closing parenthesis
while (it != end && *it != ")")
{
parsing_assigner<Point>::apply(it, end, point, wkt);
out = point;
++out;
if (it != end && *it == ",")
{
++it;
}
}
handle_close_parenthesis(it, end, wkt);
}
};
template <typename Geometry,
closure_selector Closure = closure<Geometry>::value>
struct stateful_range_appender
{
typedef typename geometry::point_type<Geometry>::type point_type;
// NOTE: Geometry is a reference
inline void append(Geometry geom, point_type const& point, bool)
{
geometry::append(geom, point);
}
};
template <typename Geometry>
struct stateful_range_appender<Geometry, open>
{
typedef typename geometry::point_type<Geometry>::type point_type;
typedef typename boost::range_size
<
typename util::bare_type<Geometry>::type
>::type size_type;
BOOST_STATIC_ASSERT(( boost::is_same
<
typename tag<Geometry>::type,
ring_tag
>::value ));
inline stateful_range_appender()
: pt_index(0)
{}
// NOTE: Geometry is a reference
inline void append(Geometry geom, point_type const& point, bool is_next_expected)
{
bool should_append = true;
if (pt_index == 0)
{
first_point = point;
//should_append = true;
}
else
{
// NOTE: if there is not enough Points, they're always appended
should_append
= is_next_expected
|| pt_index < core_detail::closure::minimum_ring_size<open>::value
|| !detail::equals::equals_point_point(point, first_point);
}
++pt_index;
if (should_append)
{
geometry::append(geom, point);
}
}
private:
size_type pt_index;
point_type first_point;
};
// Geometry is a value-type or reference-type
template <typename Geometry>
struct container_appender
{
typedef typename geometry::point_type<Geometry>::type point_type;
static inline void apply(tokenizer::iterator& it,
tokenizer::iterator const& end,
std::string const& wkt,
Geometry out)
{
handle_open_parenthesis(it, end, wkt);
stateful_range_appender<Geometry> appender;
// Parse points until closing parenthesis
while (it != end && *it != ")")
{
point_type point;
parsing_assigner<point_type>::apply(it, end, point, wkt);
bool const is_next_expected = it != end && *it == ",";
appender.append(out, point, is_next_expected);
if (is_next_expected)
{
++it;
}
}
handle_close_parenthesis(it, end, wkt);
}
};
/*!
\brief Internal, parses a point from a string like this "(x y)"
\note used for parsing points and multi-points
*/
template <typename P>
struct point_parser
{
static inline void apply(tokenizer::iterator& it,
tokenizer::iterator const& end,
std::string const& wkt,
P& point)
{
handle_open_parenthesis(it, end, wkt);
parsing_assigner<P>::apply(it, end, point, wkt);
handle_close_parenthesis(it, end, wkt);
}
};
template <typename Geometry>
struct linestring_parser
{
static inline void apply(tokenizer::iterator& it,
tokenizer::iterator const& end,
std::string const& wkt,
Geometry& geometry)
{
container_appender<Geometry&>::apply(it, end, wkt, geometry);
}
};
template <typename Ring>
struct ring_parser
{
static inline void apply(tokenizer::iterator& it,
tokenizer::iterator const& end,
std::string const& wkt,
Ring& ring)
{
// A ring should look like polygon((x y,x y,x y...))
// So handle the extra opening/closing parentheses
// and in between parse using the container-inserter
handle_open_parenthesis(it, end, wkt);
container_appender<Ring&>::apply(it, end, wkt, ring);
handle_close_parenthesis(it, end, wkt);
}
};
/*!
\brief Internal, parses a polygon from a string like this "((x y,x y),(x y,x y))"
\note used for parsing polygons and multi-polygons
*/
template <typename Polygon>
struct polygon_parser
{
typedef typename ring_return_type<Polygon>::type ring_return_type;
typedef container_appender<ring_return_type> appender;
static inline void apply(tokenizer::iterator& it,
tokenizer::iterator const& end,
std::string const& wkt,
Polygon& poly)
{
handle_open_parenthesis(it, end, wkt);
int n = -1;
// Stop at ")"
while (it != end && *it != ")")
{
// Parse ring
if (++n == 0)
{
appender::apply(it, end, wkt, exterior_ring(poly));
}
else
{
typename ring_type<Polygon>::type ring;
appender::apply(it, end, wkt, ring);
traits::push_back
<
typename boost::remove_reference
<
typename traits::interior_mutable_type<Polygon>::type
>::type
>::apply(interior_rings(poly), ring);
}
if (it != end && *it == ",")
{
// Skip "," after ring is parsed
++it;
}
}
handle_close_parenthesis(it, end, wkt);
}
};
inline bool one_of(tokenizer::iterator const& it,
std::string const& value,
bool& is_present)
{
if (boost::iequals(*it, value))
{
is_present = true;
return true;
}
return false;
}
inline bool one_of(tokenizer::iterator const& it,
std::string const& value,
bool& present1,
bool& present2)
{
if (boost::iequals(*it, value))
{
present1 = true;
present2 = true;
return true;
}
return false;
}
inline void handle_empty_z_m(tokenizer::iterator& it,
tokenizer::iterator const& end,
bool& has_empty,
bool& has_z,
bool& has_m)
{
has_empty = false;
has_z = false;
has_m = false;
// WKT can optionally have Z and M (measured) values as in
// POINT ZM (1 1 5 60), POINT M (1 1 80), POINT Z (1 1 5)
// GGL supports any of them as coordinate values, but is not aware
// of any Measured value.
while (it != end
&& (one_of(it, "M", has_m)
|| one_of(it, "Z", has_z)
|| one_of(it, "EMPTY", has_empty)
|| one_of(it, "MZ", has_m, has_z)
|| one_of(it, "ZM", has_z, has_m)
)
)
{
++it;
}
}
/*!
\brief Internal, starts parsing
\param tokens boost tokens, parsed with separator " " and keeping separator "()"
\param geometry string to compare with first token
*/
template <typename Geometry>
inline bool initialize(tokenizer const& tokens,
std::string const& geometry_name,
std::string const& wkt,
tokenizer::iterator& it,
tokenizer::iterator& end)
{
it = tokens.begin();
end = tokens.end();
if (it != end && boost::iequals(*it++, geometry_name))
{
bool has_empty, has_z, has_m;
handle_empty_z_m(it, end, has_empty, has_z, has_m);
// Silence warning C4127: conditional expression is constant
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4127)
#endif
if (has_z && dimension<Geometry>::type::value < 3)
{
BOOST_THROW_EXCEPTION(read_wkt_exception("Z only allowed for 3 or more dimensions", wkt));
}
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
if (has_empty)
{
check_end(it, end, wkt);
return false;
}
// M is ignored at all.
return true;
}
BOOST_THROW_EXCEPTION(read_wkt_exception(std::string("Should start with '") + geometry_name + "'", wkt));
}
template <typename Geometry, template<typename> class Parser, typename PrefixPolicy>
struct geometry_parser
{
static inline void apply(std::string const& wkt, Geometry& geometry)
{
geometry::clear(geometry);
tokenizer tokens(wkt, boost::char_separator<char>(" ", ",()"));
tokenizer::iterator it, end;
if (initialize<Geometry>(tokens, PrefixPolicy::apply(), wkt, it, end))
{
Parser<Geometry>::apply(it, end, wkt, geometry);
check_end(it, end, wkt);
}
}
};
template <typename MultiGeometry, template<typename> class Parser, typename PrefixPolicy>
struct multi_parser
{
static inline void apply(std::string const& wkt, MultiGeometry& geometry)
{
traits::clear<MultiGeometry>::apply(geometry);
tokenizer tokens(wkt, boost::char_separator<char>(" ", ",()"));
tokenizer::iterator it, end;
if (initialize<MultiGeometry>(tokens, PrefixPolicy::apply(), wkt, it, end))
{
handle_open_parenthesis(it, end, wkt);
// Parse sub-geometries
while(it != end && *it != ")")
{
traits::resize<MultiGeometry>::apply(geometry, boost::size(geometry) + 1);
Parser
<
typename boost::range_value<MultiGeometry>::type
>::apply(it, end, wkt, *(boost::end(geometry) - 1));
if (it != end && *it == ",")
{
// Skip "," after multi-element is parsed
++it;
}
}
handle_close_parenthesis(it, end, wkt);
}
check_end(it, end, wkt);
}
};
template <typename P>
struct noparenthesis_point_parser
{
static inline void apply(tokenizer::iterator& it,
tokenizer::iterator const& end,
std::string const& wkt,
P& point)
{
parsing_assigner<P>::apply(it, end, point, wkt);
}
};
template <typename MultiGeometry, typename PrefixPolicy>
struct multi_point_parser
{
static inline void apply(std::string const& wkt, MultiGeometry& geometry)
{
traits::clear<MultiGeometry>::apply(geometry);
tokenizer tokens(wkt, boost::char_separator<char>(" ", ",()"));
tokenizer::iterator it, end;
if (initialize<MultiGeometry>(tokens, PrefixPolicy::apply(), wkt, it, end))
{
handle_open_parenthesis(it, end, wkt);
// If first point definition starts with "(" then parse points as (x y)
// otherwise as "x y"
bool using_brackets = (it != end && *it == "(");
while(it != end && *it != ")")
{
traits::resize<MultiGeometry>::apply(geometry, boost::size(geometry) + 1);
if (using_brackets)
{
point_parser
<
typename boost::range_value<MultiGeometry>::type
>::apply(it, end, wkt, *(boost::end(geometry) - 1));
}
else
{
noparenthesis_point_parser
<
typename boost::range_value<MultiGeometry>::type
>::apply(it, end, wkt, *(boost::end(geometry) - 1));
}
if (it != end && *it == ",")
{
// Skip "," after point is parsed
++it;
}
}
handle_close_parenthesis(it, end, wkt);
}
check_end(it, end, wkt);
}
};
/*!
\brief Supports box parsing
\note OGC does not define the box geometry, and WKT does not support boxes.
However, to be generic GGL supports reading and writing from and to boxes.
Boxes are outputted as a standard POLYGON. GGL can read boxes from
a standard POLYGON, from a POLYGON with 2 points of from a BOX
\tparam Box the box
*/
template <typename Box>
struct box_parser
{
static inline void apply(std::string const& wkt, Box& box)
{
bool should_close = false;
tokenizer tokens(wkt, boost::char_separator<char>(" ", ",()"));
tokenizer::iterator it = tokens.begin();
tokenizer::iterator end = tokens.end();
if (it != end && boost::iequals(*it, "POLYGON"))
{
++it;
bool has_empty, has_z, has_m;
handle_empty_z_m(it, end, has_empty, has_z, has_m);
if (has_empty)
{
assign_zero(box);
return;
}
handle_open_parenthesis(it, end, wkt);
should_close = true;
}
else if (it != end && boost::iequals(*it, "BOX"))
{
++it;
}
else
{
BOOST_THROW_EXCEPTION(read_wkt_exception("Should start with 'POLYGON' or 'BOX'", wkt));
}
typedef typename point_type<Box>::type point_type;
std::vector<point_type> points;
container_inserter<point_type>::apply(it, end, wkt, std::back_inserter(points));
if (should_close)
{
handle_close_parenthesis(it, end, wkt);
}
check_end(it, end, wkt);
unsigned int index = 0;
std::size_t n = boost::size(points);
if (n == 2)
{
index = 1;
}
else if (n == 4 || n == 5)
{
// In case of 4 or 5 points, we do not check the other ones, just
// take the opposite corner which is always 2
index = 2;
}
else
{
BOOST_THROW_EXCEPTION(read_wkt_exception("Box should have 2,4 or 5 points", wkt));
}
geometry::detail::assign_point_to_index<min_corner>(points.front(), box);
geometry::detail::assign_point_to_index<max_corner>(points[index], box);
}
};
/*!
\brief Supports segment parsing
\note OGC does not define the segment, and WKT does not support segmentes.
However, it is useful to implement it, also for testing purposes
\tparam Segment the segment
*/
template <typename Segment>
struct segment_parser
{
static inline void apply(std::string const& wkt, Segment& segment)
{
tokenizer tokens(wkt, boost::char_separator<char>(" ", ",()"));
tokenizer::iterator it = tokens.begin();
tokenizer::iterator end = tokens.end();
if (it != end &&
(boost::iequals(*it, "SEGMENT")
|| boost::iequals(*it, "LINESTRING") ))
{
++it;
}
else
{
BOOST_THROW_EXCEPTION(read_wkt_exception("Should start with 'LINESTRING' or 'SEGMENT'", wkt));
}
typedef typename point_type<Segment>::type point_type;
std::vector<point_type> points;
container_inserter<point_type>::apply(it, end, wkt, std::back_inserter(points));
check_end(it, end, wkt);
if (boost::size(points) == 2)
{
geometry::detail::assign_point_to_index<0>(points.front(), segment);
geometry::detail::assign_point_to_index<1>(points.back(), segment);
}
else
{
BOOST_THROW_EXCEPTION(read_wkt_exception("Segment should have 2 points", wkt));
}
}
};
}} // namespace detail::wkt
#endif // DOXYGEN_NO_DETAIL
#ifndef DOXYGEN_NO_DISPATCH
namespace dispatch
{
template <typename Tag, typename Geometry>
struct read_wkt {};
template <typename Point>
struct read_wkt<point_tag, Point>
: detail::wkt::geometry_parser
<
Point,
detail::wkt::point_parser,
detail::wkt::prefix_point
>
{};
template <typename L>
struct read_wkt<linestring_tag, L>
: detail::wkt::geometry_parser
<
L,
detail::wkt::linestring_parser,
detail::wkt::prefix_linestring
>
{};
template <typename Ring>
struct read_wkt<ring_tag, Ring>
: detail::wkt::geometry_parser
<
Ring,
detail::wkt::ring_parser,
detail::wkt::prefix_polygon
>
{};
template <typename Geometry>
struct read_wkt<polygon_tag, Geometry>
: detail::wkt::geometry_parser
<
Geometry,
detail::wkt::polygon_parser,
detail::wkt::prefix_polygon
>
{};
template <typename MultiGeometry>
struct read_wkt<multi_point_tag, MultiGeometry>
: detail::wkt::multi_point_parser
<
MultiGeometry,
detail::wkt::prefix_multipoint
>
{};
template <typename MultiGeometry>
struct read_wkt<multi_linestring_tag, MultiGeometry>
: detail::wkt::multi_parser
<
MultiGeometry,
detail::wkt::linestring_parser,
detail::wkt::prefix_multilinestring
>
{};
template <typename MultiGeometry>
struct read_wkt<multi_polygon_tag, MultiGeometry>
: detail::wkt::multi_parser
<
MultiGeometry,
detail::wkt::polygon_parser,
detail::wkt::prefix_multipolygon
>
{};
// Box (Non-OGC)
template <typename Box>
struct read_wkt<box_tag, Box>
: detail::wkt::box_parser<Box>
{};
// Segment (Non-OGC)
template <typename Segment>
struct read_wkt<segment_tag, Segment>
: detail::wkt::segment_parser<Segment>
{};
} // namespace dispatch
#endif // DOXYGEN_NO_DISPATCH
/*!
\brief Parses OGC Well-Known Text (\ref WKT) into a geometry (any geometry)
\ingroup wkt
\tparam Geometry \tparam_geometry
\param wkt string containing \ref WKT
\param geometry \param_geometry output geometry
\ingroup wkt
\qbk{[include reference/io/read_wkt.qbk]}
*/
template <typename Geometry>
inline void read_wkt(std::string const& wkt, Geometry& geometry)
{
geometry::concepts::check<Geometry>();
dispatch::read_wkt<typename tag<Geometry>::type, Geometry>::apply(wkt, geometry);
}
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_IO_WKT_READ_HPP
@@ -0,0 +1,38 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-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_IO_WKT_STREAM_HPP
#define BOOST_GEOMETRY_IO_WKT_STREAM_HPP
#include <boost/geometry/io/wkt/write.hpp>
// This short file contains only one manipulator, streaming as WKT
// Don't include this in any standard-included header file.
// Don't use namespace boost::geometry, to enable the library to stream custom
// geometries which are living outside the namespace boost::geometry
// This is currently not documented on purpose: the Doxygen 2 QBK generator
// should be updated w.r.t. << which in the end ruins the DocBook XML
template<typename Char, typename Traits, typename Geometry>
inline std::basic_ostream<Char, Traits>& operator<<
(
std::basic_ostream<Char, Traits> &os,
Geometry const& geom
)
{
os << boost::geometry::wkt(geom);
return os;
}
#endif // BOOST_GEOMETRY_IO_WKT_STREAM_HPP
@@ -0,0 +1,25 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-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_IO_WKT_WKT_HPP
#define BOOST_GEOMETRY_IO_WKT_WKT_HPP
#include <boost/geometry/io/wkt/read.hpp>
#include <boost/geometry/io/wkt/write.hpp>
// BSG 2011-02-03
// We don't include stream.hpp by default. That tries to stream anything not known
// by default (such as ttmath) and reports errors.
// Users can include stream.hpp themselves (if they want to)
#endif // BOOST_GEOMETRY_IO_WKT_WKT_HPP
@@ -0,0 +1,515 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
// Copyright (c) 2014-2015 Adam Wulkiewicz, Lodz, Poland.
// This file was modified by Oracle on 2015.
// Modifications copyright (c) 2015, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
// (geolib/GGL), copyright (c) 1995-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_IO_WKT_WRITE_HPP
#define BOOST_GEOMETRY_IO_WKT_WRITE_HPP
#include <ostream>
#include <string>
#include <boost/array.hpp>
#include <boost/range.hpp>
#include <boost/variant/apply_visitor.hpp>
#include <boost/variant/static_visitor.hpp>
#include <boost/variant/variant_fwd.hpp>
#include <boost/geometry/algorithms/detail/interior_iterator.hpp>
#include <boost/geometry/algorithms/assign.hpp>
#include <boost/geometry/algorithms/convert.hpp>
#include <boost/geometry/algorithms/detail/disjoint/point_point.hpp>
#include <boost/geometry/algorithms/not_implemented.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/core/tags.hpp>
#include <boost/geometry/geometries/concepts/check.hpp>
#include <boost/geometry/geometries/ring.hpp>
#include <boost/geometry/io/wkt/detail/prefix.hpp>
namespace boost { namespace geometry
{
// Silence warning C4512: 'boost::geometry::wkt_manipulator<Geometry>' : assignment operator could not be generated
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4512)
#endif
#ifndef DOXYGEN_NO_DETAIL
namespace detail { namespace wkt
{
template <typename P, int I, int Count>
struct stream_coordinate
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os, P const& p)
{
os << (I > 0 ? " " : "") << get<I>(p);
stream_coordinate<P, I + 1, Count>::apply(os, p);
}
};
template <typename P, int Count>
struct stream_coordinate<P, Count, Count>
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>&, P const&)
{}
};
struct prefix_linestring_par
{
static inline const char* apply() { return "LINESTRING("; }
};
struct prefix_ring_par_par
{
// Note, double parentheses are intentional, indicating WKT ring begin/end
static inline const char* apply() { return "POLYGON(("; }
};
struct opening_parenthesis
{
static inline const char* apply() { return "("; }
};
struct closing_parenthesis
{
static inline const char* apply() { return ")"; }
};
struct double_closing_parenthesis
{
static inline const char* apply() { return "))"; }
};
/*!
\brief Stream points as \ref WKT
*/
template <typename Point, typename Policy>
struct wkt_point
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os, Point const& p)
{
os << Policy::apply() << "(";
stream_coordinate<Point, 0, dimension<Point>::type::value>::apply(os, p);
os << ")";
}
};
/*!
\brief Stream ranges as WKT
\note policy is used to stream prefix/postfix, enabling derived classes to override this
*/
template <typename Range, typename PrefixPolicy, typename SuffixPolicy>
struct wkt_range
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Range const& range, bool force_closed)
{
typedef typename boost::range_iterator<Range const>::type iterator_type;
typedef stream_coordinate
<
point_type, 0, dimension<point_type>::type::value
> stream_type;
bool first = true;
os << PrefixPolicy::apply();
// TODO: check EMPTY here
iterator_type begin = boost::begin(range);
iterator_type end = boost::end(range);
for (iterator_type it = begin; it != end; ++it)
{
os << (first ? "" : ",");
stream_type::apply(os, *it);
first = false;
}
// optionally, close range to ring by repeating the first point
if (force_closed
&& boost::size(range) > 1
&& detail::disjoint::disjoint_point_point(*begin, *(end - 1)))
{
os << ",";
stream_type::apply(os, *begin);
}
os << SuffixPolicy::apply();
}
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Range const& range)
{
apply(os, range, false);
}
private:
typedef typename boost::range_value<Range>::type point_type;
};
/*!
\brief Stream sequence of points as WKT-part, e.g. (1 2),(3 4)
\note Used in polygon, all multi-geometries
*/
template <typename Range>
struct wkt_sequence
: wkt_range
<
Range,
opening_parenthesis,
closing_parenthesis
>
{};
template <typename Polygon, typename PrefixPolicy>
struct wkt_poly
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Polygon const& poly)
{
typedef typename ring_type<Polygon const>::type ring;
bool const force_closed = true;
os << PrefixPolicy::apply();
// TODO: check EMPTY here
os << "(";
wkt_sequence<ring>::apply(os, exterior_ring(poly), force_closed);
typename interior_return_type<Polygon const>::type
rings = interior_rings(poly);
for (typename detail::interior_iterator<Polygon const>::type
it = boost::begin(rings); it != boost::end(rings); ++it)
{
os << ",";
wkt_sequence<ring>::apply(os, *it, force_closed);
}
os << ")";
}
};
template <typename Multi, typename StreamPolicy, typename PrefixPolicy>
struct wkt_multi
{
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Multi const& geometry)
{
os << PrefixPolicy::apply();
// TODO: check EMPTY here
os << "(";
for (typename boost::range_iterator<Multi const>::type
it = boost::begin(geometry);
it != boost::end(geometry);
++it)
{
if (it != boost::begin(geometry))
{
os << ",";
}
StreamPolicy::apply(os, *it);
}
os << ")";
}
};
template <typename Box>
struct wkt_box
{
typedef typename point_type<Box>::type point_type;
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Box const& box)
{
// Convert to ring, then stream
typedef model::ring<point_type> ring_type;
ring_type ring;
geometry::convert(box, ring);
os << "POLYGON(";
wkt_sequence<ring_type>::apply(os, ring);
os << ")";
}
private:
inline wkt_box()
{
// Only streaming of boxes with two dimensions is support, otherwise it is a polyhedron!
//assert_dimension<B, 2>();
}
};
template <typename Segment>
struct wkt_segment
{
typedef typename point_type<Segment>::type point_type;
template <typename Char, typename Traits>
static inline void apply(std::basic_ostream<Char, Traits>& os,
Segment const& segment)
{
// Convert to two points, then stream
typedef boost::array<point_type, 2> sequence;
sequence points;
geometry::detail::assign_point_from_index<0>(segment, points[0]);
geometry::detail::assign_point_from_index<1>(segment, points[1]);
// In Boost.Geometry a segment is represented
// in WKT-format like (for 2D): LINESTRING(x y,x y)
os << "LINESTRING";
wkt_sequence<sequence>::apply(os, points);
}
private:
inline wkt_segment()
{}
};
}} // namespace detail::wkt
#endif // DOXYGEN_NO_DETAIL
#ifndef DOXYGEN_NO_DISPATCH
namespace dispatch
{
template <typename Geometry, typename Tag = typename tag<Geometry>::type>
struct wkt: not_implemented<Tag>
{};
template <typename Point>
struct wkt<Point, point_tag>
: detail::wkt::wkt_point
<
Point,
detail::wkt::prefix_point
>
{};
template <typename Linestring>
struct wkt<Linestring, linestring_tag>
: detail::wkt::wkt_range
<
Linestring,
detail::wkt::prefix_linestring_par,
detail::wkt::closing_parenthesis
>
{};
/*!
\brief Specialization to stream a box as WKT
\details A "box" does not exist in WKT.
It is therefore streamed as a polygon
*/
template <typename Box>
struct wkt<Box, box_tag>
: detail::wkt::wkt_box<Box>
{};
template <typename Segment>
struct wkt<Segment, segment_tag>
: detail::wkt::wkt_segment<Segment>
{};
/*!
\brief Specialization to stream a ring as WKT
\details A ring or "linear_ring" does not exist in WKT.
A ring is equivalent to a polygon without inner rings
It is therefore streamed as a polygon
*/
template <typename Ring>
struct wkt<Ring, ring_tag>
: detail::wkt::wkt_range
<
Ring,
detail::wkt::prefix_ring_par_par,
detail::wkt::double_closing_parenthesis
>
{};
/*!
\brief Specialization to stream polygon as WKT
*/
template <typename Polygon>
struct wkt<Polygon, polygon_tag>
: detail::wkt::wkt_poly
<
Polygon,
detail::wkt::prefix_polygon
>
{};
template <typename Multi>
struct wkt<Multi, multi_point_tag>
: detail::wkt::wkt_multi
<
Multi,
detail::wkt::wkt_point
<
typename boost::range_value<Multi>::type,
detail::wkt::prefix_null
>,
detail::wkt::prefix_multipoint
>
{};
template <typename Multi>
struct wkt<Multi, multi_linestring_tag>
: detail::wkt::wkt_multi
<
Multi,
detail::wkt::wkt_sequence
<
typename boost::range_value<Multi>::type
>,
detail::wkt::prefix_multilinestring
>
{};
template <typename Multi>
struct wkt<Multi, multi_polygon_tag>
: detail::wkt::wkt_multi
<
Multi,
detail::wkt::wkt_poly
<
typename boost::range_value<Multi>::type,
detail::wkt::prefix_null
>,
detail::wkt::prefix_multipolygon
>
{};
template <typename Geometry>
struct devarianted_wkt
{
template <typename OutputStream>
static inline void apply(OutputStream& os, Geometry const& geometry)
{
wkt<Geometry>::apply(os, geometry);
}
};
template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
struct devarianted_wkt<variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
{
template <typename OutputStream>
struct visitor: static_visitor<void>
{
OutputStream& m_os;
visitor(OutputStream& os)
: m_os(os)
{}
template <typename Geometry>
inline void operator()(Geometry const& geometry) const
{
devarianted_wkt<Geometry>::apply(m_os, geometry);
}
};
template <typename OutputStream>
static inline void apply(
OutputStream& os,
variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry
)
{
boost::apply_visitor(visitor<OutputStream>(os), geometry);
}
};
} // namespace dispatch
#endif // DOXYGEN_NO_DISPATCH
/*!
\brief Generic geometry template manipulator class, takes corresponding output class from traits class
\ingroup wkt
\details Stream manipulator, streams geometry classes as \ref WKT streams
\par Example:
Small example showing how to use the wkt class
\dontinclude doxygen_1.cpp
\skip example_as_wkt_point
\line {
\until }
*/
template <typename Geometry>
class wkt_manipulator
{
public:
inline wkt_manipulator(Geometry const& g)
: m_geometry(g)
{}
template <typename Char, typename Traits>
inline friend std::basic_ostream<Char, Traits>& operator<<(
std::basic_ostream<Char, Traits>& os,
wkt_manipulator const& m)
{
dispatch::devarianted_wkt<Geometry>::apply(os, m.m_geometry);
os.flush();
return os;
}
private:
Geometry const& m_geometry;
};
/*!
\brief Main WKT-streaming function
\tparam Geometry \tparam_geometry
\param geometry \param_geometry
\ingroup wkt
\qbk{[include reference/io/wkt.qbk]}
*/
template <typename Geometry>
inline wkt_manipulator<Geometry> wkt(Geometry const& geometry)
{
concepts::check<Geometry const>();
return wkt_manipulator<Geometry>(geometry);
}
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_IO_WKT_WRITE_HPP