tec.uom.se.unit.Units Java Examples
The following examples show how to use
tec.uom.se.unit.Units.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeometryUtils.java From geowave with Apache License 2.0 | 6 votes |
/** * Build a buffer around a geometry * * @param crs * @param geometry * @param distanceUnits * @param distance * @return the buffered geometry and the degrees that it was buffered * @throws TransformException */ public static final Pair<Geometry, Double> buffer( final CoordinateReferenceSystem crs, final Geometry geometry, final String distanceUnits, final double distance) throws TransformException { Unit<Length> unit; try { unit = lookup(distanceUnits); } catch (final Exception e) { unit = Units.METRE; LOGGER.warn("Cannot lookup unit of measure " + distanceUnits, e); } final double meterDistance = unit.getConverterTo(Units.METRE).convert(distance); final double degrees = distanceToDegrees(crs, geometry, meterDistance); // buffer does not respect the CRS; it uses simple cartesian math. // nor does buffer handle dateline boundaries return Pair.of(adjustGeo(crs, geometry.buffer(degrees)), degrees); }
Example #2
Source File: QuantityTypeTest.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testDataTransferRate() { QuantityType<DataTransferRate> speed = new QuantityType<>("1024 bit/s"); QuantityType<DataTransferRate> octet = speed.toUnit(SmartHomeUnits.OCTET.divide(Units.SECOND)); assertEquals(128, octet.intValue()); QuantityType<DataTransferRate> gsm2G = new QuantityType<>("115 Mbit/s"); QuantityType<DataTransferRate> octets = gsm2G .toUnit(MetricPrefix.KILO(SmartHomeUnits.OCTET).divide(Units.SECOND)); assertEquals(14375, octets.intValue()); }
Example #3
Source File: QuantityTypeArithmeticGroupFunctionTest.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@Before public void init() { initMocks(this); items = new LinkedHashSet<>(); when(unitProvider.getUnit(Temperature.class)).thenReturn(Units.CELSIUS); }
Example #4
Source File: SmartHomeUnitsTest.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testDobsonUnits() { // https://en.wikipedia.org/wiki/Dobson_unit QuantityType<ArealDensity> oneDU = new QuantityType<>("1 DU"); QuantityType<ArealDensity> mmolpsq = oneDU.toUnit(MetricPrefix.MILLI(Units.MOLE).multiply(Units.METRE.pow(-2))); assertThat(mmolpsq.doubleValue(), is(closeTo(0.4462d, DEFAULT_ERROR))); assertThat(mmolpsq.toUnit(SmartHomeUnits.DOBSON_UNIT).doubleValue(), is(closeTo(1, DEFAULT_ERROR))); }
Example #5
Source File: GroupItemOSGiTest.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@SuppressWarnings("null") @Test public void assertThatNumberGroupItemWithDimensionCalculatesCorrectState() { NumberItem baseItem = createNumberItem("baseItem", Temperature.class, UnDefType.NULL); GroupFunctionDTO gfDTO = new GroupFunctionDTO(); gfDTO.name = "sum"; GroupFunction function = groupFunctionHelper.createGroupFunction(gfDTO, Collections.emptyList(), Temperature.class); GroupItem groupItem = new GroupItem("number", baseItem, function); groupItem.setUnitProvider(unitProvider); NumberItem celsius = createNumberItem("C", Temperature.class, new QuantityType<>("23 °C")); groupItem.addMember(celsius); NumberItem fahrenheit = createNumberItem("F", Temperature.class, new QuantityType<>("23 °F")); groupItem.addMember(fahrenheit); NumberItem kelvin = createNumberItem("K", Temperature.class, new QuantityType<>("23 K")); groupItem.addMember(kelvin); QuantityType<?> state = groupItem.getStateAs(QuantityType.class); assertThat(state.getUnit(), is(Units.CELSIUS)); assertThat(state.doubleValue(), is(-232.15d)); celsius.setState(new QuantityType<>("265 °C")); state = groupItem.getStateAs(QuantityType.class); assertThat(state.getUnit(), is(Units.CELSIUS)); assertThat(state.doubleValue(), is(9.85d)); }
Example #6
Source File: SmartHomeUnitsTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void testDobsonUnits() { // https://en.wikipedia.org/wiki/Dobson_unit QuantityType<ArealDensity> oneDU = new QuantityType<ArealDensity>("1 DU"); QuantityType<ArealDensity> mmolpsq = oneDU.toUnit(MetricPrefix.MILLI(Units.MOLE).multiply(Units.METRE.pow(-2))); assertThat(mmolpsq.doubleValue(), is(closeTo(0.4462d, DEFAULT_ERROR))); assertThat(mmolpsq.toUnit(SmartHomeUnits.DOBSON_UNIT).doubleValue(), is(closeTo(1, DEFAULT_ERROR))); }
Example #7
Source File: GroupItemTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@SuppressWarnings("null") @Test public void assertThatNumberGroupItemWithDimensionCalculatesCorrectState() { NumberItem baseItem = createNumberItem("baseItem", Temperature.class, UnDefType.NULL); GroupFunctionDTO gfDTO = new GroupFunctionDTO(); gfDTO.name = "sum"; GroupFunction function = groupFunctionHelper.createGroupFunction(gfDTO, Collections.emptyList(), Temperature.class); GroupItem groupItem = new GroupItem("number", baseItem, function); groupItem.setUnitProvider(unitProvider); NumberItem celsius = createNumberItem("C", Temperature.class, new QuantityType<Temperature>("23 °C")); groupItem.addMember(celsius); NumberItem fahrenheit = createNumberItem("F", Temperature.class, new QuantityType<Temperature>("23 °F")); groupItem.addMember(fahrenheit); NumberItem kelvin = createNumberItem("K", Temperature.class, new QuantityType<Temperature>("23 K")); groupItem.addMember(kelvin); QuantityType<?> state = (QuantityType<?>) groupItem.getStateAs(QuantityType.class); assertThat(state.getUnit(), is(Units.CELSIUS)); assertThat(state.doubleValue(), is(-232.15d)); celsius.setState(new QuantityType<Temperature>("265 °C")); state = (QuantityType<?>) groupItem.getStateAs(QuantityType.class); assertThat(state.getUnit(), is(Units.CELSIUS)); assertThat(state.doubleValue(), is(9.85d)); }
Example #8
Source File: QuantityTypeArithmeticGroupFunctionTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Before public void init() { initMocks(this); items = new LinkedHashSet<>(); when(unitProvider.getUnit(Temperature.class)).thenReturn(Units.CELSIUS); }
Example #9
Source File: GeometryCalculations.java From geowave with Apache License 2.0 | 5 votes |
/** * Build geometries with the provided coordinate at the center. The width of the geometry is twice * the distance provided. More than one geometry is return when passing the date line. * * @param distances [x,y] = [longitude, latitude] * @param unit * @param coordinate * @return the geometries that were built */ public List<Geometry> buildSurroundingGeometries( final double[] distances, final Unit<Length> unit, final Coordinate coordinate) { final List<Geometry> geos = new LinkedList<>(); final GeodeticCalculator geoCalc = new GeodeticCalculator(); geoCalc.setStartingGeographicPoint(coordinate.x, coordinate.y); try { geoCalc.setDirection(0, unit.getConverterTo(Units.METRE).convert(distances[1])); final DirectPosition north = geoCalc.getDestinationPosition(); geoCalc.setDirection(90, unit.getConverterTo(Units.METRE).convert(distances[0])); final DirectPosition east = geoCalc.getDestinationPosition(); geoCalc.setStartingGeographicPoint(coordinate.x, coordinate.y); geoCalc.setDirection(-90, unit.getConverterTo(Units.METRE).convert(distances[0])); final DirectPosition west = geoCalc.getDestinationPosition(); geoCalc.setDirection(180, unit.getConverterTo(Units.METRE).convert(distances[1])); final DirectPosition south = geoCalc.getDestinationPosition(); final double x1 = west.getOrdinate(0); final double x2 = east.getOrdinate(0); final double y1 = north.getOrdinate(1); final double y2 = south.getOrdinate(1); handleBoundaries(geos, coordinate, x1, x2, y1, y2); return geos; } catch (final TransformException ex) { LOGGER.error("Unable to build geometry", ex); } return null; }
Example #10
Source File: OrthodromicDistancePartitioner.java From geowave with Apache License 2.0 | 5 votes |
private List<Geometry> getGeometries( final Coordinate coordinate, final double[] distancePerDimension) { return getCalculator().buildSurroundingGeometries( new double[] { distancePerDimension[longDimensionPosition], distancePerDimension[latDimensionPosition]}, geometricDistanceUnit == null ? Units.METRE : geometricDistanceUnit, coordinate); }
Example #11
Source File: GeometryUtils.java From geowave with Apache License 2.0 | 5 votes |
public static Unit<Length> lookup(final String name) { final String lowerCaseName = name.toLowerCase(); Unit<Length> unit = lookup(SI.class, lowerCaseName); if (unit != null) { return unit; } unit = lookup(NonSI.class, lowerCaseName); if (unit != null) { return unit; } if (lowerCaseName.endsWith("s")) { return lookup(lowerCaseName.substring(0, lowerCaseName.length() - 1)); } if (lowerCaseName.startsWith("kilo") && (lowerCaseName.length() > 4)) { final Unit<Length> u = lookup(lowerCaseName.substring(4)); if (u != null) { return u.multiply(1000); } } // if we get here, try some aliases if (lowerCaseName.equals("feet")) { return USCustomary.FOOT; } // if we get here, try some aliases if (lowerCaseName.equals("meter")) { return Units.METRE; } if (lowerCaseName.equals("unity")) { return (Unit) AbstractUnit.ONE; } return null; }
Example #12
Source File: SmartHomeUnitsTest.java From openhab-core with Eclipse Public License 2.0 | 4 votes |
@Test public void testPpm() { QuantityType<Dimensionless> ppm = new QuantityType<>("500 ppm"); assertEquals("0.05 %", ppm.toUnit(Units.PERCENT).toString()); }
Example #13
Source File: SmartHomeUnitsTest.java From smarthome with Eclipse Public License 2.0 | 4 votes |
@Test public void testPpm() { QuantityType<Dimensionless> ppm = new QuantityType<>("500 ppm"); assertEquals("0.05 %", ppm.toUnit(Units.PERCENT).toString()); }
Example #14
Source File: RegionBoundsInputUI.java From snap-desktop with GNU General Public License v3.0 | 4 votes |
private JLabel createDegreeLabel() { return new JLabel(Units.DEGREE_ANGLE.toString()); }