Search in sources :

Example 6 with RangeValue

use of org.n52.shetland.ogc.swe.RangeValue in project arctic-sea by 52North.

the class SweCommonDecoderV20 method parseAllowedTimes.

@SuppressWarnings("rawtypes")
private SweAllowedTimes parseAllowedTimes(AllowedTimesType att) throws DateTimeParseException {
    SweAllowedTimes allowedTimes = new SweAllowedTimes();
    if (att.isSetId()) {
        allowedTimes.setGmlId(att.getId());
    }
    if (CollectionHelper.isNotNullOrEmpty(att.getValueArray())) {
        for (Object value : att.getValueArray()) {
            allowedTimes.addValue(DateTimeHelper.parseIsoString2DateTime(value.toString()));
        }
    }
    if (CollectionHelper.isNotNullOrEmpty(att.getIntervalArray())) {
        for (List interval : att.getIntervalArray()) {
            RangeValue<DateTime> rangeValue = new RangeValue<DateTime>();
            Iterator iterator = interval.iterator();
            if (iterator.hasNext()) {
                rangeValue.setRangeStart(DateTimeHelper.parseIsoString2DateTime(iterator.next().toString()));
            }
            if (iterator.hasNext()) {
                rangeValue.setRangeEnd(DateTimeHelper.parseIsoString2DateTime(iterator.next().toString()));
            }
            allowedTimes.addInterval(rangeValue);
        }
    }
    if (att.isSetSignificantFigures()) {
        allowedTimes.setSignificantFigures(att.getSignificantFigures());
    }
    return allowedTimes;
}
Also used : Iterator(java.util.Iterator) XmlObject(org.apache.xmlbeans.XmlObject) List(java.util.List) ArrayList(java.util.ArrayList) SweAllowedTimes(org.n52.shetland.ogc.swe.simpleType.SweAllowedTimes) DateTime(org.joda.time.DateTime) RangeValue(org.n52.shetland.ogc.swe.RangeValue)

Example 7 with RangeValue

use of org.n52.shetland.ogc.swe.RangeValue in project arctic-sea by 52North.

the class SweCommonEncoderv101Test method should_encode_Datarecord_with_fieldTimeRange.

@Test
public void should_encode_Datarecord_with_fieldTimeRange() throws EncodingException {
    final String field1Name = "test-name";
    final RangeValue<DateTime> field1Value = new RangeValue<DateTime>();
    final long now = System.currentTimeMillis();
    final DateTime rangeStart = new DateTime(now - 1000);
    final DateTime rangeEnd = new DateTime(now + 1000);
    field1Value.setRangeStart(rangeStart);
    field1Value.setRangeEnd(rangeEnd);
    final XmlObject encode = sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField(field1Name, new SweTimeRange().setValue(field1Value))));
    assertThat(encode, is(instanceOf(DataRecordType.class)));
    final DataRecordType xbDataRecord = (DataRecordType) encode;
    assertThat(xbDataRecord.getFieldArray().length, is(1));
    final DataComponentPropertyType field1 = xbDataRecord.getFieldArray(0);
    assertThat(field1.isSetTimeRange(), is(TRUE));
    final DateTime xbTimeRangeStart = new DateTime(((XmlCalendar) field1.getTimeRange().getValue().get(0)).getTimeInMillis());
    final DateTime xbTimeRangeEnd = new DateTime(((XmlCalendar) field1.getTimeRange().getValue().get(1)).getTimeInMillis());
    assertThat(field1.getName(), is(field1Name));
    assertThat(xbTimeRangeStart, is(field1Value.getRangeStart()));
    assertThat(xbTimeRangeEnd, is(field1Value.getRangeEnd()));
}
Also used : SimpleDataRecordType(net.opengis.swe.x101.SimpleDataRecordType) DataRecordType(net.opengis.swe.x101.DataRecordType) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) XmlObject(org.apache.xmlbeans.XmlObject) DataComponentPropertyType(net.opengis.swe.x101.DataComponentPropertyType) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) DateTime(org.joda.time.DateTime) RangeValue(org.n52.shetland.ogc.swe.RangeValue) Test(org.junit.Test)

Example 8 with RangeValue

use of org.n52.shetland.ogc.swe.RangeValue in project arctic-sea by 52North.

the class SweCommonDecoderV101Test method should_decode_Category_with_Quality_QuantityRange.

