Search in sources :

Example 1 with AbstractDataValueProperty

use of org.geotoolkit.swe.xml.AbstractDataValueProperty in project geotoolkit by Geomatys.

the class OMXmlFactory method convertTo200.

private static AbstractObservation convertTo200(final Observation observation) {
    final String name = (observation.getName() != null) ? observation.getName().getCode() : "";
    final String type;
    if (observation instanceof Measurement) {
        type = "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement";
    } else {
        type = "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_ComplexObservation";
    }
    final org.geotoolkit.gml.xml.v321.AbstractTimeObjectType time;
    if (observation.getSamplingTime() instanceof Period) {
        final Period p = (Period) observation.getSamplingTime();
        String dateBegin = null;
        if (p.getBeginning() != null && p.getBeginning().getDate() != null) {
            dateBegin = p.getBeginning().getDate().toString();
        }
        String dateEnd = null;
        if (p.getEnding() != null && p.getEnding().getDate() != null) {
            dateEnd = p.getEnding().getDate().toString();
        }
        time = (org.geotoolkit.gml.xml.v321.AbstractTimeObjectType) GMLXmlFactory.createTimePeriod("3.2.1", null, dateBegin, dateEnd);
    } else if (observation.getSamplingTime() instanceof Instant) {
        final Instant p = (Instant) observation.getSamplingTime();
        String date = null;
        if (p.getDate() != null) {
            date = p.getDate().toString();
        }
        time = (org.geotoolkit.gml.xml.v321.AbstractTimeObjectType) GMLXmlFactory.createTimeInstant("3.2.1", null, date);
    } else if (observation.getSamplingTime() != null) {
        throw new IllegalArgumentException("Unexpected samplingTime type:" + observation.getSamplingTime().getClass().getName());
    } else {
        time = null;
    }
    final String procedure = ((org.geotoolkit.observation.xml.Process) observation.getProcedure()).getHref();
    final Identifier idOP = ((org.geotoolkit.swe.xml.Phenomenon) observation.getObservedProperty()).getName();
    final String observedProperty = (idOP != null) ? idOP.getCode() : null;
    final SamplingFeature sf = convertTo200((SamplingFeature) observation.getFeatureOfInterest());
    final org.geotoolkit.gml.xml.v321.FeaturePropertyType feature = (org.geotoolkit.gml.xml.v321.FeaturePropertyType) buildFeatureProperty("2.0.0", sf);
    final Object result;
    if (observation.getResult() instanceof org.geotoolkit.swe.xml.v101.DataArrayPropertyType) {
        final org.geotoolkit.swe.xml.v101.DataArrayPropertyType resultv100 = (org.geotoolkit.swe.xml.v101.DataArrayPropertyType) observation.getResult();
        final org.geotoolkit.swe.xml.v101.TextBlockType encodingV100 = (org.geotoolkit.swe.xml.v101.TextBlockType) resultv100.getDataArray().getEncoding();
        final int count = resultv100.getDataArray().getElementCount().getCount().getValue();
        final String id = resultv100.getDataArray().getId();
        final org.geotoolkit.swe.xml.v200.TextEncodingType enc = new org.geotoolkit.swe.xml.v200.TextEncodingType(encodingV100.getId(), encodingV100.getDecimalSeparator(), encodingV100.getTokenSeparator(), encodingV100.getBlockSeparator());
        final String values = resultv100.getDataArray().getValues();
        List<Object> dataValues = null;
        final AbstractDataValueProperty dataValues100 = resultv100.getDataArray().getDataValues();
        if (dataValues100 != null) {
            dataValues = dataValues100.getAny();
        }
        final org.geotoolkit.swe.xml.v101.SimpleDataRecordType recordv100 = (org.geotoolkit.swe.xml.v101.SimpleDataRecordType) resultv100.getDataArray().getElementType();
        final List<org.geotoolkit.swe.xml.v200.Field> fields = new ArrayList<org.geotoolkit.swe.xml.v200.Field>();
        for (org.geotoolkit.swe.xml.v101.AnyScalarPropertyType scalar : recordv100.getField()) {
            final org.geotoolkit.swe.xml.v200.AbstractDataComponentType component = convert(scalar.getValue());
            fields.add(new org.geotoolkit.swe.xml.v200.Field(scalar.getName(), component));
        }
        final org.geotoolkit.swe.xml.v200.DataRecordType record = new org.geotoolkit.swe.xml.v200.DataRecordType(recordv100.getId(), recordv100.getDefinition(), recordv100.isFixed(), fields);
        // final ElementType elem = new ElementType(resultv100.getDataArray().getName(), record);
        final org.geotoolkit.swe.xml.v200.DataArrayType array = new org.geotoolkit.swe.xml.v200.DataArrayType(id, count, enc, values, id, record, dataValues);
        final org.geotoolkit.swe.xml.v200.DataArrayPropertyType resultv200 = new org.geotoolkit.swe.xml.v200.DataArrayPropertyType(array);
        result = resultv200;
    } else {
        result = observation.getResult();
    }
    return new org.geotoolkit.observation.xml.v200.OMObservationType(null, name, type, time, procedure, observedProperty, observation.getObservedProperty(), feature, result);
}
Also used : Measurement(org.opengis.observation.Measurement) ArrayList(java.util.ArrayList) SamplingFeature(org.opengis.observation.sampling.SamplingFeature) Identifier(org.opengis.metadata.Identifier) Instant(org.opengis.temporal.Instant) Period(org.opengis.temporal.Period) AbstractDataValueProperty(org.geotoolkit.swe.xml.AbstractDataValueProperty)

Aggregations

ArrayList (java.util.ArrayList)1 AbstractDataValueProperty (org.geotoolkit.swe.xml.AbstractDataValueProperty)1 Identifier (org.opengis.metadata.Identifier)1 Measurement (org.opengis.observation.Measurement)1 SamplingFeature (org.opengis.observation.sampling.SamplingFeature)1 Instant (org.opengis.temporal.Instant)1 Period (org.opengis.temporal.Period)1