Package javax.measure.converter

Examples of javax.measure.converter.UnitConverter


        final int expectedID = getUnitMessageID(targetUnit);
        if (getUnitMessageID(unit) != expectedID) {
            throw new IllegalArgumentException(Errors.format(expectedID, unit));
        }
        final double[] converted = values.clone();
        final UnitConverter converter = unit.getConverterTo(targetUnit);
        for (int i=0; i<converted.length; i++) {
            converted[i] = converter.convert(converted[i]);
        }
        this.value = ensureValidValue(descriptor, converted);
        this.unit  = unit;
    }
View Full Code Here


            FeatureCollection results = FeatureCollections.newCollection();
            FeatureType targetFeatureType = createTargetFeatureType(featureCollection.getSchema());
            Unit fromUnit = SI.METER;
            Unit toUnit = Unit.valueOf("mi");
            UnitConverter unitConvert = fromUnit.getConverterTo(toUnit);
            Feature nearestFeature = null;
            double nearestDistance = 9e9;
            double nearestBearing = 0;
            Iterator featureIterator = null;
            double[] nearestPoint = new double[2];
            try {
                featureIterator = featureCollection.iterator();
                while (featureIterator.hasNext()) {
                    SimpleFeature f = (SimpleFeature) featureIterator.next();
                    if (f.getDefaultGeometryProperty().getValue() == null)
                        continue;
                    DistanceOp op = new DistanceOp(point, (Geometry) f.getDefaultGeometryProperty()
                            .getValue());
                    Coordinate[] co = op.closestPoints();
                    double[] co0 = new double[] { co[0].x, co[0].y, };
                    double[] co1 = new double[] { co[1].x, co[1].y, };
                    double[] geo0 = new double[2];
                    double[] geo1 = new double[2];
                    crsTransform.transform(co0, 0, geo0, 0, 1);
                    crsTransform.transform(co1, 0, geo1, 0, 1);

                    // get distance
                    Measure m = DefaultGeographicCRS.WGS84.distance(geo0, geo1);
                    if (m.doubleValue() > nearestDistance)
                        continue;
                    nearestFeature = f;
                    nearestDistance = m.doubleValue();
                    nearestBearing = calcBearing(co);
                    nearestPoint[0] = geo1[0];
                    nearestPoint[1] = geo1[1];
                }
            } finally {
                if (featureIterator != null)
                    featureCollection.close(featureIterator);
            }
            if (nearestFeature != null) {
                nearestDistance = unitConvert.convert(nearestDistance);
                results.add(createTargetFeature(nearestFeature,
                        (SimpleFeatureType) targetFeatureType, nearestPoint, nearestDistance,
                        nearestBearing));
            }
            return results;
View Full Code Here

            FeatureCollection results = FeatureCollections.newCollection();
            FeatureType targetFeatureType = createTargetFeatureType(featureCollection.getSchema());
            Unit fromUnit = SI.METER;
            Unit toUnit = Unit.valueOf("mi");
            UnitConverter unitConvert = fromUnit.getConverterTo(toUnit);
            Feature nearestFeature = null;
            double nearestDistance = 9e9;
            double nearestBearing = 0;
            Iterator featureIterator = null;
            try {
                featureIterator = featureCollection.iterator();
                while (featureIterator.hasNext()) {
                    SimpleFeature f = (SimpleFeature) featureIterator.next();
                    if (f.getDefaultGeometryProperty().getValue() == null)
                        continue;
                    DistanceOp op = new DistanceOp(point, (Geometry) f.getDefaultGeometryProperty()
                            .getValue());
                    Coordinate[] co = op.closestPoints();
                    double[] co0 = new double[] { co[0].x, co[0].y, };
                    double[] co1 = new double[] { co[1].x, co[1].y, };
                    double[] geo0 = new double[2];
                    double[] geo1 = new double[2];
                    crsTransform.transform(co0, 0, geo0, 0, 1);
                    crsTransform.transform(co1, 0, geo1, 0, 1);

                    // get distance
                    Measure m = DefaultGeographicCRS.WGS84.distance(geo0, geo1);
                    if (m.doubleValue() > nearestDistance)
                        continue;
                    nearestFeature = f;
                    nearestDistance = m.doubleValue();
                    nearestBearing = calcBearing(co);
                }
            } finally {
                if (featureIterator != null)
                    featureCollection.close(featureIterator);
            }
            if (nearestFeature != null) {
                nearestDistance = unitConvert.convert(nearestDistance);
                results.add(createTargetFeature(nearestFeature,
                        (SimpleFeatureType) targetFeatureType, nearestDistance, nearestBearing));
            }
            return results;
        } catch (WPSException e) {
View Full Code Here

            CoordinateReferenceSystem hor = CRS.getHorizontalCRS(crs);
            if (hor instanceof GeographicCRS) {
                generator = new GeographicGenerator(center, quadrantSegments, crs);
            } else {
                Unit unit = hor.getCoordinateSystem().getAxis(0).getUnit();
                UnitConverter converter = SI.METER.getConverterTo(unit);
                generator = new MetricGenerator(center, quadrantSegments, converter);
            }
        } else {
            generator = new MetricGenerator(center, quadrantSegments, UnitConverter.IDENTITY);
        }
View Full Code Here

   
    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);
      return converter.convert(mt.doubleValue());
    } else {
      return mt.doubleValue();
    }
   
  }
View Full Code Here

        } else {
            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

    addIntegerComponent(t.getMinute());
  }
 
  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

             * If it's not hour, minute, or second, then it's
             *   smaller than second. Convert to nearest
             *  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

Related Classes of javax.measure.converter.UnitConverter

Copyright © 2018 www.massapicom. 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.