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);
}
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;
}
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;
}
Aggregations