I need to convert some cartesian (x,y) meter points coordinate from an origin to WGS 84 using QGIS 3.x API.
I have the lat and long of the origin: lat is +44.0 lon is +9.0 degrees. I try to make a simple test in C++, if i try to convert a point which coordinates are 0,0 the result must be lat +44 and long 9 degrees.
#include <QCoreApplication>
#include <qgscoordinatereferencesystem.h>
#include <qgscoordinatetransformcontext.h>
#include <qgsgeometry.h>
#include <qgsgeometryengine.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QgsApplication app(argc, argv, true);
QgsApplication::initQgis();
// Create a local Cartesian CRS with origin at lat=44, lon=9
QString projString = "+proj=cart +lon_0=9 +lat_0=44 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs";
QgsCoordinateReferenceSystem cartCRS;
cartCRS.createFromProj(projString);
// Create a point in the local Cartesian coordinates
QgsPointXY point(0, 0);
// Create a coordinate transform from the local Cartesian CRS to WGS84 CRS
QgsCoordinateTransform coordTransform(cartCRS, QgsCoordinateReferenceSystem::fromEpsgId(4326));
// Transform the point to latitude and longitude
QgsPointXY latLon = coordTransform.transform(point);
// Print the resulting latitude and longitude
qDebug() << "Latitude:" << latLon.y() << ", Longitude:" << latLon.x();
QgsApplication::exitQgis();
return a.exec();
}
But I received wrong values: Latitude 9 Longitude 90. What am I doing wrong?
If you have a Python code for me is OK!