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);

    // 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;

    // 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();


    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!

  • Can you check your projString as valid with QGIS?
    – Cary H
    May 23 at 12:17
  • Checking the string with qgis return true... so i think it is ok, but the conversion does not work..r
    – Gab74
    May 23 at 12:22
  • Have you tried pyproj? gis.stackexchange.com/questions/330445/…
    – Cary H
    May 24 at 11:36
  • ..sorry buy i must use only QGis...
    – Gab74
    May 24 at 14:41


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.