Search in sources :

Example 1 with CompositePhenomenonType

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

use of org.geotoolkit.swe.xml.v101.CompositePhenomenonType 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)

Example 3 with CompositePhenomenonType

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

the class OMUtils method getPhenomenon.

public static Phenomenon getPhenomenon(final String version, String name, final List<? extends Field> phenomenons, final String phenomenonIdBase, final Set<org.opengis.observation.Phenomenon> existingPhens) {
    final Phenomenon phenomenon;
    if (phenomenons.size() == 1) {
        phenomenon = SOSXmlFactory.buildPhenomenon(version, phenomenons.get(0).name, phenomenons.get(0).label, phenomenons.get(0).name, phenomenons.get(0).description);
    } else {
        final Set<PhenomenonType> types = new LinkedHashSet<>();
        for (Field phen : phenomenons) {
            types.add(new PhenomenonType(phen.name, phen.label, phen.name, phen.description));
        }
        // look for an already existing (composite) phenomenon to use instead of creating a new one
        for (org.opengis.observation.Phenomenon existingPhen : existingPhens) {
            if (existingPhen instanceof CompositePhenomenon) {
                CompositePhenomenon cphen = (CompositePhenomenon) existingPhen;
                if (componentsEquals(cphen.getComponent(), types)) {
                    return (Phenomenon) cphen;
                }
            }
        }
        final String compositeId = "composite" + UUID.randomUUID().toString();
        final String definition = phenomenonIdBase + compositeId;
        if (name == null) {
            name = definition;
        }
        phenomenon = new CompositePhenomenonType(compositeId, name, definition, null, null, types);
    }
    return phenomenon;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CompositePhenomenonType(org.geotoolkit.swe.xml.v101.CompositePhenomenonType) Field(org.geotoolkit.observation.model.Field) CompositePhenomenonType(org.geotoolkit.swe.xml.v101.CompositePhenomenonType) PhenomenonType(org.geotoolkit.swe.xml.v101.PhenomenonType) Phenomenon(org.geotoolkit.swe.xml.Phenomenon) CompositePhenomenon(org.opengis.observation.CompositePhenomenon) CompositePhenomenon(org.opengis.observation.CompositePhenomenon) LineString(org.geotoolkit.gml.xml.LineString)

Aggregations

CompositePhenomenonType (org.geotoolkit.swe.xml.v101.CompositePhenomenonType)3 PhenomenonType (org.geotoolkit.swe.xml.v101.PhenomenonType)3 LinkedHashSet (java.util.LinkedHashSet)2 Field (org.geotoolkit.observation.model.Field)2 Phenomenon (org.geotoolkit.swe.xml.Phenomenon)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LineString (org.geotoolkit.gml.xml.LineString)1 Test (org.junit.Test)1 CompositePhenomenon (org.opengis.observation.CompositePhenomenon)1