Programming with JViews Maps > Creating a Map Application Using the API > Handling Spatial Reference Systems > Managing Units

The management of units is performed by using three classes included in the ilog.views.maps package:

These classes deprecate the former ilog.views.maps.IlvUnitConverter, which did not make a clear distinction between units to measure angles and distances.

Units are simply reference systems to measure physical quantity. By convention, a kernel unit is defined for each type of unit. For angles, the kernel units are radians, and for lengths, the kernel units are meters. This allows an easy conversion between any derived units.

Units are attached to each axis of a coordinate system. This means that inside a coordinate system, you can have each ordinate expressed in different coordinates. For example, with geographic coordinate, you can have the x- and y-ordinates expressed in degrees, while the z-ordinate (corresponding for example to the ellipsoid height) is expressed in meters. Usually, in a coordinate system, the same unit is used to measure all physical quantities that are alike (for example, degrees for all angles).

The example is composed of the following steps:

The complete source code of the example can be found in the following file:

<installdir>/jviews-maps81/codefragments/srs/src/Sample3.java

Predefined Units

The package contains a list of predefined units, to measure both lengths and angles. A predefined unit is referenced by its abbreviation. To access a predefined unit converter, you can use either the static instance of the relevant class, or the static method GetRegisteredUnit().

See the following tables for a list of the predefined angular and linear units supplied with JViews Maps.

Table 3.2 Predefined Angular Units
Abbreviation 
Full Name 
ToKernel 
rad 
Radian 
1.0 
deg 
Degree 
PI / 180 
grad 
Grad 
PI / 200 

Table 3.3 Predefined Linear Units
Abbreviation 
Full Name 
ToKernel 
km 
Kilometer 
1000.0 
Meter 
1.0 
dm 
Decimeter 
0.1 
cm 
Centimeter 
0.01 
mm 
Millimeter 
0.0010 
kmi 
International Nautical Mile 
1852.0 
in 
International Inch 
0.0254 
ft 
International Foot 
0.3048 
yd 
International Yard 
0.9144 
mi 
International Statute Mile 
1609.344 
fath 
International Fathom 
1.8288 
ch 
International Chain 
20.1168 
link 
International Link 
0.201168 
us-in 
U.S. Surveyor's Inch 
0.025400050800101603 
us-ft 
U.S. Surveyor's Foot 
0.304800609601219 
us-yd 
U.S. Surveyor's Yard 
0.914401828803658 
us-ch 
U.S. Surveyor's Chain 
20.11684023368047 
us-mi 
U.S. Surveyor's Statute Mile 
1609.347218694437 
ind-yd 
Indian Yard 
0.91439523 
ind-ft 
Indian Foot 
0.30479841 
ind-ch 
Indian Chain 
20.11669506 

Defining Units

The IlvUnit class is the superclass of all the units.The JViews Maps package provides two specialized versions of this class:

To define a new unit, you can create a new instance of these two classes specifying three parameters:

For example, the following code creates a new instance of IlvLinearUnit to convert meters to feet (assuming than 1 ft = 0.3048 meters):

IlvLinearUnit unit = new IlvLinearUnit(0.3048,
                                       "ft",
                                       "International foot");

Using Units

Units can be used for simple conversion between values, or in a coordinate system. Various standard units are defined in the built-in unit classes of the JViews Maps package. These units can be retrieved by using either predefined static members of the classes IlvLinearUnit and IlvAngularUnit (these are the most used units), or the GetRegisteredUnit() method.

Simple Unit Conversion

For example, to convert meters to feet you can use either the static definition of feet as follows:

IlvLinearUnit unit = IlvLinearUnit.FT;
double meters = 100D;
double feet = unit.fromMeters(meters);
System.out.println("100 m = " + feet + " ft");
// The following is also valid, as the kernel unit for lengths
// is the meter.
double other_feet = unit.fromKernel(meters);
System.out.println("100 m = " + feet + " ft");

or the registered version:

IlvUnit unit = IlvUnit.GetRegisteredUnit("ft");
double meters = 100D;
double feet = unit.fromKernel(meters);
System.out.println("100 m = " + feet + " ft");

For standard conversion of units, the IlvUnit class defines the following methods:

In addition, the IlvLinearUnit class (respectively IlvAngularUnit) defines the toMeters() and fromMeters() methods (respectively toRadians and fromRadians methods) for applications that need explicit method calls.

In Coordinate Systems

Units are part of the definition of coordinate systems, which means that all the coordinate systems have to be constructed with units for axis. Once the unit is defined for a coordinate system, the transformation factory is able to automatically add subsequent affine transforms to convert coordinates in the transformation path.