Class Units


  • public final class Units
    extends Object
    A set of units to use in addition of SI and NonSI.
    Since:
    2.1
    Author:
    Martin Desruisseaux (IRD)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Unit<Time> DAY
      Helper definition so someone can align to GeoTools Day Unit type *
      static Unit<Angle> DEGREE_ANGLE  
      static Unit<Angle> DEGREE_MINUTE_SECOND
      Pseudo-unit for degree - minute - second.
      static Unit<Length> FOOT  
      static Unit<Angle> GRADE  
      static Unit<Length> KILOMETER  
      static Unit<Length> METRE  
      static Unit<Angle> MICRORADIAN  
      static Unit<Angle> MINUTE_ANGLE  
      static Unit<Time> MONTH
      Time duration of 1/12 of a Units.YEAR.
      static Unit<Length> NAUTICAL_MILE  
      static Unit<Dimensionless> ONE  
      static Unit<Length> PIXEL
      Length of 1/72 of a USCustomary.INCH
      static Unit<Dimensionless> PPM
      Parts per million.
      static Unit<Angle> RADIAN  
      static Unit<Angle> SECOND_ANGLE  
      static Unit<Angle> SEXAGESIMAL_DMS
      Pseudo-unit for sexagesimal degree.
      static Unit<Time> YEAR  
    • Field Detail

      • DEGREE_ANGLE

        public static final Unit<Angle> DEGREE_ANGLE
      • DEGREE_MINUTE_SECOND

        public static final Unit<Angle> DEGREE_MINUTE_SECOND
        Pseudo-unit for degree - minute - second. Numbers in this pseudo-unit has the following format:

        signed degrees (integer) - arc-minutes (integer) - arc-seconds (real, any precision).

        This unit is non-linear and not practical for computation. Consequently, it should be avoid as much as possible. Unfortunately, this pseudo-unit is extensively used in the EPSG database (code 9107).

      • GRADE

        public static final Unit<Angle> GRADE
      • MICRORADIAN

        public static final Unit<Angle> MICRORADIAN
      • MINUTE_ANGLE

        public static final Unit<Angle> MINUTE_ANGLE
      • RADIAN

        public static final Unit<Angle> RADIAN
      • SEXAGESIMAL_DMS

        public static final Unit<Angle> SEXAGESIMAL_DMS
        Pseudo-unit for sexagesimal degree. Numbers in this pseudo-unit has the following format:

        sign - degrees - decimal point - minutes (two digits) - integer seconds (two digits) - fraction of seconds (any precision).

        This unit is non-linear and not pratical for computation. Consequently, it should be avoid as much as possible. Unfortunatly, this pseudo-unit is extensively used in the EPSG database (code 9110).

      • SECOND_ANGLE

        public static final Unit<Angle> SECOND_ANGLE
      • PPM

        public static final Unit<Dimensionless> PPM
        Parts per million.
      • ONE

        public static final Unit<Dimensionless> ONE
      • FOOT

        public static final Unit<Length> FOOT
      • METRE

        public static final Unit<Length> METRE
      • KILOMETER

        public static final Unit<Length> KILOMETER
      • NAUTICAL_MILE

        public static final Unit<Length> NAUTICAL_MILE
      • PIXEL

        public static final Unit<Length> PIXEL
        Length of 1/72 of a USCustomary.INCH
      • DAY

        public static final Unit<Time> DAY
        Helper definition so someone can align to GeoTools Day Unit type *
      • MONTH

        public static final Unit<Time> MONTH
        Time duration of 1/12 of a Units.YEAR.
      • YEAR

        public static final Unit<Time> YEAR
    • Method Detail

      • getDefaultFormat

        public static UnitFormatter getDefaultFormat()
        Gets an instance of the default system-wide Unit format. Use this method instead of SimpleUnitFormat.getInstance(), since custom Geotools units are not known to SimpleUnitFormat.getInstance().
        See Also:
        UnitFormat.getInstance()
      • toName

        public static String toName​(Unit<?> unit)
        Unit name, willing to use UnitFormat to look up appropriate label if a name has not been not defined.

        This allows us to format units like PIXEL.

      • toSymbol

        public static String toSymbol​(Unit<?> unit)
        Unit symbol, willing to use UnitFormat to look up appropriate label if required.

        This allows us to format units like PIXEL.

      • autoCorrect

        public static <Q extends Quantity<Q>> Unit<Q> autoCorrect​(Unit<Q> unit)
        Returns an equivalent unit instance based on the provided unit. First, it tries to get one of the reference units defined in the JSR 385 implementation in use. Units are considered equivalent if the equals(Unit, Unit) method returns true. If no equivalent reference unit is defined, it returns the provided unit.
      • equals

        public static final boolean equals​(Unit<?> unit1,
                                           Unit<?> unit2)
        Checks whether two units can be considered equivalent. TransformedUnits are considered equivalent if they have the same system unit and their conversion factors to the system unit produce the identity converter when the inverse of the second factor is concatenated with the first factor, considering the precision of a float number. For other types of units, the comparison is delegated to their normal equals method.
      • getConverterToAny

        public static UnitConverter getConverterToAny​(Unit<?> fromUnit,
                                                      Unit<?> toUnit)
        Gets a UnitConverter between two units, wrapping any raised exception in a IllegalArgumentException.
        Throws:
        IllegalArgumentException - if unit1 can't be converter to unit2