Example usage for org.joda.time DateTime parse

List of usage examples for org.joda.time DateTime parse

Introduction

In this page you can find the example usage for org.joda.time DateTime parse.

Prototype

@FromString
public static DateTime parse(String str) 

Source Link

Document

Parses a DateTime from the specified string.

Usage

From source file:org.n52.oxf.valueDomains.time.TimePosition.java

License:Open Source License

@Override
public int compareTo(final ITimePosition timePosP) {

    DateTime thisTimePosition = DateTime.parse(this.toISO8601Format());
    DateTime theOtherTimePosition = DateTime.parse(timePosP.toISO8601Format());

    return !thisTimePosition.isEqual(theOtherTimePosition)
            ? thisTimePosition.isBefore(theOtherTimePosition) ? -1 : 1
            : 0;//w w w .j  a  v a2 s .  c  o  m
}

From source file:org.n52.oxf.valueDomains.time.TimePosition.java

License:Open Source License

@Override
public Calendar getCalendar() {
    DateTime dateTime = DateTime.parse(this.toISO8601Format());
    return dateTime.toGregorianCalendar();
}

From source file:org.n52.scidbwcs.md.TemporalReference.java

License:Open Source License

public TemporalReference(String tdim, String t0_str, String dt_str) {
    this.tdim = tdim;
    this.t0 = DateTime.parse(t0_str);
    this.dt = Period.parse(dt_str);
}

From source file:org.n52.scidbwcs.wcs.GDALWrapper.java

License:Open Source License

private static ArrayList<String> buildTranslateCommand(WCSGetCoverageRequest req) throws WCSException {
    ArrayList<String> cmdlist = new ArrayList<>();
    String cmd = "";
    if (Config.get().SCIDBWCS_GDALPATH != null) {
        cmd += Config.get().SCIDBWCS_GDALPATH;
        if (!Config.get().SCIDBWCS_GDALPATH.endsWith("/")) {
            cmd += "/";
        }/*from ww  w.  j  a v a  2s  .c  om*/
    }
    cmd += "./gdal_translate";
    cmdlist.add(cmd);

    if (req.resx > 0 && req.resy > 0) {
        cmdlist.add("-tr");
        cmdlist.add(Double.toString(req.resx));
        cmdlist.add(Double.toString(req.resy));
    }

    if (req.width > 0 && req.height > 0) {
        cmdlist.add("-outsize");
        cmdlist.add(Integer.toString(req.width));
        cmdlist.add(Integer.toString(req.height));
    }

    if (req.crs.equalsIgnoreCase("IMAGE")) {
        assert req.bbox.length == 4 || req.bbox.length == 6;

        cmdlist.add("-srcwin");
        cmdlist.add(Long.toString((long) Math.round(req.bbox[0])));
        cmdlist.add(Long.toString((long) Math.round(req.bbox[1])));
        cmdlist.add(Long.toString((long) Math.round(req.bbox[2] - req.bbox[0])));
        cmdlist.add(Long.toString((long) Math.round(req.bbox[3] - req.bbox[1])));

    } else {
        assert req.bbox.length == 4 || req.bbox.length == 6;

        cmdlist.add("-projwin");
        cmdlist.add(Double.toString(req.bbox[0]));
        cmdlist.add(Double.toString(req.bbox[3]));
        cmdlist.add(Double.toString(req.bbox[2]));
        cmdlist.add(Double.toString(req.bbox[1]));

        cmdlist.add("-projwin_srs");
        cmdlist.add(req.crs);
    }

    if (req.time != null && req.time.length > 0) {
        // Convert datetime to index (could be done automatically by GDAl as well)
        Array A = ArrayManager.instance().getArrayMD_JDBC(req.coverage);
        Long tidx = A.trs().indexAtDatetime(DateTime.parse(req.time[0]));

        if (tidx < A.getTDim().getTrueMin() || tidx > A.getTDim().getTrueMax()) {
            throw new WCSException("Requested time is out of the coverage's range.",
                    WCSException.WCS_EXCEPTION_CODE.InvalidParameterValue);
        }
        // TODO: Check whether tidx is valid in temporal dimension

        cmdlist.add("-oo");
        cmdlist.add("t=" + tidx.toString());
    }

    switch (req.format.toUpperCase()) {
    case "JPEG":
    case "PNG":
    case "GIF":
    case "BMP":
        cmdlist.add("-of");
        cmdlist.add(req.format.toUpperCase());
        break;
    case "GEOTIFF":
        cmdlist.add("-of");
        cmdlist.add("GTiff");
        break;
    case "NETCDF":
        cmdlist.add("-of");
        cmdlist.add("netCDF");
        break;
    }

    switch (req.interpolation.toUpperCase()) {
    case "NEAREST":
        cmdlist.add("-r");
        cmdlist.add("nearest");
        break;
    case "BILINEAR":
        cmdlist.add("-r");
        cmdlist.add("bilinear");
        break;
    case "BICUBIC":
        cmdlist.add("-r");
        cmdlist.add("cubic");
        break;
    }

    // SciDB connection string
    String inDSStr = "SCIDB:array=" + req.coverage + " host="
            + (Config.get().SCIDBWCS_DB_SSL ? "https" : "http") + "://" + Config.get().SCIDBWCS_DB_HOST
            + " port=" + Config.get().SCIDBWCS_DB_SHIMPORT + " user=" + Config.get().SCIDBWCS_DB_USER
            + " password=" + Config.get().SCIDBWCS_DB_PW;
    cmdlist.add(inDSStr);

    String outDSStr = Config.get().SCIDBWCS_TEMPPATH + (Config.get().SCIDBWCS_TEMPPATH.endsWith("/") ? "" : "/")
            + req.getRequestID();

    switch (req.format.toUpperCase()) {
    case "JPEG":
        outDSStr += ".jpg";
        break;
    case "PNG":
        outDSStr += ".png";
        break;
    case "GIF":
        outDSStr += ".gif";
        break;
    case "BMP":
        outDSStr += ".bmp";
        break;
    case "GEOTIFF":
        outDSStr += ".tif";
        break;
    case "NETCDF":
        outDSStr += ".nc";
        break;
    }

    cmdlist.add(outDSStr);

    return cmdlist;
}

