Mastering units is vital for working with geographic data. Your users will enter data in one unit without realizing that the map is based on another unit. For example, many users in the U.S. expect to enter units in the U.S. feet, but the map may be in meters. The following diagram shows the object model diagram of the different kinds of unit you can convert. An abstract class named Unit
provides the basis for instantiable classes named LinearUnit
, AreaUnit
, and AngularUnit
:
The Unit
class has one method of interest, called Create
, which allows you to create a unit using an ID that is a property of Unit
. The Unit
class also has the Name
and UnitType
methods. The good news is that you don't have to know these IDs or names. You can just use an ID like this:
AreaUnit squareYards = (AreaUnit)AreaUnit.Create(AreaUnits.SquareYards.Id);
In this case, the ID is 109442 and the name is SquareYards
. For example, to convert from square yards to square meters, you would simply call this line of code after the preceding one:
double squareMeters = squareYards.ConvertToSquareMeters(100.0);
100 square yards would then be converted into square meters.
The LinearUnit
class works in a similar fashion; in this class, you can convert distances to and from other units. The AngularUnit
class allows you to convert angular units, such as degrees to radians and vice versa.
The LinearUnit
class allows you to convert feet, inches, kilometers, meters, miles, millimeters, nautical miles, and yards. The AreaUnit
class allows you to convert acres, areas, hectares, square centimeters, square decimeters, square feet, square inches, square kilometers, square miles, square millimeters, and square yards. The AngularUnit
class allows you to convert degrees, grads, minutes, radians, and seconds.