Search in sources :

Example 21 with TimePeriod

use of org.n52.shetland.ogc.gml.time.TimePeriod in project arctic-sea by 52North.

the class SosV1GetCapabilitiesResponseEncoder method setContents.

/**
 * Sets the content section to the Capabilities document.
 *
 * @param xbContents SOS 2.0 contents section
 * @param offerings  SOS offerings for contents
 * @param version    SOS response version
 *
 * @throws EncodingException * if an error occurs.
 */
protected void setContents(Contents xbContents, Collection<SosObservationOffering> offerings, String version) throws EncodingException {
    // Contents xbContType = xbContents.addNewContents();
    ObservationOfferingList xbObservationOfferings = xbContents.addNewObservationOfferingList();
    for (SosObservationOffering offering : offerings) {
        ObservationOfferingType xbObservationOffering = xbObservationOfferings.addNewObservationOffering();
        // TODO check NAme or ID
        xbObservationOffering.setId(NcName.makeValid(offering.getOffering().getIdentifier()));
        // envelope
        if (offering.isSetObservedArea()) {
            xbObservationOffering.addNewBoundedBy().addNewEnvelope().set(encodeObjectToXml(GmlConstants.NS_GML, offering.getObservedArea()));
        }
        // set gml:name to offering's id (not ncname resolved)
        for (CodeType name : offering.getOffering().getName()) {
            xbObservationOffering.addNewName().set(encodeObjectToXml(GmlConstants.NS_GML, name));
        }
        // set up time
        if (offering.getPhenomenonTime() instanceof TimePeriod) {
            xbObservationOffering.addNewTime().set(encodeObjectToXml(SweConstants.NS_SWE_101, offering.getPhenomenonTime()));
        }
        offering.getObservableProperties().forEach(phenomenon -> xbObservationOffering.addNewObservedProperty().setHref(phenomenon));
        offering.getFeatureOfInterestTypes().forEach(featureOfInterestType -> xbObservationOffering.addNewFeatureOfInterest().setHref(featureOfInterestType));
        offering.getProcedureDescriptionFormats().forEach(procedureDescriptionFormat -> xbObservationOffering.addNewProcedure().setHref(procedureDescriptionFormat));
        offering.getProcedures().forEach(procedure -> xbObservationOffering.addNewProcedure().setHref(procedure));
        offering.getFeatureOfInterest().forEach(featureOfInterest -> xbObservationOffering.addNewFeatureOfInterest().setHref(featureOfInterest));
        offering.getResultModels().forEach(xbObservationOffering::addResultModel);
        offering.getResponseFormats().forEach(responseFormat -> xbObservationOffering.addNewResponseFormat().setStringValue(responseFormat));
        offering.getResponseModes().forEach(responseMode -> xbObservationOffering.addNewResponseMode().setStringValue(responseMode));
    }
}
Also used : ObservationOfferingList(net.opengis.sos.x10.ContentsDocument.Contents.ObservationOfferingList) ObservationOfferingType(net.opengis.sos.x10.ObservationOfferingType) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) CodeType(org.n52.shetland.ogc.gml.CodeType) SosObservationOffering(org.n52.shetland.ogc.sos.SosObservationOffering)

Example 22 with TimePeriod

use of org.n52.shetland.ogc.gml.time.TimePeriod in project arctic-sea by 52North.

the class JSONDecoder method parseTimePeriod.

protected TimePeriod parseTimePeriod(JsonNode node) throws DateTimeParseException {
    if (node.isArray()) {
        ArrayNode array = (ArrayNode) node;
        String startTime = array.get(0).textValue();
        String endTime = array.get(1).textValue();
        DateTime start = parseDateTime(startTime);
        DateTime end = parseDateTime(endTime);
        return new TimePeriod(start, end);
    } else {
        return null;
    }
}
Also used : TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) DateTime(org.joda.time.DateTime)

Example 23 with TimePeriod

use of org.n52.shetland.ogc.gml.time.TimePeriod in project arctic-sea by 52North.

the class UVFEncoder method getTemporalBBoxFromObservations.