From source file:org.n52.scidbwcs.wcs.WCSGetCoverageRequest.java

License:Open Source License

public static WCSGetCoverageRequest fromKVP(String kvp) throws WCSException {

    final WCSGetCoverageRequest req = new WCSGetCoverageRequest();

    int getparsidx = kvp.lastIndexOf("?");

    if (getparsidx >= 0) {
        req.url = kvp.substring(0, getparsidx);
        kvp = kvp.substring(getparsidx + 1);
    } else {/*from w w w. j a  v a  2  s.c  o m*/
        req.url = kvp;
    }

    Map<String, String> kv = new HashMap<>();
    String[] args = kvp.split("&");
    for (String a : args) {
        int idx = a.indexOf("=");
        kv.put(a.substring(0, idx), a.substring(idx + 1));
    }

    req.request = kv.getOrDefault("REQUEST", "");
    kv.remove("REQUEST");
    req.service = kv.getOrDefault("SERVICE", "");
    kv.remove("SERVICE");
    req.version = kv.getOrDefault("VERSION", "");
    kv.remove("VERSION");
    req.coverage = kv.getOrDefault("COVERAGE", "");
    kv.remove("COVERAGE");
    req.width = Integer.parseInt(kv.getOrDefault("WIDTH", "-1"));
    kv.remove("WIDTH");
    req.height = Integer.parseInt(kv.getOrDefault("HEIGHT", "-1"));
    kv.remove("HEIGHT");
    req.depth = Integer.parseInt(kv.getOrDefault("DEPTH", "-1"));
    kv.remove("DEPTH");
    req.resx = Double.parseDouble(kv.getOrDefault("RESX", "0"));
    kv.remove("RESX");
    req.resy = Double.parseDouble(kv.getOrDefault("RESY", "0"));
    kv.remove("RESY");
    req.resz = Double.parseDouble(kv.getOrDefault("RESZ", "0"));
    kv.remove("RESZ");
    req.format = kv.getOrDefault("FORMAT", "");
    kv.remove("FORMAT");
    req.interpolation = kv.getOrDefault("INTERPOLATION", "");
    kv.remove("INTERPOLATION");

    String[] bbox = kv.getOrDefault("BBOX", "").split(",");
    kv.remove("BBOX");
    if (bbox.length == 4 || bbox.length == 6) {
        req.bbox = new double[bbox.length];
        for (int i = 0; i < bbox.length; ++i) {
            req.bbox[i] = Double.parseDouble(bbox[i]);
        }
    } else { // 
        // Time musst be given
        req.bbox = null;
    }

    // Time does not support tmin/tmax/tres style
    if (kv.containsKey("TIME")) {
        String[] time = kv.getOrDefault("TIME", null).split(",");
        kv.remove("TIME");
        if (!ArrayManager.instance().getArrayMD_JDBC(req.coverage).isTemporal()) {
            throw new WCSException(
                    "Array '" + req.coverage + "' has no temporal reference but TIME WCS parameter is given.",
                    WCSException.WCS_EXCEPTION_CODE.InvalidParameterValue);
        }
        if (time.length > 1) {
            throw new WCSException("Accepts only a single TIME value.",
                    WCSException.WCS_EXCEPTION_CODE.InvalidParameterValue);
        } else if (time.length == 1) {

            if (time[0].split("/").length != 1) {
                throw new WCSException("Time period start/end/res not supported.",
                        WCSException.WCS_EXCEPTION_CODE.InvalidParameterValue);
            }
            try {
                DateTime t = DateTime.parse(time[0]);
            } catch (Exception e) {
                throw new WCSException("Invalid datetime format, ISO 8601 expected.",
                        WCSException.WCS_EXCEPTION_CODE.InvalidParameterValue);
            }
            req.time = new String[time.length];
            for (int i = 0; i < time.length; ++i) {
                req.time[i] = time[i];
            }
        } else {
            req.time = null;
        }
        kv.remove("TIME");
    } else {
        req.time = null;
    }

    req.crs = kv.getOrDefault("CRS", "");
    kv.remove("CRS");
    req.response_crs = kv.getOrDefault("RESPONSE_CRS", req.crs);
    kv.remove("RESPONSE_CRS");
    req.exceptions = kv.getOrDefault("EXCEPTIONS", "application / vnd.ogc.se_xml");
    kv.remove("EXCEPTIONS");

    // Add all other parameters
    req.parameter = new HashMap<>();
    kv.forEach(new BiConsumer<String, String>() {
        @Override
        public void accept(String t, String u) {
            // a/b/c is not supported
            req.parameter.put(t, u.split(","));
        }
    });

    return req;
}

