Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
410b0c3
[io][wkt] add to_wkt in write.hpp
sudo-panda Feb 29, 2020
abe1339
[test][io][wkt] modify tests for wkt to also test to_wkt
sudo-panda Feb 29, 2020
19855ae
[io][wkt] implement changes requested in review
sudo-panda Mar 1, 2020
aa5b1b5
[io][wkt] add from_wkt function
sudo-panda Mar 1, 2020
6c10e7a
[doc][io][wkt] add docs for to_wkt and from_wkt
sudo-panda Mar 1, 2020
40071e4
[io][wkt] fix bug
sudo-panda Mar 2, 2020
b5cb2a4
[test][io][wkt] Add test for from_wkt
sudo-panda Mar 2, 2020
8c48b58
[doc][io][wkt] add doc for from_wkt and to_wkt
sudo-panda Mar 3, 2020
d9c8ff3
[doc][io][wkt] fix bugs in index.html and example file
sudo-panda Mar 3, 2020
267097c
[io][wkt] minor bug fixes
sudo-panda Mar 4, 2020
dc6ab7e
[io][wkt] modify output formatter for < C++11
sudo-panda Mar 5, 2020
29975b2
[io][wkt] revert back output_formatter in write
sudo-panda Mar 6, 2020
7ef8419
[io][wkt] allow users to set the precision for wkt
sudo-panda Mar 7, 2020
cfd58ad
[ex][io][wkt] add `significant_digits` example
sudo-panda Mar 7, 2020
1fd9b22
[io][wkt] add ostream template specialization of `output_formatter`
sudo-panda Mar 7, 2020
44c342c
[doc][io][wkt] minor changes and bug fixes
sudo-panda Mar 7, 2020
72a4788
[test][io][wkt] add test for `significant_digits`
sudo-panda Mar 7, 2020
2051e75
[io][wkt] minor changes
sudo-panda Mar 8, 2020
5abaed5
[test][io][wkt] add debug messages
sudo-panda Mar 17, 2020
fa4b3dd
[io][wkt] modify conditions for setting precision
sudo-panda Mar 17, 2020
36cf42f
[io][wkt] remove specialization for `ostream`
sudo-panda Mar 18, 2020
89c58a6
[io][wkt] remove `significant_digits` from wkt
sudo-panda Mar 18, 2020
322cd9f
[io][wkt] overload `to_wkt` function
sudo-panda Mar 18, 2020
6bf00d4
[doc][io] remove set precision example in wkt
sudo-panda Mar 18, 2020
6b67192
[test][io][wkt] remove test for precise wkt
sudo-panda Mar 18, 2020
2d096e5
[io][wkt] fix formatting
sudo-panda Mar 18, 2020
d4e9f6e
[io][wkt] fix `if` formatting
sudo-panda Mar 18, 2020
3b08f8c
[doc] add copyright information
sudo-panda Mar 19, 2020
ea31a91
[io][wkt] Revert changes and make to_wkt a wrapper
sudo-panda Apr 28, 2020
1d32d87
[ex][io][wkt] mordernize the example
sudo-panda Dec 3, 2020
0839e31
[ex][io][wkt] modify ex to show adv of from_wkt
sudo-panda Dec 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/imports.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@
[import src/examples/io/svg.cpp]
[import src/examples/io/wkt.cpp]
[import src/examples/io/read_wkt.cpp]
[import src/examples/io/to_wkt.cpp]
[import src/examples/io/from_wkt.cpp]

[import src/examples/strategies/buffer_join_round.cpp]
[import src/examples/strategies/buffer_join_miter.cpp]
Expand Down
2 changes: 2 additions & 0 deletions doc/quickref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,8 @@
<simplelist type="vert" columns="1">
<member><link linkend="geometry.reference.io.wkt.read_wkt">read_wkt</link></member>
<member><link linkend="geometry.reference.io.wkt.wkt">wkt</link></member>
<member><link linkend="geometry.reference.io.wkt.to_wkt">to_wkt</link></member>
<member><link linkend="geometry.reference.io.wkt.from_wkt">from_wkt</link></member>
</simplelist>
</entry>
<entry valign="top">
Expand Down
23 changes: 23 additions & 0 deletions doc/reference/io/from_wkt.qbk
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[/============================================================================
Boost.Geometry (aka GGL, Generic Geometry Library)

Copyright (c) 2020 Baidyanath Kundu, Haldia, India.

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)
=============================================================================/]

