I have a .flt file that is located at N30 W84. I wrote a function that converts from lat,long to geocentric coordinates. In order to test this function I wrote, I want to use the mgGetCoord3d function to verify that I get the same results as when I calculate it with my custom function. The problem is, mgGetCoord3d returns (x,y,z)=0,0,0. I have tried this with multiple flt files and I always get the same result. What am I doing wrong? Thanks in advance...
#include <stdlib.h> /* exit */
using namespace std;
#define PI 3.14159
//Function to convert the geographic coordinates to geocentric coordinates.
Point GeographicToGeocentric (double latitude, double longitude)
// convert latitude and longitude from degrees to radians
double latrads = latitude / 180 * PI;
double lonrads = longitude / 180 * PI;
//calculate the geocentric x, y, z coordinates using trigonometric functions
result.z = sin(latrads);
double adjustedradius = cos(latrads);
result.x = adjustedradius * cos(lonrads);
result.y = adjustedradius * sin(lonrads);
int main(int argc, char* argv)
if (!(db = mgOpenDb(argv)))
printf("\nError in mgOpenDb(%s)\n", argv);
cout<<"File's coordinates (x,y,z): " << x << "," << y << "," << z << endl;
result = GeographicToGeocentric(30,84);
cout<<"Calculated coordinates (x,y,z): " << result.x << "," << result.y << "," << result.z << endl;
This is the output:
File's coordinates (x,y,z): 0,0,0
Calculated coordinates (x,y,z): 0.0905254,0.861281,0.5
The problem is that fltHeader does not contain a fltCoord3d. The function mgGetCoord3d expects you to give it a node and the name of a fltCoord3d record inside the node. The fltHeader node uses some double values to represent the db origin. Take a look at the data dictionary for fltHeader. The origin is stored in two doubles representing Lat and Lon. (fltOriginLat1 & fltOriginLong1)
You might also be interested in the mgProject and mgUnProject functions. These functions will convert between coord3d (x/y/z) and mgprojcoord (lat/lon/elevation) using a database's projection.
Hope this helps.
Thanks that did help clarify some things for me. I noticed in the fltHeader there is an attribute called fltProjection. Is there a method to convert from flat earth to geocentric? That is ultimately what I want to do. thanks!
btw, I didn't post the code, but I did use the mgProject and mgUnproject methods hoping that would be the way to convert to geocentric, but it didn't quite work. i will post the code when i get back in the office. thanks in advance.
There is no public method that I know of. There is a pro tool called Convert Database Projection. The fltProjection attribute on the fltHeader just tells you what projection the vertex positions currently represent. If you write your own routine to convert the projection, make sure you also change the fltProjection on the fltHeader to reflect the current projection of the db.
btw, I didnÃ¢â¬â¢t post the code, but I did use the mgProject and mgUnproject methods hoping that would be the way to convert to geocentric, but it didnÃ¢â¬â¢t quite work. i will post the code when i get back in the office. thanks in advance.
Keep in mind that mgProject and mgUnproject will convert from the current projection to lat/lon/elevation. It will not automatically change your projection.