use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class OmObservationTest method should_have_SpatialFilteringProfileParameter.
@Test
public final void should_have_SpatialFilteringProfileParameter() throws OwsExceptionReport, DecodingException {
OmObservation omObservation = new OmObservation();
NamedValue<Geometry> namedValue = new NamedValue<>();
namedValue.setName(new ReferenceType(OmConstants.PARAM_NAME_SAMPLING_GEOMETRY));
GeometryFactory fac = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4326);
namedValue.setValue(new GeometryValue(fac.createPoint(new Coordinate(34.5, 76.4))));
// test no parameter is set
assertFalse(omObservation.isSetParameter());
assertFalse(omObservation.isSetSpatialFilteringProfileParameter());
omObservation.addParameter(namedValue);
// test with set SpatialFilteringProfile parameter
assertTrue(omObservation.isSetParameter());
assertTrue(omObservation.isSetSpatialFilteringProfileParameter());
assertThat(omObservation.getSpatialFilteringProfileParameter(), is(equalTo(namedValue)));
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class SweHelper method createSosSweDataArray.
/**
* Create {@link SweDataArray} from {@link OmObservation}
*
* @param sosObservation
* The {@link OmObservation} to create {@link SweDataArray} from
*
* @return Created {@link SweDataArray}
*
* @throws EncodingException
* If the service does not support the {@link SweDataArray}
* creation from value of {@link OmObservation}
*/
public SweDataArray createSosSweDataArray(OmObservation sosObservation) throws EncodingException {
String observablePropertyIdentifier = sosObservation.getObservationConstellation().getObservableProperty().getIdentifier();
SweDataArrayValue dataArrayValue = new SweDataArrayValue();
SweDataArray dataArray = new SweDataArray();
dataArray.setEncoding(createTextEncoding(sosObservation));
dataArrayValue.setValue(dataArray);
if (sosObservation.getValue() instanceof SingleObservationValue) {
SingleObservationValue<?> singleValue = (SingleObservationValue<?>) sosObservation.getValue();
if (singleValue.getValue() instanceof SweDataArrayValue) {
return (SweDataArray) singleValue.getValue().getValue();
} else {
dataArray.setElementType(createElementType(singleValue, observablePropertyIdentifier));
dataArrayValue.addBlock(createBlock(dataArray.getElementType(), sosObservation.getPhenomenonTime(), observablePropertyIdentifier, singleValue.getValue()));
}
} else if (sosObservation.getValue() instanceof MultiObservationValues) {
MultiObservationValues<?> multiValue = (MultiObservationValues<?>) sosObservation.getValue();
if (multiValue.getValue() instanceof SweDataArrayValue) {
return ((SweDataArrayValue) multiValue.getValue()).getValue();
} else if (multiValue.getValue() instanceof TVPValue) {
TVPValue tvpValues = (TVPValue) multiValue.getValue();
for (TimeValuePair timeValuePair : tvpValues.getValue()) {
if (timeValuePair != null && timeValuePair.getValue() != null && timeValuePair.getValue().isSetValue()) {
if (!dataArray.isSetElementTyp()) {
dataArray.setElementType(createElementType(timeValuePair, observablePropertyIdentifier));
}
List<String> newBlock = createBlock(dataArray.getElementType(), timeValuePair.getTime(), observablePropertyIdentifier, timeValuePair.getValue());
dataArrayValue.addBlock(newBlock);
}
}
}
}
return dataArray;
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class UVFEncoder method getFilename.
private String getFilename(List<OmObservation> observations) {
Set<String> identifiers = new HashSet<>();
for (OmObservation o : observations) {
if (o.getObservationConstellation().isSetIdentifier()) {
identifiers.add(o.getObservationConstellation().getIdentifier());
}
}
StringBuffer pathBuffer = new StringBuffer();
if (!identifiers.isEmpty()) {
for (String identifier : identifiers) {
pathBuffer.append(identifier).append("_");
}
pathBuffer.replace(pathBuffer.lastIndexOf("_"), pathBuffer.length(), "");
} else {
pathBuffer.append("_").append(Long.toString(java.lang.System.nanoTime()));
}
pathBuffer.append(".uvf");
return pathBuffer.toString();
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class UVFEncoder method writeLine3.
private void writeLine3(Writer fw, OmObservation o, String lineEnding) throws IOException {
// 3.Zeile 88888 0 0 0.000
StringBuilder sb = new StringBuilder(45);
if (o.getObservationConstellation().isSetIdentifier()) {
sb.append(ensureIdentifierLength(o.getObservationConstellation().getIdentifier(), UVFConstants.MAX_IDENTIFIER_LENGTH));
} else if (o.isSetIdentifier()) {
sb.append(ensureIdentifierLength(o.getIdentifier(), UVFConstants.MAX_IDENTIFIER_LENGTH));
} else {
if (!o.isSetObservationID()) {
o.setObservationID(JavaHelper.generateID(o.toString()));
}
sb.append(ensureIdentifierLength(o.getObservationID(), UVFConstants.MAX_IDENTIFIER_LENGTH));
}
fillWithSpaces(sb, UVFConstants.MAX_IDENTIFIER_LENGTH);
AbstractFeature f = o.getObservationConstellation().getFeatureOfInterest();
if (o.getObservationConstellation().getFeatureOfInterest() instanceof AbstractSamplingFeature && ((AbstractSamplingFeature) o.getObservationConstellation().getFeatureOfInterest()).isSetGeometry()) {
AbstractSamplingFeature sf = (AbstractSamplingFeature) f;
// Rechtswert
String xString = sf.isSetGeometry() ? Double.toString(sf.getGeometry().getCoordinate().y) : "";
xString = ensureValueLength(xString, 10);
sb.append(xString);
fillWithSpaces(sb, 25);
// Hochwert
String yString = sf.isSetGeometry() ? Double.toString(sf.getGeometry().getCoordinate().x) : "";
yString = ensureValueLength(yString, 10);
sb.append(yString);
fillWithSpaces(sb, 35);
if (sf.isSetGeometry() && !Double.isNaN(sf.getGeometry().getCoordinate().z)) {
String zString = Double.toString(sf.getGeometry().getCoordinate().z);
zString = ensureValueLength(zString, 10);
sb.append(zString);
}
}
fillWithSpaces(sb, 45);
writeToFile(fw, sb.toString(), lineEnding);
}
use of org.n52.shetland.ogc.om.OmObservation in project arctic-sea by 52North.
the class UVFEncoder method writeMessStellenname.
private void writeMessStellenname(Writer fw, OmObservation o, String lineEnding) throws IOException {
if (o.getObservationConstellation().getFeatureOfInterest().isSetName()) {
final CodeType firstName = o.getObservationConstellation().getFeatureOfInterest().getFirstName();
String name = ensureIdentifierLength(firstName.isSetValue() ? firstName.getValue() : "", UVFConstants.MAX_IDENTIFIER_LENGTH);
writeToFile(fw, String.format("$sb Mess-Stellenname: %s", name), lineEnding);
}
}
Aggregations