private TimePeriod getTemporalBBoxFromObservations(List<OmObservation> observationCollection) throws EncodingException {
    DateTime start = null;
    DateTime end = null;
    for (OmObservation observation : observationCollection) {
        Time phenomenonTime = observation.getPhenomenonTime();
        if (phenomenonTime instanceof TimeInstant) {
            final DateTime time = ((TimeInstant) phenomenonTime).getTimePosition().getTime();
            if (start == null || time.isBefore(start)) {
                start = time;
            }
            if (end == null || time.isAfter(end)) {
                end = time;
            }
        } else {
            final DateTime periodStart = ((TimePeriod) phenomenonTime).getStart();
            if (start == null || periodStart.isBefore(start)) {
                start = periodStart;
            }
            final DateTime periodEnd = ((TimePeriod) phenomenonTime).getEnd();
            if (end == null || periodEnd.isAfter(end)) {
                end = periodEnd;
            }
        }
    }
    if (start != null && end != null) {
        return new TimePeriod(start, end);
    } else {
        final String message = "Could not extract centuries from observation collection";
        LOGGER.error(message);
        throw new EncodingException(message);
    }
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) OmObservation(org.n52.shetland.ogc.om.OmObservation) Time(org.n52.shetland.ogc.gml.time.Time) DateTime(org.joda.time.DateTime) DateTime(org.joda.time.DateTime) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant)

Example 24 with TimePeriod

use of org.n52.shetland.ogc.gml.time.TimePeriod in project arctic-sea by 52North.

the class UVFEncoder method writeLine2.

private void writeLine2(Writer fw, OmObservation o, TimePeriod centuries, String lineEnding) throws IOException {
    // 2.Zeile ABFLUSS m3/s 1900 1900
    StringBuilder sb = new StringBuilder(39);
    // Identifier
    AbstractPhenomenon observableProperty = o.getObservationConstellation().getObservableProperty();
    String observablePropertyIdentifier = observableProperty.getIdentifier();
    if (observablePropertyIdentifier != null && !observablePropertyIdentifier.isEmpty()) {
        observablePropertyIdentifier = ensureIdentifierLength(observablePropertyIdentifier, UVFConstants.MAX_IDENTIFIER_LENGTH);
    }
    sb.append(observablePropertyIdentifier);
    fillWithSpaces(sb, UVFConstants.MAX_IDENTIFIER_LENGTH);
    // Unit (optional)
    String unit = getUnit(o);
    if (unit != null && !unit.isEmpty()) {
        unit = ensureIdentifierLength(unit, UVFConstants.MAX_IDENTIFIER_LENGTH);
        sb.append(" ");
        sb.append(unit);
    }
    fillWithSpaces(sb, 30);
    // Centuries
    sb.append(centuries.getStart().getCenturyOfEra() + "00 " + centuries.getEnd().getCenturyOfEra() + "00");
    writeToFile(fw, sb.toString(), lineEnding);
}
Also used : AbstractPhenomenon(org.n52.shetland.ogc.om.AbstractPhenomenon)

Example 25 with TimePeriod

use of org.n52.shetland.ogc.gml.time.TimePeriod in project arctic-sea by 52North.

the class AqdEncoder method processObservation.

protected void processObservation(OmObservation observation, TimePeriod timePeriod, TimeInstant resultTime, FeatureCollection featureCollection, AbstractEReportingHeader eReportingHeader, int counter) {
    if (observation.isSetPhenomenonTime()) {
        // generate gml:id
        observation.setGmlId(getObservationId(counter));
        // add xlink:href to eReportingHeader.content
        eReportingHeader.addContent((AbstractFeature) new OmObservation().setIdentifier(new CodeWithAuthority(getObservationXlink(observation.getGmlId()))));
        timePeriod.extendToContain(observation.getPhenomenonTime());
        observation.setResultTime(resultTime);
        featureCollection.addMember(observation);
    }
}
Also used : OmObservation(org.n52.shetland.ogc.om.OmObservation) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority)

Aggregations

TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)33 TimeInstant (org.n52.shetland.ogc.gml.time.TimeInstant)16 DateTime (org.joda.time.DateTime)13 Time (org.n52.shetland.ogc.gml.time.Time)12 OmObservation (org.n52.shetland.ogc.om.OmObservation)10 EncodingException (org.n52.svalbard.encode.exception.EncodingException)8 XmlObject (org.apache.xmlbeans.XmlObject)7 Test (org.junit.Test)4 EReportingHeader (org.n52.shetland.aqd.EReportingHeader)3 ReferenceType (org.n52.shetland.ogc.gml.ReferenceType)3 FeatureCollection (org.n52.shetland.ogc.om.features.FeatureCollection)3 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)3 DataAvailability (org.n52.shetland.ogc.sos.gda.GetDataAvailabilityResponse.DataAvailability)3 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)3 SweField (org.n52.shetland.ogc.swe.SweField)3 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)3 DecodingException (org.n52.svalbard.decode.exception.DecodingException)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 CodeWithAuthority (org.n52.shetland.ogc.gml.CodeWithAuthority)2 GetObservationRequest (org.n52.shetland.ogc.sos.request.GetObservationRequest)2