Search in sources :

Example 1 with EncodedValuesPropertyType

use of org.geotoolkit.swe.xml.v200.EncodedValuesPropertyType in project geotoolkit by Geomatys.

the class OMXmlFactory method convertTo100.

private static AbstractObservation convertTo100(final Observation observation) {
    final String name = (observation.getName() != null) ? observation.getName().getCode() : "";
    final String definition = observation.getDefinition();
    final org.geotoolkit.gml.xml.v311.AbstractTimeGeometricPrimitiveType 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.v311.AbstractTimeGeometricPrimitiveType) GMLXmlFactory.createTimePeriod("3.1.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.v311.AbstractTimeGeometricPrimitiveType) GMLXmlFactory.createTimeInstant("3.1.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 idName = ((org.geotoolkit.swe.xml.Phenomenon) observation.getObservedProperty()).getName();
    final String phenomenonName = (idName != null) ? idName.getCode() : "";
    // extract id
    final String phenId;
    if (phenomenonName.indexOf(':') != -1) {
        phenId = phenomenonName.substring(phenomenonName.lastIndexOf(':') + 1, phenomenonName.length());
    } else {
        phenId = phenomenonName;
    }
    final org.geotoolkit.swe.xml.v101.PhenomenonType observedProperty = new PhenomenonType(phenId, phenomenonName);
    final org.geotoolkit.sampling.xml.v100.SamplingFeatureType sf = (org.geotoolkit.sampling.xml.v100.SamplingFeatureType) convertTo100((SamplingFeature) observation.getFeatureOfInterest());
    final Object result;
    if (observation.getResult() instanceof org.geotoolkit.swe.xml.v200.DataArrayPropertyType) {
        final org.geotoolkit.swe.xml.v200.DataArrayPropertyType resultv200 = (org.geotoolkit.swe.xml.v200.DataArrayPropertyType) observation.getResult();
        final org.geotoolkit.swe.xml.v200.TextEncodingType encodingV200 = (org.geotoolkit.swe.xml.v200.TextEncodingType) resultv200.getDataArray().getEncoding();
        final int count = resultv200.getDataArray().getElementCount().getCount().getValue();
        final String id = resultv200.getDataArray().getId();
        final org.geotoolkit.swe.xml.v101.TextBlockType enc = new org.geotoolkit.swe.xml.v101.TextBlockType(encodingV200.getId(), encodingV200.getDecimalSeparator(), encodingV200.getTokenSeparator(), encodingV200.getBlockSeparator());
        final String values = resultv200.getDataArray().getValues();
        List<Object> dataValues = null;
        final EncodedValuesPropertyType dataValues200 = resultv200.getDataArray().getDataValues();
        if (dataValues200 != null) {
            dataValues = dataValues200.getAny();
        }
        final org.geotoolkit.swe.xml.v200.DataRecordType recordv200 = (org.geotoolkit.swe.xml.v200.DataRecordType) resultv200.getDataArray().getElementType().getAbstractRecord();
        final List<org.geotoolkit.swe.xml.v101.AnyScalarPropertyType> fields = new ArrayList<org.geotoolkit.swe.xml.v101.AnyScalarPropertyType>();
        for (org.geotoolkit.swe.xml.v200.Field scalar : recordv200.getField()) {
            fields.add(new org.geotoolkit.swe.xml.v101.AnyScalarPropertyType(scalar));
        }
        final org.geotoolkit.swe.xml.v101.SimpleDataRecordType record = new org.geotoolkit.swe.xml.v101.SimpleDataRecordType(null, recordv200.getId(), recordv200.getDefinition(), recordv200.isFixed(), fields);
        final org.geotoolkit.swe.xml.v101.DataArrayType array = new org.geotoolkit.swe.xml.v101.DataArrayType(id, count, null, record, enc, values, dataValues);
        final org.geotoolkit.swe.xml.v101.DataArrayPropertyType resultv100 = new org.geotoolkit.swe.xml.v101.DataArrayPropertyType(array);
        result = resultv100;
    } else {
        result = observation.getResult();
    }
    if (observation instanceof Measurement) {
        return new org.geotoolkit.observation.xml.v100.MeasurementType(name, definition, sf, observedProperty, procedure, (org.geotoolkit.observation.xml.v100.MeasureType) result, time);
    } else {
        return new org.geotoolkit.observation.xml.v100.ObservationType(name, definition, sf, observedProperty, procedure, result, time);
    }
}
Also used : ArrayList(java.util.ArrayList) Identifier(org.opengis.metadata.Identifier) Instant(org.opengis.temporal.Instant) Period(org.opengis.temporal.Period) EncodedValuesPropertyType(org.geotoolkit.swe.xml.v200.EncodedValuesPropertyType) Measurement(org.opengis.observation.Measurement) PhenomenonType(org.geotoolkit.swe.xml.v101.PhenomenonType) SamplingFeature(org.opengis.observation.sampling.SamplingFeature) PhenomenonType(org.geotoolkit.swe.xml.v101.PhenomenonType)

Aggregations

ArrayList (java.util.ArrayList)1 PhenomenonType (org.geotoolkit.swe.xml.v101.PhenomenonType)1 EncodedValuesPropertyType (org.geotoolkit.swe.xml.v200.EncodedValuesPropertyType)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