Search in sources :

Example 1 with PhenomenonType

use of org.geotoolkit.swe.xml.v101.PhenomenonType in project geotoolkit by Geomatys.

the class OMUtilsTest method getPhenomenonTest.

@Test
public void getPhenomenonTest() throws Exception {
    Field PRES = new Field(1, FieldType.QUANTITY, "PRES", "Pression", "urn:ogc:def:phenomenon:GEOM:pres", "Pa");
    Field PSAL = new Field(2, FieldType.QUANTITY, "PSAL", "Salinity", "urn:ogc:def:phenomenon:GEOM:psal", "mg/l");
    Field TEMP = new Field(3, FieldType.QUANTITY, "TEMP", "Temperature", "urn:ogc:def:phenomenon:GEOM:TEMP", "°c");
    List<Field> phenomenons = Arrays.asList(PRES, PSAL, TEMP);
    final Set<PhenomenonType> components = new LinkedHashSet<>();
    for (Field phen : phenomenons) {
        components.add(new PhenomenonType(phen.name, phen.label, phen.name, phen.description));
    }
    String phenomenonIdBase = "urn:ogc:phenomenon:";
    final String compositeId = "composite" + UUID.randomUUID().toString();
    final String compositeName = phenomenonIdBase + compositeId;
    CompositePhenomenonType expResult = new CompositePhenomenonType(compositeId, compositeName, null, null, null, components);
    Set<org.opengis.observation.Phenomenon> existingPhens = new HashSet<>();
    existingPhens.add(expResult);
    List<Field> newPhens = new ArrayList<>();
    newPhens.add(PRES);
    newPhens.add(PSAL);
    newPhens.add(TEMP);
    Phenomenon result = OMUtils.getPhenomenon("1.0.0", newPhens, existingPhens);
    Assert.assertEquals(expResult.getId(), result.getId());
    Assert.assertEquals(expResult, result);
    // order matters
    newPhens = new ArrayList<>();
    newPhens.add(PSAL);
    newPhens.add(PRES);
    newPhens.add(TEMP);
    result = OMUtils.getPhenomenon("1.0.0", newPhens, existingPhens);
    Assert.assertNotEquals(expResult.getId(), result.getId());
    Assert.assertNotEquals(expResult, result);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CompositePhenomenonType(org.geotoolkit.swe.xml.v101.CompositePhenomenonType) PhenomenonType(org.geotoolkit.swe.xml.v101.PhenomenonType) CompositePhenomenonType(org.geotoolkit.swe.xml.v101.CompositePhenomenonType) ArrayList(java.util.ArrayList) Field(org.geotoolkit.observation.model.Field) Phenomenon(org.geotoolkit.swe.xml.Phenomenon) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 2 with PhenomenonType

use of org.geotoolkit.swe.xml.v101.PhenomenonType in project geotoolkit by Geomatys.

the class ObservationXMLBindingTest method marshallingTest.

/**
 * Test simple Record Marshalling.
 *
 * @throws java.lang.Exception
 */
@Test
public void marshallingTest() throws Exception {
    DirectPositionType pos = new DirectPositionType("urn:ogc:crs:espg:4326", 2, Arrays.asList(3.2, 6.5));
    PointType location = new PointType("point-ID", pos);
    SamplingPointType sp = new SamplingPointType("samplingID-007", "urn:sampling:test:007", "a sampling Test", new FeaturePropertyType(""), location);
    PhenomenonType observedProperty = new PhenomenonType("phenomenon-007", "urn:OGC:phenomenon-007");
    TimePeriodType samplingTime = new TimePeriodType("t1", "2007-01-01", "2008-09-09");
    TextBlockType encoding = new TextBlockType("encoding-001", ",", "@@", ".");
    List<AnyScalarPropertyType> fields = new ArrayList<>();
    AnyScalarPropertyType field = new AnyScalarPropertyType("text-field-001", new Text("urn:something", "some value"));
    fields.add(field);
    SimpleDataRecordType record = new SimpleDataRecordType(fields);
    DataArrayType array = new DataArrayType("array-001", 1, "array-001", record, encoding, "somevalue", null);
    DataArrayPropertyType arrayProp = new DataArrayPropertyType(array);
    ObservationType obs = new ObservationType("urn:Observation-007", "observation definition", sp, observedProperty, "urn:sensor:007", arrayProp, samplingTime);
    StringWriter sw = new StringWriter();
    marshaller.marshal(obs, sw);
    String result = sw.toString();
    // we remove the first line
    result = result.substring(result.indexOf("?>") + 2).trim();
    String expResult = "<om:Observation xmlns:sampling=\"http://www.opengis.net/sampling/1.0\"" + " xmlns:om=\"http://www.opengis.net/om/1.0\"" + " xmlns:xlink=\"http://www.w3.org/1999/xlink\"" + " xmlns:gml=\"http://www.opengis.net/gml\"" + " xmlns:swe=\"http://www.opengis.net/swe/1.0.1\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + '\n' + "    <gml:name>urn:Observation-007</gml:name>" + '\n' + "    <om:samplingTime>" + '\n' + "        <gml:TimePeriod gml:id=\"t1\">" + '\n' + "            <gml:beginPosition>2007-01-01</gml:beginPosition>" + '\n' + "            <gml:endPosition>2008-09-09</gml:endPosition>" + '\n' + "        </gml:TimePeriod>" + '\n' + "    </om:samplingTime>" + '\n' + "    <om:procedure xlink:href=\"urn:sensor:007\"/>" + '\n' + "    <om:observedProperty>" + '\n' + "        <swe:Phenomenon gml:id=\"phenomenon-007\">" + '\n' + "            <gml:name>urn:OGC:phenomenon-007</gml:name>" + '\n' + "        </swe:Phenomenon>" + '\n' + "    </om:observedProperty>" + '\n' + "    <om:featureOfInterest>" + '\n' + "        <sampling:SamplingPoint gml:id=\"samplingID-007\">" + '\n' + "            <gml:description>a sampling Test</gml:description>" + '\n' + "            <gml:name>urn:sampling:test:007</gml:name>" + '\n' + "            <gml:boundedBy>" + '\n' + "                <gml:Null>not_bounded</gml:Null>" + '\n' + "            </gml:boundedBy>" + '\n' + "            <sampling:sampledFeature xlink:href=\"\"/>" + '\n' + "            <sampling:position>" + '\n' + "                <gml:Point gml:id=\"point-ID\">" + '\n' + "                    <gml:pos srsName=\"urn:ogc:crs:espg:4326\" srsDimension=\"2\">3.2 6.5</gml:pos>" + '\n' + "                </gml:Point>" + '\n' + "            </sampling:position>" + '\n' + "        </sampling:SamplingPoint>" + '\n' + "    </om:featureOfInterest>" + '\n' + "    <om:result xsi:type=\"swe:DataArrayPropertyType\" >" + '\n' + "        <swe:DataArray gml:id=\"array-001\">" + '\n' + "            <swe:elementCount>" + '\n' + "                <swe:Count>" + '\n' + "                    <swe:value>1</swe:value>" + '\n' + "                </swe:Count>" + '\n' + "            </swe:elementCount>" + '\n' + "            <swe:elementType name=\"array-001\">" + '\n' + "                <swe:SimpleDataRecord>" + '\n' + "                    <swe:field name=\"text-field-001\">" + '\n' + "                        <swe:Text definition=\"urn:something\">" + '\n' + "                            <swe:value>some value</swe:value>" + '\n' + "                        </swe:Text>" + '\n' + "                    </swe:field>" + '\n' + "                </swe:SimpleDataRecord>" + '\n' + "            </swe:elementType>" + '\n' + "            <swe:encoding>" + '\n' + "                <swe:TextBlock blockSeparator=\"@@\" decimalSeparator=\".\" tokenSeparator=\",\" id=\"encoding-001\"/>" + '\n' + "            </swe:encoding>" + '\n' + "            <swe:values>somevalue</swe:values>" + '\n' + "        </swe:DataArray>" + '\n' + "    </om:result>" + '\n' + "</om:Observation>\n";
    assertXmlEquals(expResult, result, "xmlns:*");
    UnitOfMeasureEntry uom = new UnitOfMeasureEntry("m", "meters", "distance", "meters");
    MeasureType meas = new MeasureType(uom, 7);
    MeasurementType measmt = new MeasurementType("urn:Observation-007", "observation definition", sp, observedProperty, "urn:sensor:007", meas, samplingTime);
    sw = new StringWriter();
    marshaller.marshal(measmt, sw);
    result = sw.toString();
    // we remove the first line
    result = result.substring(result.indexOf("?>") + 2).trim();
    expResult = "<om:Measurement xmlns:sampling=\"http://www.opengis.net/sampling/1.0\"" + " xmlns:om=\"http://www.opengis.net/om/1.0\"" + " xmlns:xlink=\"http://www.w3.org/1999/xlink\"" + " xmlns:gml=\"http://www.opengis.net/gml\"" + " xmlns:swe=\"http://www.opengis.net/swe/1.0.1\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + '\n' + "    <gml:name>urn:Observation-007</gml:name>" + '\n' + "    <om:samplingTime>" + '\n' + "        <gml:TimePeriod gml:id=\"t1\">" + '\n' + "            <gml:beginPosition>2007-01-01</gml:beginPosition>" + '\n' + "            <gml:endPosition>2008-09-09</gml:endPosition>" + '\n' + "        </gml:TimePeriod>" + '\n' + "    </om:samplingTime>" + '\n' + "    <om:procedure xlink:href=\"urn:sensor:007\"/>" + '\n' + "    <om:observedProperty>" + '\n' + "        <swe:Phenomenon gml:id=\"phenomenon-007\">" + '\n' + "            <gml:name>urn:OGC:phenomenon-007</gml:name>" + '\n' + "        </swe:Phenomenon>" + '\n' + "    </om:observedProperty>" + '\n' + "    <om:featureOfInterest>" + '\n' + "        <sampling:SamplingPoint gml:id=\"samplingID-007\">" + '\n' + "            <gml:description>a sampling Test</gml:description>" + '\n' + "            <gml:name>urn:sampling:test:007</gml:name>" + '\n' + "            <gml:boundedBy>" + '\n' + "                <gml:Null>not_bounded</gml:Null>" + '\n' + "            </gml:boundedBy>" + '\n' + "            <sampling:sampledFeature xlink:href=\"\"/>" + '\n' + "            <sampling:position>" + '\n' + "                <gml:Point gml:id=\"point-ID\">" + '\n' + "                    <gml:pos srsName=\"urn:ogc:crs:espg:4326\" srsDimension=\"2\">3.2 6.5</gml:pos>" + '\n' + "                </gml:Point>" + '\n' + "            </sampling:position>" + '\n' + "        </sampling:SamplingPoint>" + '\n' + "    </om:featureOfInterest>" + '\n' + "    <om:result xsi:type=\"om:MeasureType\" uom=\"meters\">7.0</om:result>" + '\n' + "</om:Measurement>\n";
    assertXmlEquals(expResult, result, "xmlns:*");
    ObservationCollectionType collection = new ObservationCollectionType();
    collection.add(measmt);
    sw = new StringWriter();
    marshaller.marshal(collection, sw);
    result = sw.toString();
    // System.out.println(result);
    collection = new ObservationCollectionType();
    collection.add(obs.getTemporaryTemplate("temporaryName", samplingTime));
    sw = new StringWriter();
    marshaller.marshal(collection, sw);
    result = sw.toString();
}
Also used : ObservationType(org.geotoolkit.observation.xml.v100.ObservationType) DirectPositionType(org.geotoolkit.gml.xml.v311.DirectPositionType) PhenomenonType(org.geotoolkit.swe.xml.v101.PhenomenonType) AnyScalarPropertyType(org.geotoolkit.swe.xml.v101.AnyScalarPropertyType) ArrayList(java.util.ArrayList) MeasureType(org.geotoolkit.observation.xml.v100.MeasureType) ObservationCollectionType(org.geotoolkit.observation.xml.v100.ObservationCollectionType) Text(org.geotoolkit.swe.xml.v101.Text) DataArrayPropertyType(org.geotoolkit.swe.xml.v101.DataArrayPropertyType) TimePeriodType(org.geotoolkit.gml.xml.v311.TimePeriodType) StringWriter(java.io.StringWriter) SamplingPointType(org.geotoolkit.sampling.xml.v100.SamplingPointType) MeasurementType(org.geotoolkit.observation.xml.v100.MeasurementType) TextBlockType(org.geotoolkit.swe.xml.v101.TextBlockType) UnitOfMeasureEntry(org.geotoolkit.gml.xml.v311.UnitOfMeasureEntry) PointType(org.geotoolkit.gml.xml.v311.PointType) SamplingPointType(org.geotoolkit.sampling.xml.v100.SamplingPointType) FeaturePropertyType(org.geotoolkit.gml.xml.v311.FeaturePropertyType) SimpleDataRecordType(org.geotoolkit.swe.xml.v101.SimpleDataRecordType) DataArrayType(org.geotoolkit.swe.xml.v101.DataArrayType)

Example 3 with PhenomenonType

use of org.geotoolkit.swe.xml.v101.PhenomenonType 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 4 with PhenomenonType

use of org.geotoolkit.swe.xml.v101.PhenomenonType in project geotoolkit by Geomatys.

the class MeasurementType method getTemporaryTemplate.

/**
 * Construit un nouveau template temporaire d'observation a partir d'un template fournit en argument.
 * On y rajoute un samplingTime et un id temporaire.
 */
@Override
public MeasurementType getTemporaryTemplate(final String temporaryName, TemporalGeometricPrimitive time) {
    if (time == null) {
        TimePositionType begin = new TimePositionType("1900-01-01T00:00:00");
        time = new TimePeriodType(begin);
    }
    PhenomenonType pheno = null;
    if (getObservedProperty() != null) {
        pheno = (PhenomenonType) getObservedProperty();
    }
    SamplingFeatureType foi = null;
    if (getFeatureOfInterest() != null) {
        foi = (SamplingFeatureType) getFeatureOfInterest();
    }
    final MeasureType res = (MeasureType) getResult();
    res.setValue(0);
    return new MeasurementType(temporaryName, getDefinition(), foi, pheno, getProcedure().getHref(), res, (AbstractTimeGeometricPrimitiveType) time);
}
Also used : SamplingFeatureType(org.geotoolkit.sampling.xml.v100.SamplingFeatureType) TimePeriodType(org.geotoolkit.gml.xml.v311.TimePeriodType) PhenomenonType(org.geotoolkit.swe.xml.v101.PhenomenonType) TimePositionType(org.geotoolkit.gml.xml.v311.TimePositionType)

Example 5 with PhenomenonType

use of org.geotoolkit.swe.xml.v101.PhenomenonType in project geotoolkit by Geomatys.

the class ObservationType method matchPhenomenon.

private boolean matchPhenomenon(PhenomenonType phen, PhenomenonType templatePhen) {
    if (Objects.equals(phen.getName().getCode(), templatePhen.getName().getCode())) {
        // due to transient field observed properties name will not be equals. so if the code is equals, we assume that its correct
        if (phen instanceof CompositePhenomenonType && templatePhen instanceof CompositePhenomenonType) {
            CompositePhenomenonType copyCompo = new CompositePhenomenonType((CompositePhenomenonType) phen);
            CompositePhenomenonType tempCompo = (CompositePhenomenonType) templatePhen;
            if (copyCompo.getComponent().size() == tempCompo.getComponent().size()) {
                for (int i = 0; i < copyCompo.getComponent().size(); i++) {
                    if (!matchPhenomenon(copyCompo.getComponent().get(i), tempCompo.getComponent().get(i))) {
                        return false;
                    }
                }
                return true;
            }
        } else {
            PhenomenonType copyPhen = new PhenomenonType(phen);
            copyPhen.setName(templatePhen.getName());
            return Objects.equals(copyPhen, templatePhen);
        }
    }
    return false;
}
Also used : CompositePhenomenonType(org.geotoolkit.swe.xml.v101.CompositePhenomenonType) PhenomenonType(org.geotoolkit.swe.xml.v101.PhenomenonType) CompositePhenomenonType(org.geotoolkit.swe.xml.v101.CompositePhenomenonType)

Aggregations

PhenomenonType (org.geotoolkit.swe.xml.v101.PhenomenonType)7 ArrayList (java.util.ArrayList)4 TimePeriodType (org.geotoolkit.gml.xml.v311.TimePeriodType)3 CompositePhenomenonType (org.geotoolkit.swe.xml.v101.CompositePhenomenonType)3 LinkedHashSet (java.util.LinkedHashSet)2 DirectPositionType (org.geotoolkit.gml.xml.v311.DirectPositionType)2 FeaturePropertyType (org.geotoolkit.gml.xml.v311.FeaturePropertyType)2 PointType (org.geotoolkit.gml.xml.v311.PointType)2 UnitOfMeasureEntry (org.geotoolkit.gml.xml.v311.UnitOfMeasureEntry)2 Field (org.geotoolkit.observation.model.Field)2 MeasureType (org.geotoolkit.observation.xml.v100.MeasureType)2 MeasurementType (org.geotoolkit.observation.xml.v100.MeasurementType)2 ObservationCollectionType (org.geotoolkit.observation.xml.v100.ObservationCollectionType)2 ObservationType (org.geotoolkit.observation.xml.v100.ObservationType)2 SamplingPointType (org.geotoolkit.sampling.xml.v100.SamplingPointType)2 Phenomenon (org.geotoolkit.swe.xml.Phenomenon)2 AnyScalarPropertyType (org.geotoolkit.swe.xml.v101.AnyScalarPropertyType)2 DataArrayPropertyType (org.geotoolkit.swe.xml.v101.DataArrayPropertyType)2 DataArrayType (org.geotoolkit.swe.xml.v101.DataArrayType)2 SimpleDataRecordType (org.geotoolkit.swe.xml.v101.SimpleDataRecordType)2