Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
read_wkt

Parses OGC Well-Known Text (WKT (Well-Known Text)) into a geometry (any geometry)

Synopsis

template<typename Geometry>
void read_wkt(std::string const & wkt, Geometry & geometry)

Parameters

Type

Concept

Name

Description

std::string const &

wkt

string containing WKT (Well-Known Text)

Geometry &

Any type fulfilling a Geometry Concept

geometry

A model of the specified concept output geometry

Header

Either

#include <boost/geometry.hpp>

Or

#include <boost/geometry/io/wkt/read.hpp>

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.

Example

Shows the usage of read_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()
{
    typedef boost::geometry::model::d2::point_xy<double> point_type;

    point_type a;
    boost::geometry::model::linestring<point_type> b;
    boost::geometry::model::polygon<point_type> c;
    boost::geometry::model::box<point_type> d;
    boost::geometry::model::segment<point_type> e;

    boost::geometry::read_wkt("POINT(1 2)", a);
    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;
}

See also

PrevUpHomeNext