Search in sources :

Example 6 with Type

use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.

the class FieldDecoder method decodeJSON.

public SweField decodeJSON(JsonNode node) throws DecodingException {
    final String type = node.path(JSONConstants.TYPE).textValue();
    final SweAbstractDataComponent element;
    if (type.equals(JSONConstants.BOOLEAN_TYPE)) {
        element = decodeBoolean(node);
    } else if (type.equals(JSONConstants.COUNT_TYPE)) {
        element = decodeCount(node);
    } else if (type.equals(JSONConstants.COUNT_RANGE_TYPE)) {
        element = decodeCountRange(node);
    } else if (type.equals(JSONConstants.OBSERVABLE_PROPERTY_TYPE)) {
        element = decodeObservableProperty(node);
    } else if (type.equals(JSONConstants.QUALITY_TYPE)) {
        element = decodeQuality(node);
    } else if (type.equals(JSONConstants.TEXT_TYPE)) {
        element = decodeText(node);
    } else if (type.equals(JSONConstants.QUANTITY_TYPE)) {
        element = decodeQuantity(node);
    } else if (type.equals(JSONConstants.QUANTITY_RANGE_TYPE)) {
        element = decodeQuantityRange(node);
    } else if (type.equals(JSONConstants.TIME_TYPE)) {
        element = decodeTime(node);
    } else if (type.equals(JSONConstants.TIME_RANGE_TYPE)) {
        element = decodeTimeRange(node);
    } else if (type.equals(JSONConstants.CATEGORY_TYPE)) {
        element = decodeCategory(node);
    } else {
        throw new UnsupportedDecoderInputException(this, node);
    }
    final String name = node.path(JSONConstants.NAME).textValue();
    element.setDescription(node.path(JSONConstants.DESCRIPTION).textValue());
    element.setIdentifier(node.path(JSONConstants.IDENTIFIER).textValue());
    element.setDefinition(node.path(JSONConstants.DEFINITION).textValue());
    element.setLabel(node.path(JSONConstants.LABEL).textValue());
    return new SweField(name, element);
}
Also used : SweField(org.n52.shetland.ogc.swe.SweField) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) UnsupportedDecoderInputException(org.n52.svalbard.decode.exception.UnsupportedDecoderInputException)

Example 7 with Type

use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.

the class GeoJSONDecoder method decodeCRS.

protected GeometryFactory decodeCRS(JsonNode node, GeometryFactory factory) throws GeoJSONDecodingException {
    if (!node.path(JSONConstants.CRS).hasNonNull(JSONConstants.TYPE)) {
        throw new GeoJSONDecodingException("Missing CRS type");
    }
    String type = node.path(JSONConstants.CRS).path(JSONConstants.TYPE).textValue();
    JsonNode properties = node.path(JSONConstants.CRS).path(JSONConstants.PROPERTIES);
    switch(type) {
        case JSONConstants.NAME:
            return decodeNamedCRS(properties, factory);
        case JSONConstants.LINK:
            return decodeLinkedCRS(properties, factory);
        default:
            throw new GeoJSONDecodingException("Unknown CRS type: " + type);
    }
}
Also used : GeoJSONDecodingException(org.n52.svalbard.coding.json.GeoJSONDecodingException) JsonNode(com.fasterxml.jackson.databind.JsonNode) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString)

Example 8 with Type

use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.

the class UVFEncoder method encodeToUvf.

