Search in sources :

Example 1 with Measurement

use of org.opengis.observation.Measurement 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)

Example 2 with Measurement

use of org.opengis.observation.Measurement 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)2 Identifier (org.opengis.metadata.Identifier)2 Measurement (org.opengis.observation.Measurement)2 SamplingFeature (org.opengis.observation.sampling.SamplingFeature)2 Instant (org.opengis.temporal.Instant)2 Period (org.opengis.temporal.Period)2 AbstractDataValueProperty (org.geotoolkit.swe.xml.AbstractDataValueProperty)1 PhenomenonType (org.geotoolkit.swe.xml.v101.PhenomenonType)1 EncodedValuesPropertyType (org.geotoolkit.swe.xml.v200.EncodedValuesPropertyType)1