Measuring Distance

AutoCAD Map 3D Geospatial Platform API

 
Measuring Distance
 
 
 

Measuring distance in geographic or projected coordinate systems requires great circle calculations. Both MgGeometry.Buffer() and MgGeometry.Distance() accept a measurement parameter that defines the great circle to be used. If the measurement parameter is null, the calculation is done using a linear algorithm.

Create the measurement parameter, an MgCoordinateSystemMeasure object, from the MgCoordinateSystem object.

Distance is calculated in the units of the SRS. MgCoordinateSystem includes two methods, ConvertCoordinateSystemUnitsToMeters() and ConvertMetersToCoordinateSystemUnits(), to convert to and from linear distances.

For example, to calculate the distance between two MgGeometry objects a and b, using the coordinate system srs, perform the following steps:

MgCoordinateSystemMeasure measure = srs.GetMeasure();
double distInMapUnits = a.Distance(b, measure);
double distInMeters = srs.ConvertCoordinateSystemUnitsToMeters(
   distInMapUnits);

Another way to calculate the distance is to use MgCoordinateSystemMeasure.GetDistance(), as in the following:

distInMapUnits = measure.GetDistance(a, b);