diff --git a/example/01_point_example.cpp b/example/01_point_example.cpp index d1a70e74fb..7f8aa5f288 100644 --- a/example/01_point_example.cpp +++ b/example/01_point_example.cpp @@ -129,7 +129,7 @@ int main() assign_values(d3a, 1, 2, 3); assign_values(d3b, 4, 5, 6); d3 = distance(d3a, d3b); - + std::cout << wkt(d3a) << std::endl; // Other examples show other types of points, geometries and more algorithms diff --git a/include/boost/geometry/io/wkt/detail/prefix.hpp b/include/boost/geometry/io/wkt/detail/prefix.hpp index b566e02aa6..98624c2088 100644 --- a/include/boost/geometry/io/wkt/detail/prefix.hpp +++ b/include/boost/geometry/io/wkt/detail/prefix.hpp @@ -32,6 +32,11 @@ struct prefix_point static inline const char* apply() { return "POINT"; } }; +struct prefix_point_z +{ + static inline const char* apply() { return "POINT Z"; } +}; + struct prefix_polygon { static inline const char* apply() { return "POLYGON"; } diff --git a/include/boost/geometry/io/wkt/write.hpp b/include/boost/geometry/io/wkt/write.hpp index 6bd584b222..926799eeb6 100644 --- a/include/boost/geometry/io/wkt/write.hpp +++ b/include/boost/geometry/io/wkt/write.hpp @@ -113,13 +113,14 @@ struct double_closing_parenthesis /*! \brief Stream points as \ref WKT */ -template +template struct wkt_point { template static inline void apply(std::basic_ostream& os, Point const& p, bool) { - os << Policy::apply() << "("; + if(dimension::type::value == 3) os << Policy2::apply() << "("; + else os << Policy1::apply() << "("; stream_coordinate::type::value>::apply(os, p); os << ")"; } @@ -350,7 +351,8 @@ struct wkt : detail::wkt::wkt_point < Point, - detail::wkt::prefix_point + detail::wkt::prefix_point, + detail::wkt::prefix_point_z > {}; @@ -417,6 +419,7 @@ struct wkt detail::wkt::wkt_point < typename boost::range_value::type, + detail::wkt::prefix_null, detail::wkt::prefix_null >, detail::wkt::prefix_multipoint diff --git a/test/io/wkt/wkt.cpp b/test/io/wkt/wkt.cpp index ac418505d3..f066dd8717 100644 --- a/test/io/wkt/wkt.cpp +++ b/test/io/wkt/wkt.cpp @@ -175,6 +175,7 @@ void test_all() { using namespace boost::geometry; typedef bg::model::point P; + typedef bg::model::point PZ; test_wkt

("POINT(1 2)", 1); test_wkt >("LINESTRING(1 1,2 2,3 3)", 3, 2 * sqrt(2.0)); @@ -200,6 +201,7 @@ void test_all() "LINESTRING(1 0,2 0,3 0)"); test_relaxed_wkt

("POINT ( 1 2) ", "POINT(1 2)"); test_relaxed_wkt

("POINT M ( 1 2)", "POINT(1 2)"); + test_relaxed_wkt("POINT (1 2 3)", "Point Z(1 2 3)"); test_relaxed_wkt >("BOX(1 1,2 2)", "POLYGON((1 1,1 2,2 2,2 1,1 1))"); test_relaxed_wkt >("LINESTRING EMPTY", "LINESTRING()");