[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]
[from_wkt]

[heading See also]
* [link geometry.reference.io.wkt.wkt WKT streaming manipulator]
* [link geometry.reference.io.wkt.read_wkt Read WKT]
* [link geometry.reference.io.wkt.to_wkt To WKT]
2 changes: 2 additions & 0 deletions doc/reference/io/read_wkt.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ is reserved for future usage, which will then have an indication of the used tex
[read_wkt]

[heading See also]
* [link geometry.reference.io.wkt.from_wkt From WKT]
* [link geometry.reference.io.wkt.to_wkt To WKT]
* [link geometry.reference.io.wkt.wkt WKT streaming manipulator]
25 changes: 25 additions & 0 deletions doc/reference/io/to_wkt.qbk
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[/============================================================================
Boost.Geometry (aka GGL, Generic Geometry Library)

Copyright (c) 2009-2014 Barend Gehrels, Amsterdam, the Netherlands.
Copyright (c) 2020 Baidyanath Kundu, Haldia, India.

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)
=============================================================================/]

[def __this_function__ to_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]
[to_wkt]
[to_wkt_output]

[heading See also]
* [link geometry.reference.io.wkt.read_wkt Read WKT]
* [link geometry.reference.io.wkt.from_wkt From WKT]
* [link geometry.reference.io.wkt.wkt WKT streaming manipulator]
2 changes: 2 additions & 0 deletions doc/reference/io/wkt.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ also supports other textformats (svg, dsv)]

[heading See also]
* [link geometry.reference.io.wkt.read_wkt Read WKT]
* [link geometry.reference.io.wkt.from_wkt From WKT]
* [link geometry.reference.io.wkt.from_wkt To WKT]
2 changes: 2 additions & 0 deletions doc/src/examples/io/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ project boost-geometry-doc-example-io
exe svg : svg.cpp ;
exe wkt : wkt.cpp ;
exe read_wkt : read_wkt.cpp ;
exe to_wkt : to_wkt.cpp ;
exe from_wkt : from_wkt.cpp ;
36 changes: 36 additions & 0 deletions doc/src/examples/io/from_wkt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example

// Copyright (c) 2014 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2020 Baidyanath Kundu, Haldia, India.

// 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)

//[from_wkt
//` Shows the usage of from_wkt

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/polygon.hpp>

int main()
{
using point_type = boost::geometry::model::d2::point_xy<double>;
using box_type = boost::geometry::model::box<point_type>;
using segment_type = boost::geometry::model::segment<point_type>;
using polygon_type = boost::geometry::model::polygon<point_type>;
using linestring_type = boost::geometry::model::linestring<point_type>;

auto const a = boost::geometry::from_wkt<point_type>("POINT(1 2)");
auto const d = boost::geometry::from_wkt<box_type>("BOX(0 0,3 3)");
auto const e = boost::geometry::from_wkt<segment_type>("SEGMENT(1 0,3 4)");
auto const c = boost::geometry::from_wkt<polygon_type>("POLYGON((0 0,0 7,4 2,2 0,0 0))");
auto const b = boost::geometry::from_wkt<linestring_type>("LINESTRING(0 0,2 2,3 1)");

return 0;
}

//]
64 changes: 64 additions & 0 deletions doc/src/examples/io/to_wkt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example

// Copyright (c) 2020 Baidyanath Kundu, Haldia, India.

// 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)

//[to_wkt
//` Shows the usage of to_wkt

#include <iostream>

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>

