public final class Units extends Static
Unit
instances, and some constants in addition to the
SI
and NonSI
ones.Defined in the sis-utility
module
Modifier and Type | Field and Description |
---|---|
static Unit<Duration> |
MILLISECOND
Unit for milliseconds.
|
static Unit<Dimensionless> |
PPM
Parts per million.
|
Modifier and Type | Method and Description |
---|---|
static double |
derivative(UnitConverter converter,
double value)
Returns an estimation of the derivative of the given converter at the given value.
|
static Unit<Angle> |
ensureAngular(Unit<?> unit)
Makes sure that the specified unit is either null or an angular unit.
|
static Unit<Length> |
ensureLinear(Unit<?> unit)
Makes sure that the specified unit is either null or a linear unit.
|
static Unit<Dimensionless> |
ensureScale(Unit<?> unit)
Makes sure that the specified unit is either null or a scale unit.
|
static Unit<Duration> |
ensureTemporal(Unit<?> unit)
Makes sure that the specified unit is either null or a temporal unit.
|
static Integer |
getEpsgCode(Unit<?> unit,
boolean inAxis)
Returns the EPSG code of the given units, or
null if unknown. |
static boolean |
isAngular(Unit<?> unit)
Returns
true if the given unit is a linear unit. |
static boolean |
isLinear(Unit<?> unit)
Returns
true if the given unit is a linear unit. |
static boolean |
isPressure(Unit<?> unit)
Returns
true if the given unit is a pressure unit. |
static boolean |
isScale(Unit<?> unit)
Returns
true if the given unit is a dimensionless scale unit. |
static boolean |
isTemporal(Unit<?> unit)
Returns
true if the given unit is a temporal unit. |
static <A extends Quantity> |
multiply(Unit<A> unit,
double factor)
Multiplies the given unit by the given factor.
|
static <A extends Quantity> |
toStandardUnit(Unit<A> unit)
Returns the factor by which to multiply the standard unit in order to get the given unit.
|
static Unit<?> |
valueOf(String uom)
Parses the given symbol.
|
static Unit<?> |
valueOfEPSG(int code)
Returns a hard-coded unit from an EPSG code.
|
public static final Unit<Duration> MILLISECOND
Date
objects.public static final Unit<Dimensionless> PPM
This unit does not have an easily readable symbol because of the JSR-275 bug.
public static boolean isAngular(Unit<?> unit)
true
if the given unit is a linear unit.
Linear units are convertible to NonSI.DEGREE_ANGLE
.
Angular units are dimensionless, which may be a cause of confusion with other
dimensionless units like Unit.ONE
or PPM
. This method take care
of differentiating angular units from other dimensionless units.
unit
- The unit to check (may be null
).true
if the given unit is non-null and angular.ensureAngular(Unit)
public static boolean isLinear(Unit<?> unit)
true
if the given unit is a linear unit.
Linear units are convertible to SI.METRE
.unit
- The unit to check (may be null
).true
if the given unit is non-null and linear.ensureLinear(Unit)
public static boolean isPressure(Unit<?> unit)
true
if the given unit is a pressure unit.
Pressure units are convertible to SI.PASCAL
.
Those units are sometime used instead of linear units for altitude measurements.unit
- The unit to check (may be null
).true
if the given unit is non-null and a pressure unit.public static boolean isTemporal(Unit<?> unit)
true
if the given unit is a temporal unit.
Temporal units are convertible to SI.SECOND
.unit
- The unit to check (may be null
).true
if the given unit is non-null and temporal.ensureTemporal(Unit)
public static boolean isScale(Unit<?> unit)
unit
- The unit to check (may be null
).true
if the given unit is non-null and a dimensionless scale.ensureScale(Unit)
public static Unit<Angle> ensureAngular(Unit<?> unit) throws IllegalArgumentException
unit
- The unit to check, or null
if none.unit
argument, which may be null.IllegalArgumentException
- if unit
is non-null and not an angular unit.isAngular(Unit)
public static Unit<Length> ensureLinear(Unit<?> unit) throws IllegalArgumentException
unit
- The unit to check, or null
if none.unit
argument, which may be null.IllegalArgumentException
- if unit
is non-null and not a linear unit.isLinear(Unit)
public static Unit<Duration> ensureTemporal(Unit<?> unit) throws IllegalArgumentException
unit
- The unit to check, or null
if none.unit
argument, which may be null.IllegalArgumentException
- if unit
is non-null and not a temporal unit.isTemporal(Unit)
public static Unit<Dimensionless> ensureScale(Unit<?> unit) throws IllegalArgumentException
unit
- The unit to check, or null
if none.unit
argument, which may be null.IllegalArgumentException
- if unit
is non-null and not a scale unit.isScale(Unit)
@Workaround(library="JSR-275", version="0.9.3") public static <A extends Quantity> Unit<A> multiply(Unit<A> unit, double factor)
SI.METRE
by 1000 gives SI.KILOMETRE
. Invoking this method is equivalent to invoking
Unit.times(double)
except for the following:
multiply(SI.RADIANS, 0.0174532925199...)
will return
NonSI.DEGREE_ANGLE
even if the given numerical value is slightly
different than pi/180. The tolerance factor and the
set of units handled especially may change in future SIS versions.A
- The quantity measured by the unit.unit
- The unit to multiply.factor
- The multiplication factor.@Workaround(library="JSR-275", version="0.9.3") public static <A extends Quantity> double toStandardUnit(Unit<A> unit)
Example: If the given unit is kilometre, then this method returns 1000 since a measurement in kilometres must be multiplied by 1000 in order to give the equivalent measurement in the "standard" units (here metres).
A
- The quantity measured by the unit.unit
- The unit for which we want the multiplication factor to standard unit.@Workaround(library="JSR-275", version="0.9.3") public static double derivative(UnitConverter converter, double value)
Current implementation computes the derivative as below:
The above is exact for linear converters, which is the case of the vast majority of unit converters in use. It may not be exact for a few unusual converter like the one from sexagesimal degrees to decimal degrees for example.return converter.convert(value + 1) - converter.convert(value);
converter
- The converter for which we want the derivative at a given point.value
- The point at which to compute the derivative.public static Unit<?> valueOf(String uom) throws IllegalArgumentException
Unit.valueOf(CharSequence)
, but
hands especially a few symbols found in WKT parsing or in XML files. The list of symbols
handled especially is implementation-dependent and may change in future SIS versions.
uom
arguments is of the form "EPSG:####"
or "urn:ogc:def:uom:EPSG:####"
(ignoring case and whitespaces), then "####"
is parsed as an integer and forwarded to the valueOfEPSG(int)
method.
"degrees_east"
or "degrees_north"
. This valueOf
method
ignores those suffixes and unconditionally returns NonSI.DEGREE_ANGLE
for all
axis directions. In particular, the units for "degrees_west"
and "degrees_east"
do not have opposite sign. It is caller responsibility to handle the
direction of axes associated to NetCDF units.uom
- The symbol to parse, or null
.null
if uom
was null.IllegalArgumentException
- if the given symbol can not be parsed.public static Unit<?> valueOfEPSG(int code)
code
argument given to this
method shall be a code identifying a record in the "Unit of Measure"
table of
the EPSG database. If this method does not recognize the given code, then it returns
null
.
The list of units recognized by this method is not exhaustive. This method recognizes
the base units declared in the TARGET_UOM_CODE
column of the above-cited table,
and some frequently-used units. The list of recognized units may be updated in any future
version of SIS.
The org.apache.sis.referencing.factory.epsg.DirectEpsgFactory
uses this method
for fetching the base units, and derives automatically other units from the information
found in the EPSG database. This method is also used by other classes not directly related
to the EPSG database, like org.apache.sis.referencing.factory.web.AutoCRSFactory
which uses EPSG code for identifying units.
The currently recognized values are:
Linear units | Angular units | Scale units | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
code
- The EPSG code for a unit of measurement.null
if the code is unrecognized.public static Integer getEpsgCode(Unit<?> unit, boolean inAxis)
null
if unknown.
This method is the converse of valueOfEPSG(int)
.
The same unit may be represented by different EPSG codes depending on the context:
inAxis
argument,
which specifies whether the code will be used for axis definition or in other context.unit
- The unit for which to get the EPSG code.inAxis
- true
for a unit used in Coordinate System Axis definition.null
if unknown.Copyright © 2010–2014 The Apache Software Foundation. All rights reserved.