diff --git a/doc/reference/io/read_wkt.qbk b/doc/reference/io/read_wkt.qbk index 05eca9817..d34e90647 100644 --- a/doc/reference/io/read_wkt.qbk +++ b/doc/reference/io/read_wkt.qbk @@ -8,6 +8,23 @@ http://www.boost.org/LICENSE_1_0.txt) =============================================================================/] +[heading The WKT Format] +WKT is a general markup format in ASCII. +It is described in detail on [@http://en.wikipedia.org/wiki/Well-known_text Wikipedia] + +Boost Geometry supports the common formats (POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON). Because Boost.Geometry +also supports Box and Segment geometries, which are not standard OGC geometries, there are some extensions: + +* a Box can be read from WKT by specifying either a polygon (with 4 points) or a specific BOX string (non OGC) +* a Segment can be read from WKT by specifying either a linestring (with 2 points) or a specific SEGMENT string (non OGC) +* a Ring can be read from WKT by specifying a polygon (with no holes) + +[heading Conformance] +Other libraries refer to this functionality as [*ST_GeomFromText] or [*STGeomFromText]. +That is not done here because Boost.Geometry support more text formats. The name GeomFromText +is reserved for future usage, which will then have an indication of the used text format. + + [heading Example] [read_wkt] diff --git a/doc/reference/io/wkt.qbk b/doc/reference/io/wkt.qbk index 8dac6185c..7c45a9f67 100644 --- a/doc/reference/io/wkt.qbk +++ b/doc/reference/io/wkt.qbk @@ -8,6 +8,12 @@ http://www.boost.org/LICENSE_1_0.txt) =============================================================================/] +[def __this_function__ wkt] + +[heading_conformance_ogc __this_function__..AsText] +[note __this_function__ is not named "AsText" or "as_text" because Boost.Geometry +also supports other textformats (svg, dsv)] + [heading Example] [wkt] [wkt_output] diff --git a/doc/src/examples/io/read_wkt.cpp b/doc/src/examples/io/read_wkt.cpp index 8abd818dd..55ed25e97 100644 --- a/doc/src/examples/io/read_wkt.cpp +++ b/doc/src/examples/io/read_wkt.cpp @@ -10,25 +10,26 @@ //[read_wkt //` Shows the usage of read_wkt -#include -#include - #include #include +#include #include int main() { - // Specify the basic type typedef boost::geometry::model::d2::point_xy point_type; - // Declare some geometries and set their values point_type a; - boost::geometry::model::polygon b; + boost::geometry::model::linestring b; + boost::geometry::model::polygon c; + boost::geometry::model::box d; + boost::geometry::model::segment e; boost::geometry::read_wkt("POINT(1 2)", a); - boost::geometry::read_wkt("POLYGON((0 0,0 7,4 2,2 0,0 0))", b); - + boost::geometry::read_wkt("LINESTRING(0 0,2 2,3 1)", b); + boost::geometry::read_wkt("POLYGON((0 0,0 7,4 2,2 0,0 0))", c); + boost::geometry::read_wkt("BOX(0 0,3 3)", d); + boost::geometry::read_wkt("SEGMENT(1 0,3 4)", e); return 0; } diff --git a/doc/src/examples/io/wkt.cpp b/doc/src/examples/io/wkt.cpp index f862b41a4..ffde1b094 100644 --- a/doc/src/examples/io/wkt.cpp +++ b/doc/src/examples/io/wkt.cpp @@ -11,7 +11,6 @@ //` Shows the usage of wkt #include -#include #include #include @@ -19,14 +18,19 @@ int main() { - // Specify the basic type - typedef boost::geometry::model::d2::point_xy point_type; + namespace geom = boost::geometry; + typedef geom::model::d2::point_xy point_type; - // Declare some geometries and set their values - point_type a; - boost::geometry::assign_values(a, 3, 6); + point_type point = geom::make(3, 6); + geom::model::polygon polygon; + geom::append(geom::exterior_ring(polygon), geom::make(0, 0)); + geom::append(geom::exterior_ring(polygon), geom::make(0, 4)); + geom::append(geom::exterior_ring(polygon), geom::make(4, 4)); + geom::append(geom::exterior_ring(polygon), geom::make(4, 0)); + geom::append(geom::exterior_ring(polygon), geom::make(0, 0)); - std::cout << boost::geometry::wkt(a) << std::endl; + std::cout << boost::geometry::wkt(point) << std::endl; + std::cout << boost::geometry::wkt(polygon) << std::endl; return 0; } @@ -37,7 +41,11 @@ int main() //[wkt_output /*` Output: -point(3 6) +[pre +POINT(3 6) +POLYGON((0 0,0 4,4 4,4 0,0 0)) +] + */ //] diff --git a/include/boost/geometry/extensions/algorithms/buffer/buffered_piece_collection.hpp b/include/boost/geometry/extensions/algorithms/buffer/buffered_piece_collection.hpp index 1f7e6efee..244ff2714 100644 --- a/include/boost/geometry/extensions/algorithms/buffer/buffered_piece_collection.hpp +++ b/include/boost/geometry/extensions/algorithms/buffer/buffered_piece_collection.hpp @@ -172,7 +172,7 @@ struct buffered_piece_collection // To check clustered locations we keep track of segments being opposite somewhere std::set m_in_opposite_segments; - RobustPolicy const& m_rescale_policy; + RobustPolicy const& m_robust_policy; struct buffer_occupation_info : public occupation_info > { @@ -195,7 +195,7 @@ struct buffered_piece_collection }; buffered_piece_collection(RobustPolicy const& robust_policy) - : m_rescale_policy(robust_policy) + : m_robust_policy(robust_policy) {} @@ -291,7 +291,8 @@ struct buffered_piece_collection turn_policy::apply(*prev1, *it1, *next1, *prev2, *it2, *next2, - the_model, m_rescale_policy, std::back_inserter(m_turns)); + false, false, false, false, + the_model, m_robust_policy, std::back_inserter(m_turns)); } } } @@ -388,7 +389,7 @@ struct buffered_piece_collection int const side_wrt_circle = side_on_convex_range(turn.point, boost::begin(ring) + seg_id.segment_index, boost::begin(ring) + pc.last_segment_index, - seg_id, on_segment_seg_id, m_rescale_policy); + seg_id, on_segment_seg_id, m_robust_policy); switch (side_wrt_circle) { case 0 : turn.count_on_offsetted++; break; @@ -397,7 +398,7 @@ struct buffered_piece_collection return; } - int side_helper = side_on_convex_range(turn.point, pc.helper_segments, m_rescale_policy); + int side_helper = side_on_convex_range(turn.point, pc.helper_segments, m_robust_policy); if (side_helper == 1) { // Left or outside @@ -407,7 +408,7 @@ struct buffered_piece_collection int const side_offsetted = side_on_convex_range(turn.point, boost::begin(ring) + seg_id.segment_index, boost::begin(ring) + pc.last_segment_index, - seg_id, on_segment_seg_id, m_rescale_policy); + seg_id, on_segment_seg_id, m_robust_policy); if (side_offsetted == 1) { return; @@ -424,8 +425,8 @@ struct buffered_piece_collection } if (side_helper == 0) { - if (detail::overlay::points_equal_or_close(turn.point, pc.helper_segments.back(), m_rescale_policy) - || detail::overlay::points_equal_or_close(turn.point, pc.helper_segments.front(), m_rescale_policy)) + if (detail::overlay::points_equal_or_close(turn.point, pc.helper_segments.back(), m_robust_policy) + || detail::overlay::points_equal_or_close(turn.point, pc.helper_segments.front(), m_robust_policy)) { turn.count_on_corner++; } @@ -664,12 +665,12 @@ struct buffered_piece_collection >::type robust_point_type; robust_point_type p1_rob, p2_rob, prev1_rob, prev2_rob, cur1_rob, cur2_rob; - geometry::recalculate(p1_rob, select_for_side(prev1, it1, which), m_rescale_policy); - geometry::recalculate(p2_rob, select_for_side(prev2, it2, which), m_rescale_policy); - geometry::recalculate(prev1_rob, *prev1, m_rescale_policy); - geometry::recalculate(prev2_rob, *prev2, m_rescale_policy); - geometry::recalculate(cur1_rob, *it1, m_rescale_policy); - geometry::recalculate(cur2_rob, *it2, m_rescale_policy); + geometry::recalculate(p1_rob, select_for_side(prev1, it1, which), m_robust_policy); + geometry::recalculate(p2_rob, select_for_side(prev2, it2, which), m_robust_policy); + geometry::recalculate(prev1_rob, *prev1, m_robust_policy); + geometry::recalculate(prev2_rob, *prev2, m_robust_policy); + geometry::recalculate(cur1_rob, *it1, m_robust_policy); + geometry::recalculate(cur2_rob, *it2, m_robust_policy); int const code1 = side_strategy::apply(p1_rob, prev2_rob, cur2_rob); int const code2 = side_strategy::apply(p2_rob, prev1_rob, cur1_rob); @@ -743,7 +744,7 @@ struct buffered_piece_collection return true; } - if (detail::overlay::points_equal_or_close(a.point, b.point, m_rescale_policy)) + if (detail::overlay::points_equal_or_close(a.point, b.point, m_robust_policy)) { std::cout << "="; return true; @@ -1165,7 +1166,7 @@ struct buffered_piece_collection enrich_intersection_points(m_turns, detail::overlay::operation_union, offsetted_rings, offsetted_rings, - m_rescale_policy, side_strategy_type()); + m_robust_policy, side_strategy_type()); } // Discards all rings which do have not-OK intersection points only. @@ -1222,7 +1223,7 @@ struct buffered_piece_collection traversed_rings.clear(); traverser::apply(offsetted_rings, offsetted_rings, detail::overlay::operation_union, - m_rescale_policy, m_turns, traversed_rings); + m_robust_policy, m_turns, traversed_rings); } template diff --git a/include/boost/geometry/extensions/algorithms/buffer/buffered_ring.hpp b/include/boost/geometry/extensions/algorithms/buffer/buffered_ring.hpp index 3aec0c677..9e8d47bf6 100644 --- a/include/boost/geometry/extensions/algorithms/buffer/buffered_ring.hpp +++ b/include/boost/geometry/extensions/algorithms/buffer/buffered_ring.hpp @@ -250,13 +250,7 @@ struct within static inline bool apply(Point const& point, MultiGeometry const& multi, Strategy const& strategy) { - return detail::within::geometry_multi_within_code - < - Point, - MultiGeometry, - Strategy, - point_in_buffered_ring - >::apply(point, multi, strategy) == 1; + return detail::within::point_in_geometry(point, multi, strategy) == 1; } }; diff --git a/include/boost/geometry/policies/robustness/get_rescale_policy.hpp b/include/boost/geometry/policies/robustness/get_rescale_policy.hpp index 142a3592e..ed7c1eb94 100644 --- a/include/boost/geometry/policies/robustness/get_rescale_policy.hpp +++ b/include/boost/geometry/policies/robustness/get_rescale_policy.hpp @@ -58,7 +58,8 @@ static inline void init_rescale_policy(Geometry const& geometry, num_type const diff = boost::numeric_cast(detail::get_max_size(env)); num_type const range = 10000000.0; // Define a large range to get precise integer coordinates num_type const half = 0.5; - factor = boost::numeric_cast( + factor = math::equals(diff, num_type()) ? 1 + : boost::numeric_cast( boost::numeric_cast(half + range / diff)); // Assign input/output minimal points @@ -90,7 +91,8 @@ static inline void init_rescale_policy(Geometry1 const& geometry1, num_type const diff = boost::numeric_cast(detail::get_max_size(env)); num_type const range = 10000000.0; // Define a large range to get precise integer coordinates num_type const half = 0.5; - factor = boost::numeric_cast( + factor = math::equals(diff, num_type()) ? 1 + : boost::numeric_cast( boost::numeric_cast(half + range / diff)); // Assign input/output minimal points