From source file:org.n52.server.io.TimeseriesFactory.java

License:Open Source License

public TimeseriesFactory(ObservationSeriesCollection collection) {
    this.collection = collection;
    ITimePosition[] index = this.collection.getSortedTimeArray();
    if (index.length > 0) {
        DateTime endTime = DateTime.parse(index[index.length - 1].toISO8601Format());
        this.timezone = endTime.getZone().toTimeZone();
    }/*from   w  ww  .ja v a  2s . c  o  m*/
}

From source file:org.n52.server.io.TimeseriesFactory.java

License:Open Source License

public TimeSeries createTimeSeries(SosTimeseries timeseries, String seriesType) {
    TimeSeries timeSeries = new TimeSeries(timeseries.getTimeseriesId());

    ITimePosition timeArray[] = collection.getSortedTimeArray();
    ObservedValueTuple prevObservation;//from ww w.  j  a v a  2  s .  c  o  m
    ObservedValueTuple nextObservation = collection.getTuple(new OXFFeature(timeseries.getFeatureId(), null),
            timeArray[0]);
    ObservedValueTuple observation = nextObservation;

    int counter = 0;
    Double sum = 0.0;

    // all obs
    LOGGER.debug("Compressionlevel none");
    for (int i = 0; i < timeArray.length; i++) {

        prevObservation = observation;
        observation = nextObservation;

        if (i + 1 < timeArray.length) {
            nextObservation = collection.getTuple(new OXFFeature(timeseries.getFeatureId(), null),
                    timeArray[i + 1]);
        }

        // String obsVal = observation.getValue(0).toString();
        // String prevObsVal = prevObservation.getValue(0).toString();
        // String nextObsVal = nextObservation.getValue(0).toString();

        // if ((i == 0) || // first observation --> in
        // (i == timeArray.length - 1) || // last observation --> in
        // (!(prevObsVal.equals(obsVal) && nextObsVal.equals(obsVal)))) {

        counter++;

        Double resultVal = getValidData(observation.getValue(0).toString());

        if (seriesType.equals("1")) {
            // nothing
        } else if (seriesType.equals("2")) {
            if (resultVal != null) {
                resultVal += sum;
            } else {
                resultVal = sum;
            }
        } else {
            // nothing
        }

        sum = resultVal;

        ITimePosition timePos = (ITimePosition) observation.getTime();
        DateTime time = DateTime.parse(timePos.toISO8601Format());
        timeSeries.add(new FixedMillisecond(time.getMillis()), resultVal);
    }

    // }

    LOGGER.debug("Compressed observations from " + timeArray.length + " to " + counter);

    return timeSeries;

}

