Converting Coordinates

AutoCAD Map 3D ObjectARX

 
Converting Coordinates
 
 
 

Any Cartesian coordinate pair you select in a geo-referenced coordinate system corresponds to a point on the surface of the earth. This fact defines a relation between the coordinate pairs in one coordinate system and the coordinate pairs in any other, so long as the point in question actually exists in both systems. In other words, so long as the coordinate systems have a region of intersection, and the point in question is in it.

To convert the coordinates of a point from one geo-referenced coordinate system to another

  1. Define a "source" coordinate system with ade_projsetsrc.
  2. Define a "destination" coordinate system with ade_projsetdest.
  3. Pass a coordinate pair to ade_projptforward.

    The function assumes that the coordinate pair you pass to it is a point in the source system, and it returns the corresponding coordinate pair in the destination system. If there is no corresponding coordinate pair, it returns nil.

To convert in the other direction, use ade_projptbackward.

You can specify coordinate triplets, but if you do, the Z value is ignored.

The following sample converts a known position from Latitude Longitude (LL) to Universal Transverse Mercator (UTM) using ade_projptforward(). If the conversion is successful, information about the conversion is displayed and the UTM coordinate is converted back to Lat Long using ade_projptbackward(). If you don't know the specific coordinate system code, click Select Coordinate System. In the Select Global Coordinate System dialog box, which is located under the Map ->Tools->Assign Global Coordinate System menu option. Select a category, and then select from a list of available coordinate systems. Click Properties to view the Code value of the selected coordinate system.

char* pszSourceCoordSys = "LL84";
int resultCode = ade_projsetsrc(pszSourceCoordSys);
char* pszDestCoordSys = "UTM27-15";
resultCode = ade_projsetdest(pszDestCoordSys);
ads_point coordPairToConvert;
        
coordPairToConvert[0] = -90.4794;
coordPairToConvert[1] = 38.7503;
        
ads_point convertedCoordPair;
        
resultCode = ade_projptforward(
coordPairToConvert,
convertedCoordPair);
        
if (RTNORM == resultCode){
acutPrintf(
"\nThe %s coordinate value of: %.4lf\,%.4lf was successfully converted"
" to %s yielding the value of: %.4lf\,%.4lf"
, pszSourceCoordSys, coordPairToConvert[0], coordPairToConvert[1]
, pszDestCoordSys, convertedCoordPair[0], convertedCoordPair[1]);
          
coordPairToConvert[0] = convertedCoordPair[0];
coordPairToConvert[1] = convertedCoordPair[1];
          
ads_point convertedBackCoordPair;
resultCode = ade_projptbackward(
coordPairToConvert,
convertedBackCoordPair);
acutPrintf(
"\n\n\nUsing ade_projptbackward(), the %s coordinate value of: %.4lf\,%.4lf was"
" successfully converted back to %s yielding the value of: %.4lf\,%.4lf"
, pszDestCoordSys, coordPairToConvert[0], coordPairToConvert[1]
, pszSourceCoordSys, convertedBackCoordPair[0], convertedBackCoordPair[1]);
}
else {
acutPrintf(
"\nNo coordinate conversion took place.");
}