...one of the most highly
regarded and expertly designed C++ library projects in the
world.

— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards

Transforms from one geometry to another geometry using a strategy.

template<typename Geometry1, typename Geometry2> bool transform(Geometry1 const & geometry1, Geometry2 & geometry2)

Type |
Concept |
Name |
Description |
---|---|---|---|

Geometry1 const & |
Any type fulfilling a Geometry Concept |
geometry1 |
A model of the specified concept |

Geometry2 & |
Any type fulfilling a Geometry Concept |
geometry2 |
A model of the specified concept |

True if the transformation could be done

Either

`#include <boost/geometry/geometry.hpp>`

Or

`#include <boost/geometry/algorithms/transform.hpp>`

The function transform is not defined by OGC.

Case |
Behavior |
---|---|

Spherical (degree) / Spherical (radian) |
Transforms coordinates from degree to radian, or vice versa |

Spherical / Cartesian (3D) |
Transforms coordinates from spherical coordinates to X,Y,Z, or vice versa, on a unit sphere |

Spherical (degree, with radius) / Spherical (radian, with radius) |
Transforms coordinates from degree to radian, or vice versa. Third coordinate (radius) is untouched |

Spherical (with radius) / Cartesian (3D) |
Transforms coordinates from spherical coordinates to X,Y,Z, or vice versa, on a unit sphere. Third coordinate (radius) is taken into account |

Linear

Shows how points can be transformed using the default strategy

#include <iostream> #include <boost/geometry.hpp> int main() { namespace bg = boost::geometry; // Select a point near the pole (theta=5.0, phi=15.0) bg::model::point<long double, 2, bg::cs::spherical<bg::degree> > p1(15.0, 5.0); // Transform from degree to radian. Default strategy is automatically selected, // it will convert from degree to radian bg::model::point<long double, 2, bg::cs::spherical<bg::radian> > p2; bg::transform(p1, p2); // Transform from degree (lon-lat) to 3D (x,y,z). Default strategy is automatically selected, // it will consider points on a unit sphere bg::model::point<long double, 3, bg::cs::cartesian> p3; bg::transform(p1, p3); std::cout << "p1: " << bg::dsv(p1) << std::endl << "p2: " << bg::dsv(p2) << std::endl << "p3: " << bg::dsv(p3) << std::endl; return 0; }

Output:

p1: (15, 5) p2: (0.261799, 0.0872665) p3: (0.084186, 0.0225576, 0.996195)