2

I need formula to convert xyz Cartesian coordinates to latitude,longitude,altitude using WGS84 to use in VBA application

x,y,z coordinates will be normal points (lets say, user pick point in AutoCAD, Microstation software without any user coordinate system set) and these xyz coordinates to be converted to latitude, longitude, altitude using WGS84

So, I need nearest accurate formula for conversion?

closed as unclear what you're asking by Vince, Fran Raga, J.R, nmtoken, user2856 Jun 15 at 9:02

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Do you mean ECEF points (earth centred earth fixed) XYZ? Or, as I suspect, do you mean XYZ in a projected coordinate system? Without you naming the projection - there is no way this question may be answered. – JimT Jun 12 at 12:56
  • @JimT XYZ cartesian coordinates without any projection, if conversion is not possible, I can take projection as WGS84 for conversion to lat, long, altitude – mmk Jun 12 at 13:26
  • 2
    No conversion is possible without knowing the original spatial reference. Reprojection math is less a formula than a process, and that process depends on both source and destination. – Vince Jun 12 at 13:33
  • @Vince if conversion is not possible, then take xyz cartesian in wgs84, if possible then covert to lat, long, altitude in wgs84 as well – mmk Jun 12 at 13:38
  • 1
    The point is, there is no way to know how to convert the X/Y/Z to degrees without knowing the spheroid and projection of the X/Y/Z values. What you're asking here is like calling a friend to say you are lost, and asking them to give you directions to their house, but not providing any indication of where you are. – Vince Jun 12 at 13:46
1

You have several options. Keep in mind that once you convert to a Cartesian coordinate system, the farther you go from the point of origin (0,0,0 in Cartesian space), the less accurate your coordinate system will be.

On option is to use the Universal Transverse Mercator (UTM) projection. Wikipedia will give you a lot more information (and math), but there is a lot of source code out there that you can use to do the transformations.

Another option is something that isn't used much in GIS, but is used frequently in modeling and simulation systems is a "Flat Earth" projection, made popular by a company called Multigen. Basically, it defines a plane on the tangent of a single point on the earth, referred to as the origin. Once you define an origin you can translate any lat/lon back and forth to Cartesian coordinates. The farther you get from the origin, and the closer you get to either pole, the more error you will get (I.e. the distance in the Cartesian system will be different from the actual geographic distance). But it's 'good enough' for a lot of applications.

Here is some C++ code I have, it should be pretty straight forward to convert to other languages. By the way, the Cartesian coordinates here are in meters.

    //! Provides conversion between WGS84 geodetic and flat earth coordinates.
class FlatEarthProjection
{
private:
    double lat_origin;
    double lon_origin;
    double convergence;

public:
    ~FlatEarthProjection(void);
    FlatEarthProjection(void);
    FlatEarthProjection(double originLat, double originLon);

    //! Set the origin for conversions.
    void setOrigin(double lat, double lon);

    //! Get the origin latitude.
    double getOriginLatitude(void) const;

    //! Get the origin longitude.
    double getOriginLongitude(void) const;

    //! Returns true if transformations are valid (valid origin); false otherwise.
    bool isValid(void) const;

    //! Convert the local (flat earth) y-coordinate to geodetic latitude.
    double convertLocalToGeoLat(double y) const;

    //! Convert the local (flat earth) x-coordinate to geodetic longitude.
    double convertLocalToGeoLon(double x) const;

    //! Convert geodetic longitude to local (flat earth) x.
    double convertGeoToLocalX(double lon) const;

    //! Convert geodetic latitude to local (flat earth) y.
    double convertGeoToLocalY(double lat) const;
};

FlatEarthProjection::~FlatEarthProjection(void)
{
}

FlatEarthProjection::FlatEarthProjection(void) : lat_origin(0.0f), lon_origin(0.0f), convergence(0.0f)
{
}

FlatEarthProjection::FlatEarthProjection(double originLat, double originLon)
{
    setOrigin(originLat, originLon);
}

void FlatEarthProjection::setOrigin(double lat, double lon)
{
    lat_origin = lat;       
    lon_origin = lon;
    convergence = cos(lat_origin * (M_PI / 180.0));
}

double FlatEarthProjection::getOriginLatitude(void) const
{
    return lat_origin;
}

double FlatEarthProjection::getOriginLongitude(void) const
{
    return lon_origin;
}

bool FlatEarthProjection::isValid(void) const
{
    return (convergence != 0.0f);
}

double FlatEarthProjection::convertLocalToGeoLat(double x) const
{
    return (x / 111120.0) + lat_origin;
}

double FlatEarthProjection::convertLocalToGeoLon(double y) const
{
    return ((y / (convergence  * 111120.0)) + lon_origin);
}

double FlatEarthProjection::convertGeoToLocalX(double lon) const
{
    return (lon - lon_origin) * convergence  * 111120.0;
}

double FlatEarthProjection::convertGeoToLocalY(double lat) const
{
    return (lat - lat_origin) * 111120.0;
}
  • The OP already has X,Y,Z values. If they weren't created using this algorithm, then this decoder isn't going to be of any value. – Vince Jun 12 at 15:40
  • I don't think that's true. All he needs is the latitude and longitude of the origin (the 0,0,0 of his Cartesian coordinates and conversion for whatever the units are in his pre-existing Cartesian data, for example, feet to meters). The CAD software will already be on a planar Cartesian coordinate system, so this approach just maps that to the 0,0,0 for a given lat/lon. – kevin42 Jun 12 at 15:46
  • @kevin42 xyz are in meters, if I consider 0,0,0 as origin for conversion to wgs84 lat, lon I want to consider z value as well, what is M_PI in C++ code (is it? Pi = 3.14) if I am comparing with online converter, values are with much difference, any simple accurate formula to convert normal xyz (in meters) to lat, lon, altitude considering wgs84? – mmk Jun 13 at 4:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.