...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
WKT-string formulating function.
template<typename Geometry> std::string to_wkt(Geometry const & geometry)
Type |
Concept |
Name |
Description |
---|---|---|---|
Geometry const & |
Any type fulfilling a Geometry Concept |
geometry |
A model of the specified concept |
Either
#include <boost/geometry.hpp>
Or
#include <boost/geometry/io/wkt/write.hpp>
The function to_wkt implements function AsText from the OGC Simple Feature Specification.
Note | |
---|---|
to_wkt is not named "AsText" or "as_text" because Boost.Geometry also supports other textformats (svg, dsv) |
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; return 0; }
Output:
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))