private File encodeToUvf(ObservationStream observationStream, File tempDir, MediaType contentType) throws IOException, EncodingException {
    List<OmObservation> mergeObservations = mergeTotoList(observationStream);
    String ending = getLineEnding(contentType);
    String filename = getFilename(mergeObservations);
    File uvfFile = new File(tempDir, filename);
    try (Writer fw = new OutputStreamWriter(new FileOutputStream(uvfFile), "UTF-8")) {
        for (OmObservation o : mergeObservations) {
            if (o.isSetValue() && !checkForSingleObservationValue(o.getValue()) && !checkForMultiObservationValue(o.getValue())) {
                String errorMessage = String.format("The resulting values are not of numeric type " + "which is only supported by this encoder '%s'.", this.getClass().getName());
                LOGGER.error(errorMessage);
                throw new EncodingException(errorMessage);
            }
            /*
                 * HEADER: Metadata
                 */
            writeFunktionInterpretation(fw, o, ending);
            writeIndex(fw, ending);
            writeMessGroesse(fw, o, ending);
            writeMessEinheit(fw, o, ending);
            writeMessStellennummer(fw, o, ending);
            writeMessStellenname(fw, o, ending);
            /*
                 * HEADER: Lines 1 - 4
                 */
            writeLine1(fw, ending);
            TimePeriod temporalBBox = getTemporalBBoxFromObservations(mergeObservations);
            writeLine2(fw, o, temporalBBox, ending);
            writeLine3(fw, o, ending);
            writeLine4(fw, temporalBBox, ending);
            /*
                 * Observation Data
                 */
            writeObservationValue(fw, o, ending);
        }
    }
    return uvfFile;
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) FileOutputStream(java.io.FileOutputStream) OmObservation(org.n52.shetland.ogc.om.OmObservation) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 9 with Type

use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.

the class CountObservationDecodingTest method testObservation.

@Test
public void testObservation() {
    assertThat(observation, is(notNullValue()));
    final String type = observation.getObservationConstellation().getObservationType();
    assertThat(type, is(equalTo(OmConstants.OBS_TYPE_COUNT_OBSERVATION)));
    final ObservationValue<?> value = observation.getValue();
    assertThat(value, is(instanceOf(SingleObservationValue.class)));
    assertThat(value.getPhenomenonTime(), is(instanceOf(TimeInstant.class)));
    TimeInstant pt = (TimeInstant) value.getPhenomenonTime();
    assertThat(pt.getValue(), is(equalTo(phenomenonTime)));
    assertThat(value.getValue(), is(instanceOf(CountValue.class)));
    CountValue v = (CountValue) value.getValue();
    assertThat(v.getValue(), is(1));
    assertThat(v.getUnit(), is(nullValue()));
}
Also used : CountValue(org.n52.shetland.ogc.om.values.CountValue) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) Test(org.junit.Test)

Example 10 with Type

use of org.n52.shetland.w3c.xlink.Type in project arctic-sea by 52North.

the class TruthObservationDecodingTest method testObservation.

@Test
public void testObservation() {
    assertThat(observation, is(notNullValue()));
    final String type = observation.getObservationConstellation().getObservationType();
    assertThat(type, is(equalTo(OmConstants.OBS_TYPE_TRUTH_OBSERVATION)));
    final ObservationValue<?> value = observation.getValue();
    assertThat(value, is(instanceOf(SingleObservationValue.class)));
    assertThat(value.getPhenomenonTime(), is(instanceOf(TimeInstant.class)));
    TimeInstant pt = (TimeInstant) value.getPhenomenonTime();
    assertThat(pt.getValue(), is(equalTo(phenomenonTime)));
    assertThat(value.getValue(), is(instanceOf(BooleanValue.class)));
    BooleanValue v = (BooleanValue) value.getValue();
    assertThat(v.getValue(), is(true));
    assertThat(v.getUnit(), is(nullValue()));
}
Also used : BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) Test(org.junit.Test)

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)27 DecodingException (org.n52.svalbard.decode.exception.DecodingException)15 Actuate (org.n52.shetland.w3c.xlink.Actuate)14 Reference (org.n52.shetland.w3c.xlink.Reference)14 Show (org.n52.shetland.w3c.xlink.Show)14 Type (org.n52.shetland.w3c.xlink.Type)14 ActuateType (org.w3.x1999.xlink.ActuateType)14 ShowType (org.w3.x1999.xlink.ShowType)14 TypeType (org.w3.x1999.xlink.TypeType)14 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)13 AbstractCRSType (net.opengis.gml.x32.AbstractCRSType)10 CodeType (net.opengis.gml.x32.CodeType)10 EXExtentType (org.isotc211.x2005.gmd.EXExtentType)10 Test (org.junit.Test)10 XmlException (org.apache.xmlbeans.XmlException)9 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)9 CIResponsiblePartyPropertyType (org.isotc211.x2005.gmd.CIResponsiblePartyPropertyType)8 CIResponsiblePartyType (org.isotc211.x2005.gmd.CIResponsiblePartyType)8 BaseUnitType (net.opengis.gml.x32.BaseUnitType)6 SupportedType (org.n52.shetland.ogc.SupportedType)6