From source file:org.n52.server.io.TimeseriesFactory.java

License:Open Source License

public TimeSeries compressToTimeSeries(SosTimeseries timeseries, boolean force, String seriesType) {

    TimeSeries timeSeries = new TimeSeries(timeseries.getTimeseriesId());

    ITimePosition timeArray[] = collection.getSortedTimeArray();
    ObservedValueTuple prevObservation;//  w w w. j  a  v a  2s .c  o m
    ObservedValueTuple nextObservation = collection.getTuple(new OXFFeature(timeseries.getFeatureId(), null),
            timeArray[0]);
    ObservedValueTuple observation = nextObservation;

    int counter = 0;
    Double sum = 0.0;

    if (FACADE_COMPRESSION || (timeArray.length > 6000 && force)) {
        // just %6
        LOGGER.debug("Compressionlevel 6");
        for (int i = 0; i < timeArray.length; i += 6) {

            prevObservation = observation;
            observation = nextObservation;

            if (i + 1 < timeArray.length) {
                nextObservation = collection.getTuple(new OXFFeature(timeseries.getFeatureId(), null),
                        timeArray[i + 1]);
            }

            String obsVal = observation.getValue(0).toString();
            String prevObsVal = prevObservation.getValue(0).toString();
            String nextObsVal = nextObservation.getValue(0).toString();

            if ((i == 0) || // first observation --> in
                    (i == timeArray.length - 1) || // last
                    // observation
                    // -->
                    // in
                    (!(prevObsVal.equals(obsVal)) || !(nextObsVal.equals(obsVal)))) {

                counter++;

                Double resultVal = getValidData(observation.getValue(0).toString());
                // line or sumline
                if (seriesType.equals("1")) {
                    // nothing
                } else if (seriesType.equals("2")) {
                    if (resultVal != null) {
                        resultVal += sum;
                    } else {
                        resultVal = sum;
                    }
                } else {
                    // nothing
                }
                sum = resultVal;

                ITimePosition timePos = (ITimePosition) observation.getTime();
                DateTime time = DateTime.parse(timePos.toISO8601Format());
                timeSeries.add(new FixedMillisecond(time.getMillis()), resultVal);
            }

        }

    } else if (FACADE_COMPRESSION && timeArray.length > 4000) {
        // just %4
        LOGGER.debug("Compressionlevel 4");
        for (int i = 0; i < timeArray.length; i += 4) {

            prevObservation = observation;
            observation = nextObservation;

            if (i + 1 < timeArray.length) {
                nextObservation = collection.getTuple(new OXFFeature(timeseries.getFeatureId(), null),
                        timeArray[i + 1]);
            }

            String obsVal = observation.getValue(0).toString();
            String prevObsVal = prevObservation.getValue(0).toString();
            String nextObsVal = nextObservation.getValue(0).toString();

            if ((i == 0) || // first observation --> in
                    (i == timeArray.length - 1) || // last
                    // observation
                    // -->
                    // in
                    (!(prevObsVal.equals(obsVal)) || !(nextObsVal.equals(obsVal)))) {

                counter++;

                Double resultVal = getValidData(observation.getValue(0).toString());

                // line or sumline
                if (seriesType.equals("1")) {
                    // nothing
                } else if (seriesType.equals("2")) {
                    if (resultVal != null) {
                        resultVal += sum;
                    } else {
                        resultVal = sum;
                    }
                } else {
                    // nothing
                }
                sum = resultVal;

                ITimePosition timePos = (ITimePosition) observation.getTime();
                DateTime time = DateTime.parse(timePos.toISO8601Format());
                timeSeries.add(new FixedMillisecond(time.getMillis()), resultVal);
            }

        }

    } else if (FACADE_COMPRESSION && timeArray.length > 2000) {
        // just %2
        LOGGER.debug("Compressionlevel 2");
        for (int i = 0; i < timeArray.length; i += 2) {

            prevObservation = observation;
            observation = nextObservation;

            if (i + 1 < timeArray.length) {
                nextObservation = collection.getTuple(new OXFFeature(timeseries.getFeatureId(), null),
                        timeArray[i + 1]);
            }

            String obsVal = observation.getValue(0).toString();
            String prevObsVal = prevObservation.getValue(0).toString();
            String nextObsVal = nextObservation.getValue(0).toString();

            if ((i == 0) || // first observation --> in
                    (i == timeArray.length - 1) || // last
                    // observation
                    // -->
                    // in
                    (!(prevObsVal.equals(obsVal)) || !(nextObsVal.equals(obsVal)))) {

                counter++;

                Double resultVal = getValidData(observation.getValue(0).toString());

                // line or sumline
                if (seriesType.equals("1")) {
                    // nothing
                } else if (seriesType.equals("2")) {
                    if (resultVal != null) {
                        resultVal += sum;
                    } else {
                        resultVal = sum;
                    }
                } else {
                    // nothing
                }
                sum = resultVal;

                ITimePosition timePos = (ITimePosition) observation.getTime();
                DateTime time = DateTime.parse(timePos.toISO8601Format());
                timeSeries.add(new FixedMillisecond(time.getMillis()), resultVal);
            }
        }

    } else {
        // all obs
        LOGGER.debug("Compressionlevel none");
        for (int i = 0; i < timeArray.length; i++) {

            prevObservation = observation;
            observation = nextObservation;

            if (i + 1 < timeArray.length) {
                nextObservation = collection.getTuple(new OXFFeature(timeseries.getFeatureId(), null),
                        timeArray[i + 1]);
            }

            String obsVal = observation.getValue(0).toString();

            // if ((i == 0) || // first observation --> in
            // (i == timeArray.length - 1) || // last observation --> in
            // (!(prevObsVal.equals(obsVal) &&
            // nextObsVal.equals(obsVal)))
            // ) {

            counter++;

            Double resultVal = getValidData(observation.getValue(0).toString());

            // line or sumline
            if (seriesType.equals("1")) {
                // nothing
            } else if (seriesType.equals("2")) {
                if (resultVal != null) {
                    resultVal += sum;
                } else {
                    resultVal = sum;
                }
            } else {
                // nothing
            }
            sum = resultVal;

            ITimePosition timePos = (ITimePosition) observation.getTime();
            DateTime time = DateTime.parse(timePos.toISO8601Format());
            timeSeries.add(new FixedMillisecond(time.getMillis()), resultVal);
            // }

        }
    }

    LOGGER.debug("Compressed observations from " + timeArray.length + " to " + counter);

    return timeSeries;

}

