Provides access to methods that allow a distance to be converted from one unit system to another.
Product Availability
Available with ArcGIS Desktop.
Members
Description | ||
---|---|---|
GetValue | Converts the string value to a double. |
CoClasses that implement IDistanceConverter
CoClasses and Classes | Description |
---|---|
DistanceConverter | Converts distance values from one unit to another. |
[C#]
////// IDistanceConverter example that shows how to convert a distance string /// to another linear unit. /// NOTE: Only projected coordinates systems will work /// public void ConvertDistance() { IDistanceConverter distanceConverter = new DistanceConverter(); // IDistanceConverter::GetValue requires a spatial reference //Get the spatial reference required from the current map UID editorUID = new UIDClass(); editorUID.Value = "esriEditor.Editor"; IEditor editor = m_application.FindExtensionByCLSID(editorUID) as IEditor; ISpatialReference spatialReference = editor.Map.SpatialReference; //convert distanceConverter.GetValue("150 ft", spatialReference); System.Windows.Forms.MessageBox.Show("" +(distanceConverter.GetValue("150 ft", spatialReference))); // Create an arbitrary SpatialReference, the only important part is the // linear units ISpatialReferenceFactory2 spatialReferenceFactory = new SpatialReferenceEnvironment() as ISpatialReferenceFactory2; IProjectedCoordinateSystem projectedCoordinateSystem = spatialReferenceFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_WGS1984UTM_10N); ILinearUnit linearUnit = spatialReferenceFactory.CreateUnit((int)esriSRUnitType.esriSRUnit_Foot) as ILinearUnit; IProjectedCoordinateSystemEdit projectedCoordinateSystemEdit = projectedCoordinateSystem as IProjectedCoordinateSystemEdit; //overhead casts object linearUnitObject = linearUnit; object missing = Type.Missing; projectedCoordinateSystemEdit.Define(ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref linearUnitObject, ref missing, ref missing); spatialReference = projectedCoordinateSystem; System.Windows.Forms.MessageBox.Show("" + (distanceConverter.GetValue("100m", spatialReference))); }