| Programming with JViews Maps > Creating a Map Application Using the API > Handling Spatial Reference Systems > Managing Units |
Managing Units |
INDEX
PREVIOUS
NEXT
|
The management of units is performed by using three classes included in the ilog.views.maps package:
IlvUnit
IlvAngularUnit to measure angles.
IlvLinearUnit to measure lengths.
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
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.
Abbreviation |
Full Name |
ToKernel |
|---|---|---|
rad |
Radian |
1.0 |
deg |
Degree |
PI / 180 |
grad |
Grad |
PI / 200 |
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"); |
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.
For example, to convert meters to feet you can use either the static definition of feet as follows:
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:
toKernel() method converts from the unit to the kernel unit.
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 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.
| Copyright © 1987-2007 ILOG S.A. All rights reserved. Documentation homepage. Legal terms. | PREVIOUS NEXT |