@Test
public void should_decode_Category_with_Quality_QuantityRange() throws DecodingException {
    final CategoryDocument xbQuantity = CategoryDocument.Factory.newInstance();
    final BigDecimal rangeStart = BigDecimal.valueOf(1.0);
    final BigDecimal rangeEnd = BigDecimal.valueOf(2.0);
    final ArrayList<BigDecimal> categoryValue = Lists.newArrayList(rangeStart, rangeEnd);
    xbQuantity.addNewCategory().addNewQuality().addNewQuantityRange().setValue(categoryValue);
    final Object decodedObject = new SweCommonDecoderV101().decode(xbQuantity);
    assertThat(decodedObject, is(instanceOf(SweCategory.class)));
    final SweCategory sweCategory = (SweCategory) decodedObject;
    assertThat(sweCategory.isSetQuality(), is(true));
    assertThat(sweCategory.getQuality().size(), is(1));
    assertThat(sweCategory.getQuality().iterator().next(), is(instanceOf(SweQuantityRange.class)));
    assertThat(((SweQuantityRange) sweCategory.getQuality().iterator().next()).getValue(), is(new RangeValue<BigDecimal>(rangeStart, rangeEnd)));
}
Also used : CategoryDocument(net.opengis.swe.x101.CategoryDocument) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) BigDecimal(java.math.BigDecimal) RangeValue(org.n52.shetland.ogc.swe.RangeValue) Test(org.junit.Test)

Example 9 with RangeValue

use of org.n52.shetland.ogc.swe.RangeValue in project arctic-sea by 52North.

the class FieldDecoder method decodeCountRange.

protected SweAbstractDataComponent decodeCountRange(JsonNode node) {
    SweCountRange swe = new SweCountRange();
    if (node.hasNonNull(JSONConstants.VALUE)) {
        int start = node.path(JSONConstants.VALUE).path(0).intValue();
        int end = node.path(JSONConstants.VALUE).path(1).intValue();
        swe.setValue(new RangeValue<Integer>(start, end));
    }
    return swe;
}
Also used : SweCountRange(org.n52.shetland.ogc.swe.simpleType.SweCountRange)

Example 10 with RangeValue

use of org.n52.shetland.ogc.swe.RangeValue in project arctic-sea by 52North.

the class SweCommonDecoderV101 method parseCountRange.

private SweCountRange parseCountRange(CountRange xbCountRange) throws DecodingException {
    SweCountRange sosCountRange = new SweCountRange();
    // }
    if (xbCountRange.getQualityArray() != null) {
        sosCountRange.setQuality(parseQuality(xbCountRange.getQualityArray()));
    }
    // }
    if (xbCountRange.isSetDefinition()) {
        sosCountRange.setDefinition(xbCountRange.getDefinition());
    }
    if (xbCountRange.isSetDescription()) {
        sosCountRange.setDescription(xbCountRange.getDescription().getStringValue());
    }
    if (xbCountRange.isSetValue()) {
        List<?> value = xbCountRange.getValue();
        Integer rangeStart = Integer.parseInt(value.get(0).toString());
        Integer rangeEnd = Integer.parseInt(value.get(1).toString());
        sosCountRange.setValue(new RangeValue<>(rangeStart, rangeEnd));
    }
    return sosCountRange;
}
Also used : SweCountRange(org.n52.shetland.ogc.swe.simpleType.SweCountRange)

Aggregations

RangeValue (org.n52.shetland.ogc.swe.RangeValue)10 XmlObject (org.apache.xmlbeans.XmlObject)6 DateTime (org.joda.time.DateTime)6 BigDecimal (java.math.BigDecimal)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)4 Test (org.junit.Test)3 SweQuantityRange (org.n52.shetland.ogc.swe.simpleType.SweQuantityRange)3 Iterator (java.util.Iterator)2 SweAllowedTimes (org.n52.shetland.ogc.swe.simpleType.SweAllowedTimes)2 SweAllowedValues (org.n52.shetland.ogc.swe.simpleType.SweAllowedValues)2 SweCountRange (org.n52.shetland.ogc.swe.simpleType.SweCountRange)2 DirectPositionListType (net.opengis.gml.x32.DirectPositionListType)1 LineStringDocument (net.opengis.gml.x32.LineStringDocument)1 LineStringType (net.opengis.gml.x32.LineStringType)1 SimpleMultiPointDocument (net.opengis.gml.x33.ce.SimpleMultiPointDocument)1 SimpleMultiPointType (net.opengis.gml.x33.ce.SimpleMultiPointType)1 CategoryDocument (net.opengis.swe.x101.CategoryDocument)1 Count (net.opengis.swe.x101.CountDocument.Count)1