int main()
{
namespace geom = boost::geometry;
typedef geom::model::d2::point_xy<double> point_type;

point_type point = geom::make<point_type>(3, 2);
geom::model::polygon<point_type> polygon;
geom::append(geom::exterior_ring(polygon), geom::make<point_type>(0, 0));
geom::append(geom::exterior_ring(polygon), geom::make<point_type>(0, 4));
geom::append(geom::exterior_ring(polygon), geom::make<point_type>(4, 4));
geom::append(geom::exterior_ring(polygon), geom::make<point_type>(4, 0));
geom::append(geom::exterior_ring(polygon), geom::make<point_type>(0, 0));

std::cout << boost::geometry::to_wkt(point) << std::endl;
std::cout << boost::geometry::to_wkt(polygon) << std::endl;

point_type point_frac = geom::make<point_type>(3.141592654, 27.18281828);
geom::model::polygon<point_type> polygon_frac;
geom::append(geom::exterior_ring(polygon_frac), geom::make<point_type>(0.00000, 0.00000));
geom::append(geom::exterior_ring(polygon_frac), geom::make<point_type>(0.00000, 4.00001));
geom::append(geom::exterior_ring(polygon_frac), geom::make<point_type>(4.00001, 4.00001));
geom::append(geom::exterior_ring(polygon_frac), geom::make<point_type>(4.00001, 0.00000));
geom::append(geom::exterior_ring(polygon_frac), geom::make<point_type>(0.00000, 0.00000));

std::cout << boost::geometry::to_wkt(point_frac, 3) << std::endl;
std::cout << boost::geometry::to_wkt(polygon_frac, 3) << std::endl;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the efforts of course. But I'm not sure about this example.
Mainly because I'm not sure about the whole functionality at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am waiting for comments from other reviewers before I change anything w.r.t. to_wkt.

return 0;
}

//]


//[to_wkt_output
/*`
Output:
[pre
POINT(3 2)
POLYGON((0 0,0 4,4 4,4 0,0 0))
POINT(3.14 27.2)
POLYGON((0 0,0 4,4 4,4 0,0 0))
]
*/
//]
4 changes: 3 additions & 1 deletion doc/src/examples/io/wkt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ int main()
/*`
Output:
[pre
POINT(3 6)
POINT(3 2)
POLYGON((0 0,0 4,4 4,4 0,0 0))
POINT(3.14 27.2)
POLYGON((0 0,0 4,4 4,4 0,0 0))
]

Expand Down
18 changes: 18 additions & 0 deletions include/boost/geometry/io/wkt/read.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
// Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
// Copyright (c) 2020 Baidyanath Kundu, Haldia, India

// This file was modified by Oracle on 2014-2020.
// Modifications copyright (c) 2014-2020 Oracle and/or its affiliates.
Expand Down Expand Up @@ -907,6 +908,23 @@ inline void read_wkt(std::string const& wkt, Geometry& geometry)
dispatch::read_wkt<typename tag<Geometry>::type, Geometry>::apply(wkt, geometry);
}

/*!
\brief Parses OGC Well-Known Text (\ref WKT) into a geometry (any geometry) and returns it
\ingroup wkt
\tparam Geometry \tparam_geometry
\param wkt string containing \ref WKT
\ingroup wkt
\qbk{[include reference/io/from_wkt.qbk]}
*/
template <typename Geometry>
inline Geometry from_wkt(std::string const& wkt)
{
Geometry geometry;
geometry::concepts::check<Geometry>();
dispatch::read_wkt<typename tag<Geometry>::type, Geometry>::apply(wkt, geometry);
return geometry;
}

}} // namespace boost::geometry

#endif // BOOST_GEOMETRY_IO_WKT_READ_HPP
26 changes: 26 additions & 0 deletions include/boost/geometry/io/wkt/write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Copyright (c) 2008-2017 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2017 Mateusz Loskot, London, UK.
// Copyright (c) 2014-2017 Adam Wulkiewicz, Lodz, Poland.
// Copyright (c) 2020 Baidyanath Kundu, Haldia, India.

// This file was modified by Oracle on 2015-2020.
// Modifications copyright (c) 2015-2020, Oracle and/or its affiliates.
Expand Down Expand Up @@ -554,6 +555,31 @@ inline wkt_manipulator<Geometry> wkt(Geometry const& geometry)
return wkt_manipulator<Geometry>(geometry);
}

/*!
\brief WKT-string formulating function
\tparam Geometry \tparam_geometry
\param geometry \param_geometry
\param significant_digits Specifies the no of significant digits to use in the output wkt
\ingroup wkt
\qbk{[include reference/io/to_wkt.qbk]}
*/
template <typename Geometry>
inline std::string to_wkt(Geometry const& geometry)
{
std::stringstream ss;
ss << boost::geometry::wkt(geometry);
return ss.str();
}

template <typename Geometry>
inline std::string to_wkt(Geometry const& geometry, int significant_digits)
{
std::stringstream ss;
ss.precision(significant_digits);
ss << boost::geometry::wkt(geometry);
return ss.str();
}

#if defined(_MSC_VER)
#pragma warning(pop)
#endif
Expand Down
Loading