Package javax.measure.converter

Examples of javax.measure.converter.UnitConverter.convert()


    if((targetUnit != null && targetUnit == NonSI.DEGREE_ANGLE) || horizontalCRS instanceof GeographicCRS || crs instanceof GeographicCRS) {
      // assume we're working against a type of geographic crs, must estimate the degrees equivalent
      // to the measure, we are going to use a very rough estimate (cylindrical earth model)
      // TODO: maybe look at the layer bbox and get a better estimate computed at the center of the bbox
      UnitConverter converter = mt.getUnit().getConverterTo(SI.METER);
      double tolMeters = converter.convert(mt.doubleValue());
      return tolMeters * OGC_METERS_TO_DEGREES;
    } else if(targetUnit != null && targetUnit.isCompatible(SI.METER)) {
      // ok, we assume the target is not a geographic one, but we might
      // have to convert between meters and feet maybe
      UnitConverter converter = mt.getUnit().getConverterTo(targetUnit);
View Full Code Here


      return tolMeters * OGC_METERS_TO_DEGREES;
    } else if(targetUnit != null && targetUnit.isCompatible(SI.METER)) {
      // ok, we assume the target is not a geographic one, but we might
      // have to convert between meters and feet maybe
      UnitConverter converter = mt.getUnit().getConverterTo(targetUnit);
      return converter.convert(mt.doubleValue());
    } else {
      return mt.doubleValue();
    }
   
  }
View Full Code Here

            Unit<? extends Quantity> metre = Unit.valueOf("m");
            try {
                meters = unit.getConverterTo(metre).convert(1);
            } catch (Exception e) {
                UnitConverter converter = unit.getConverterTo(degree);
                double toDegree = converter.convert(1);
                meters = toDegree * GridSetFactory.EPSG4326_TO_METERS;
            }
        }
        return meters;
    }
View Full Code Here

 
  protected void setUnitAndSubsecond(Unit<Duration> u, int subSec) {
    this.u = u;
    if (!u.equals(TimeUnit.SECOND)) {
      UnitConverter uc = u.getConverterTo(TimeUnit.SECOND);
      double convert = uc.convert(1D);
      double check = subSec * convert;
      if (check < 1) {
        this.subSecond = subSec;
      } else {
        throw new IllegalArgumentException("Units and value must " +
View Full Code Here

  }
 
  protected void addSubsecond(Iso8601UnitTime tu) {
    Unit<Duration> u = tu.getUnit();
    UnitConverter uc = TimeUnit.SECOND.getConverterTo(u);
    double conv = uc.convert(1D);
    int pow10 = (int)(Math.log10(conv));
    BigDecimal bd = BigDecimal.valueOf((long)tu.getSubsecond(), pow10);
    formattedTime.append(bd.toPlainString().substring(1));
  }
View Full Code Here

             *  millisecond.
             */
            if (!u.getUnit().equals(TimeUnit.SECOND)) {
              UnitConverter tc = u.getUnit().getConverterTo(
                  TimeUnit.MILLISECOND);
              double d = tc.convert(u.getSubsecond());
              int milli = (int)Math.floor(d);
              c.set(Calendar.MILLISECOND, milli);
            }
          }
        }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.