Thank you so much for a fully working code example!!
I feel like my flashlight just got a bit brighter as navigate deeper down the boost tunnels!


On Tue, Jul 6, 2021 at 6:54 PM Adam Wulkiewicz via Geometry <> wrote:
Hi John,

W dniu 06.07.2021 o 22:39, John Mairs via Geometry pisze:
> I've found some online calculators that compute (in 3 dimensions) 
> ECEF x,y,z to LLA and back.
> <>
> And I would like to do the same thing using boost geometry.
> I watched Adam's 2019 Fos4G in Bucharest and I think I saw that only
> 2D is supported.
> I'm new to GIS so all of the vocabulary terms are quite overwhelming.
> I have seen the example (transform_2) in the docs of going from degree
> (lon-lat) to 3d on the unit circle.  Even with that example i don't
> understand how (theta 5.0 and phi = 15.0) map to lat/long.

You're talking about this example right?
The coordinate system used there is spherical polar. See what is theta
and phi here:

You either need bg::cs::spherical_equatorial<bg::degree> or
bg::cs::geographic<bg::degree> to represent a point as longitude and
latitude. And while cs::spherical_equatorial is supported in transform()
by default cs::geographic is not. By "by default" I mean "without
passing an additional parameter - strategy" like that:

My talk was about SRS transformations, this is a different part of the
library than transform(), though they can be used together. It's more or
less Proj ( adapted to work with Boost.Geometry well.
The 2d/3d support depends on specific projection. Conversion between 3d
geographic coordinates and 3d ECEF cartesian coordinates is supported.

#include <boost/geometry.hpp>
#include <boost/geometry/srs/transformation.hpp>

int main()
     namespace bg = boost::geometry;
     using pt_geo_t = bg::model::point<double, 3,
     using pt_car_t = bg::model::point<double, 3, bg::cs::cartesian>;

         > tr;

     pt_geo_t pt_geo{ lon, lat, h };
     pt_car_t pt_car;

     tr.forward(pt_geo, pt_car);
     tr.inverse(pt_car, pt_geo);

In case you wanted to see how it's done or to implement it by yourself:

Geometry mailing list