...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Parses OGC Well-Known Text (WKT (Well-Known Text)) into a geometry (any geometry) and returns it.
template<typename Geometry> Geometry from_wkt(std::string const & wkt)
Type |
Concept |
Name |
Description |
---|---|---|---|
Geometry |
Any type fulfilling a Geometry Concept |
- |
Must be specified |
std::string const & |
wkt |
string containing WKT (Well-Known Text) |
Either
#include <boost/geometry.hpp>
Or
#include <boost/geometry/io/wkt/read.hpp>
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.
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; }