javax.measure.unit.NonSI Java Examples

The following examples show how to use javax.measure.unit.NonSI. 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: MapTools.java    From rcrs-server with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
   Compute the size of one metre in latitude/longitude relative to a reference point.
   @param lat The latitude of the reference point.
   @param lon The longitude of the reference point.
   @return The size of one metre at the reference point.
*/
public static double sizeOf1Metre(double lat, double lon) {
    UTM centre = UTM.latLongToUtm(LatLong.valueOf(lat, lon, NonSI.DEGREE_ANGLE), ReferenceEllipsoid.WGS84);
    UTM offset = UTM.valueOf(centre.longitudeZone(), centre.latitudeZone(), centre.eastingValue(SI.METRE), centre.northingValue(SI.METRE) + 1, SI.METRE);
    LatLong result = UTM.utmToLatLong(offset, ReferenceEllipsoid.WGS84);
    return Math.abs(result.latitudeValue(NonSI.DEGREE_ANGLE) - lat);
}
 
Example #2
Source File: SeveralTimesConvertor.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
AmountWrapper getInternalAmount(String description) {
  Unit<?> unit = CategoryMapperUtil.findDurationUnit(description);
  if (unit != null && unit.isCompatible(STANDARD_PER_WEEK_UNIT)) {
    return AmountWrapper.create(
        Amount.rangeOf((double) 3, NonSI.DAY.inverse().getConverterTo(unit).convert(1) - 1, unit)
            .to(STANDARD_PER_WEEK_UNIT),
        false);
  }
  return null;
}
 
Example #3
Source File: CategoryMapperTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
void testConvertCategory() {
  AmountWrapper twicePerDayAmount = AmountWrapper.create(Amount.valueOf(2, NonSI.DAY.inverse()));
  AmountWrapper twicePerWeekAmount =
      AmountWrapper.create(Amount.valueOf(2, NonSI.WEEK.inverse()));

  assertEquals(valueOf(12.), categoryMapper.convert(twicePerDayAmount, twicePerWeekAmount));

  AmountWrapper twiceAtLeastPerWeek =
      AmountWrapper.create(Amount.rangeOf(2, 7, NonSI.WEEK.inverse()));
  AmountWrapper threeTimesPerWeek = AmountWrapper.create(Amount.valueOf(3, NonSI.WEEK.inverse()));

  assertEquals(valueOf(2.5), categoryMapper.convert(twiceAtLeastPerWeek, threeTimesPerWeek));
}
 
Example #4
Source File: CategoryMapperTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
void testIsAmountRanged() {
  Amount<? extends Quantity> rangeOf = Amount.rangeOf(2, 2.4, NonSI.DAY.inverse());
  assertTrue(CategoryMapperUtil.isAmountRanged(rangeOf));

  Amount<? extends Quantity> vauleOf = Amount.valueOf(2, NonSI.DAY.inverse());
  assertFalse(CategoryMapperUtil.isAmountRanged(vauleOf));
}
 
Example #5
Source File: CategoryMapperTest.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
void testGetMostGeneralUnit() {
  List<Unit<?>> units = new ArrayList<>();

  units.add(NonSI.DAY.inverse());
  units.add(NonSI.YEAR.inverse());
  units.add(NonSI.MONTH.inverse());

  Unit<?> unit = CategoryMapperUtil.getMostGeneralUnit(units);
  assertEquals(YEAR.inverse().toString(), unit.toString());
}
 
Example #6
Source File: LabelEngineLayerProperties.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void convert(List<Rule> labelRuleList, Rule rule, JsonElement json, int transparency)
{       
    if((json != null) && (rule != null) && (labelRuleList != null))
    {
        JsonObject jsonObj = json.getAsJsonObject();

        TextSymbolizer textSymbolizer = styleFactory.createTextSymbolizer();

        textSymbolizer.setUnitOfMeasure(NonSI.PIXEL);

        textSymbolizer.setLabel(extractExpression(jsonObj));
        JsonElement jsonElement = jsonObj.get(LabelEngineLayerPropertiesKey.SYMBOL);
        SymbolManager.getInstance().convertTextSymbols(textSymbolizer, transparency, jsonElement);

        // Yes, this really is round the wrong way
        double maxScale = extractDouble(jsonObj, LabelEngineLayerPropertiesKey.ANNOTATION_MINIMUM_SCALE);
        double minScale = extractDouble(jsonObj, LabelEngineLayerPropertiesKey.ANNOTATION_MAXIMUM_SCALE);
        
        if((minScale > 0.0) || (maxScale > 0.0))
        {
            Rule labelRule = styleFactory.createRule();

            labelRule.setName(extractString(jsonObj, LabelEngineLayerPropertiesKey.CLASS));
            if(minScale > 0.0)
            {
                labelRule.setMinScaleDenominator(minScale);
            }

            if(maxScale > 0.0)
            {
                labelRule.setMaxScaleDenominator(maxScale);
            }
            labelRule.symbolizers().add(textSymbolizer);
            
            labelRuleList.add(labelRule);
        }
        else
        {
            rule.symbolizers().add(textSymbolizer);
        }
    }
}