-
code
output
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
This function should not be used this way. When projecting you want to transform a geometry from a spheroid or a projected coordinate system to another projected coordinate system. That is the result should always be a two dimensional point (in cartesian coordinates and in units defined by the target coordinate system). One such a system is the Web Mercator projection (epsg: 3857). So by changing your example a bit #include <boost/geometry.hpp>
#include <boost/geometry/srs/epsg.hpp>
#include <boost/geometry/srs/projection.hpp>
#include <iostream>
using geographic_point_t = boost::geometry::model::d2::
point_xy<double, boost::geometry::cs::geographic<boost::geometry::degree>>;
using cartesian_point_t = boost::geometry::model::d2::
point_xy<double, boost::geometry::cs::cartesian>;
//web mercator projection
using proj_t =
boost::geometry::srs::projection<boost::geometry::srs::static_epsg<3857>>;
int main()
{
auto pj = proj_t{};
auto a = geographic_point_t{-123., 20.};
auto b = cartesian_point_t{};
pj.forward(a, b);
std::cout << b.x() << " , " << b.y() << "\n";
} output
which is as expected. The projection source is assumed to be WGS84 coordinate system (epsg: 4326). |
Beta Was this translation helpful? Give feedback.
-
I agree that my example is far-fetched. I accidentally stumbled upon this myself, in tests. It's just that nowhere in the output parameters, neither in the projection nor in the geometry, are radians indicated, only degrees. |
Beta Was this translation helpful? Give feedback.
-
When cartesian points are used in spherical or geographic context the angle unit is radian. So if a result of transformation are longitude and latitude and you pass cartesian point instead of geographic one then unit is converted if necessary. |
Beta Was this translation helpful? Give feedback.
-
You are right - the unit of measurement for the angle of cartesian points is the radian.
Here is another example of a trivial transformation, but one that preserves degrees. code
output
|
Beta Was this translation helpful? Give feedback.
-
Ah right. I looked at Vissarion's example. So my answer is incorrect. Sorry for confusion. Vissarion is right, i.e. forward projection always projects to cartesian and sets the result directly with |
Beta Was this translation helpful? Give feedback.
This function should not be used this way. When projecting you want to transform a geometry from a spheroid or a projected coordinate system to another projected coordinate system. That is the result should always be a two dimensional point (in cartesian coordinates and in units defined by the target coordinate system). One such a system is the Web Mercator projection (epsg: 3857). So by changing your example a bit