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 complete source code of the example can be found in the following file:

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.
Predefined angular units
Abbreviation
Full Name
ToKernel
rad
Radian
1.0
deg
Degree
PI / 180
grad
Grad
PI / 200
Predefined linear units
Abbreviation
Full Name
ToKernel
km
Kilometer
1000.0
m
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:
  • The factor of conversion to kernel units (the number of kernel units necessary to define one unit).
  • The abbreviation for your unit.
  • The full name of the unit.
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:
  • The toKernel method converts from the unit to the kernel unit.
  • The fromKernel method converts from kernel unit to the specific unit.
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.

Units 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.