From source file:org.n52.server.io.TimeseriesFactory.java

License:Open Source License

public HashMap<Long, Double> compressToHashMap(String foiID, String phenID, String procID)
        throws ParseException {

    HashMap<Long, Double> data = new HashMap<Long, Double>();

    if (collection.getAllTuples().size() > 0) {

        ///*  w ww  .  j  a  va  2 s .c  o m*/
        // now lets put in the date-value pairs.
        // ! But put it only in if it differs from the
        // previous one !
        //

        ITimePosition timeArray[] = collection.getSortedTimeArray();

        ObservedValueTuple prevObservation;
        ObservedValueTuple nextObservation =
                // FIXME aufrumen in der compression wenn bentigt
                collection.getTuple(new OXFFeature(foiID, null), timeArray[0]);
        ObservedValueTuple observation = nextObservation;

        int counter = 0;

        for (int i = 0; i < timeArray.length; i++) {

            prevObservation = observation;
            observation = nextObservation;

            if (i + 1 < timeArray.length) {
                nextObservation = collection.getTuple(new OXFFeature(foiID, null), timeArray[i + 1]);
            }

            Double obsVal = null;
            try {
                obsVal = getValidData(observation.getValue(0).toString());
            } catch (NullPointerException e) {
                LOGGER.debug("Missing observation value: {}.", obsVal, e);
                continue;
            } catch (NumberFormatException e) {
                LOGGER.error("Not a number value: {}.", obsVal, e);
                continue;
            }

            TimePosition timePos = (TimePosition) observation.getTime();
            DateTime time = DateTime.parse(timePos.toISO8601Format());
            data.put(time.getMillis(), obsVal);
            counter++;
        }
        // }

    }

    return data;

}

From source file:org.nodel.reflection.Serialisation.java

License:Mozilla Public License

private static DateTime tryParseISODateTime(String value) {
    try {/*from  w  w w  .  j a  v  a2s . com*/
        return DateTime.parse(value);
    } catch (Exception exc) {
        return null;
    }
}