@SuppressWarnings("unchecked")
    public double valueAt(ICollection iCollection, long thisTime, Unit<?> requiredUnits) {
      Measurable<Quantity> res;
      if (iCollection.isQuantity()) {
        IQuantityCollection<?> iQ = (IQuantityCollection<?>) iCollection;

        if (iCollection.isTemporal()) {
          TemporalQuantityCollection<?> tQ = (TemporalQuantityCollection<?>) iCollection;
          res = (Measurable<Quantity>) tQ.interpolateValue(thisTime, InterpMethod.Linear);
        } else {
          IQuantityCollection<?> qC = (IQuantityCollection<?>) iCollection;
          res = (Measurable<Quantity>) qC.getValues().iterator().next();
        }

        if (res != null) {
          UnitConverter converter = iQ.getUnits().getConverterTo(requiredUnits);
          Unit<?> sourceUnits = iQ.getUnits();
          double doubleValue = res.doubleValue((Unit<Quantity>) sourceUnits);
          double result = converter.convert(doubleValue);
          return result;
        } else {
          return 0;
        }
      } else {
        throw new RuntimeException("Tried to get value of non quantity data type");
      }
    }
 @Override
 public double doubleValue(final Unit<Q> unit) {
   final Double value = getValue();
   if (unit == this.unit || this.unit.equals(unit)) {
     return value;
   } else {
     final UnitConverter unitConverter = this.unit.getConverterTo(unit);
     return unitConverter.convert(value);
   }
 }
예제 #3
0
  /**
   * @param bufferWidth
   * @param bufferUnits
   * @param geometryUnits
   * @return the converted distance <code>bufferWidth</code> from <code>targetUnits</code> to <code>
   *     sourceUnits</code>
   */
  private double getBufferWidth(double bufferWidth, Unit sourceUnits, Unit targetUnits) {
    assert sourceUnits != null;
    assert targetUnits != null;

    double convertedWidth;
    if (GeoToolsUtils.PIXEL_UNITS.equals(targetUnits)) {

      IViewportModel viewportModel = this.sourceLayer.getMap().getViewportModel();
      Coordinate origin = viewportModel.pixelToWorld(0, 0);
      int fixedBufferWidth = (int) Math.round(bufferWidth);
      Coordinate originPlusWidth = viewportModel.pixelToWorld(fixedBufferWidth, fixedBufferWidth);
      convertedWidth = Math.abs(originPlusWidth.x - origin.x);
    } else {
      UnitConverter converter = targetUnits.getConverterTo(sourceUnits);
      convertedWidth = converter.convert(bufferWidth);
    }
    return convertedWidth;
  }
예제 #4
0
 public static <Q extends Quantity> Measure<Q> convert(
     Measure<Q> measure, UnitConverter converter) {
   BigDecimal converted = converter.convert(decimalValue(measure), MathUtils.context());
   return Measure.valueOf(converted, measure.getUnit());
 }