Пример #1
0
  public static DateRange extractDateRange(GridDataset gridDataset) {
    DateRange maxDateRange = null;

    for (GridDataset.Gridset gridset : gridDataset.getGridsets()) {
      GridCoordSystem gsys = gridset.getGeoCoordSystem();
      DateRange dateRange;

      CoordinateAxis1DTime time1D = gsys.getTimeAxis1D();
      if (time1D != null) {
        dateRange = time1D.getDateRange();
      } else {
        CoordinateAxis time = gsys.getTimeAxis();
        if (time == null) continue;

        try {
          DateUnit du = new DateUnit(time.getUnitsString());
          Date minDate = du.makeDate(time.getMinValue());
          Date maxDate = du.makeDate(time.getMaxValue());
          dateRange = new DateRange(minDate, maxDate);
        } catch (Exception e) {
          logger.warn("Illegal Date Unit " + time.getUnitsString());
          continue;
        }
      }

      if (maxDateRange == null) maxDateRange = dateRange;
      else maxDateRange.extend(dateRange);
    }

    return maxDateRange;
  }
Пример #2
0
  private boolean filter(PointFeature pdata) {
    if ((filter_date != null) && !filter_date.included(pdata.getObservationTimeAsDate()))
      return false;

    if ((filter_bb != null)
        && !filter_bb.contains(
            pdata.getLocation().getLatitude(), pdata.getLocation().getLongitude())) return false;

    return true;
  }
  /**
   * Open an ADDE Station Dataset from an InvAccess, which must be type ADDE and Station.
   *
   * @param access open Invdataset from this access.
   * @throws IOException
   */
  public AddeStationObsDataset(InvAccess access, ucar.nc2.util.CancelTask cancelTask)
      throws IOException {
    super();
    InvDataset invDs = access.getDataset();
    this.location =
        (invDs.getID() != null)
            ? "thredds:" + access.getDataset().getCatalogUrl()
            : access.getStandardUrlName();

    addeURL = access.getStandardUrlName();

    // see if we have a stationDB file
    InvDataset invds = access.getDataset();
    String pv = invds.findProperty("_StationDBlocation");
    if (pv != null) {
      stationDBlocation = InvDatasetImpl.resolve(invds, pv);
    }

    init();

    // Get the bounding box if possible
    ThreddsMetadata.GeospatialCoverage geoCoverage = invds.getGeospatialCoverage();
    if (null != geoCoverage) boundingBox = geoCoverage.getBoundingBox();
    else // otherwise, stationHelper constructs from the station locations
    boundingBox = stationHelper.getBoundingBox();

    // get the date range if possible
    DateRange timeCoverage = invds.getTimeCoverage();
    if (timeCoverage != null) {
      startDate = timeCoverage.getStart().getDate();
      endDate = timeCoverage.getEnd().getDate();
    } else {
      startDate = new Date(0); // fake
      endDate = new Date();
    }

    /*    // LOOK maybe its already annotated ??
    LOOK set title, description
    ThreddsDataFactory.annotate( access.getDataset(), this);
    finish(); */
  }
Пример #4
0
  protected Element genLonLatEnvelope(GridCoordSystem gcs) {
    // <CoverageOfferingBrief>/lonLatEnvelope
    Element lonLatEnvelopeElem = new Element("lonLatEnvelope", wcsNS);
    lonLatEnvelopeElem.setAttribute("srsName", "urn:ogc:def:crs:OGC:1.3:CRS84");

    LatLonRect llbb = gcs.getLatLonBoundingBox();
    LatLonPoint llpt = llbb.getLowerLeftPoint();
    LatLonPoint urpt = llbb.getUpperRightPoint();

    // <CoverageOfferingBrief>/lonLatEnvelope/gml:pos
    String firstPosition = llpt.getLongitude() + " " + llpt.getLatitude();
    double lon = llpt.getLongitude() + llbb.getWidth();
    String secondPosition = lon + " " + urpt.getLatitude();
    // ToDo WCS 1.0Plus - Add vertical (Deal with conversion to meters. Yikes!!)
    //    CoordinateAxis1D vertAxis = gcs.getVerticalAxis();
    //    if ( vertAxis != null )
    //    {
    //      // See verAxis.getUnitsString()
    //      firstPosition += " " + vertAxis.getCoordValue( 0);
    //      secondPostion += " " + vertAxis.getCoordValue( ((int)vertAxis.getSize()) - 1);
    //    }

    lonLatEnvelopeElem.addContent(new Element("pos", gmlNS).addContent(firstPosition));
    lonLatEnvelopeElem.addContent(new Element("pos", gmlNS).addContent(secondPosition));

    // <CoverageOfferingBrief>/lonLatEnvelope/gml:timePostion [2]
    if (gcs.hasTimeAxis()) {
      DateRange dr = gcs.getDateRange();
      if (dr != null) {
        lonLatEnvelopeElem.addContent(
            new Element("timePosition", gmlNS).addContent(dr.getStart().toDateTimeStringISO()));
        lonLatEnvelopeElem.addContent(
            new Element("timePosition", gmlNS).addContent(dr.getEnd().toDateTimeStringISO()));
      }
    }

    return lonLatEnvelopeElem;
  }
  // check that parms have valid stations, vars and times
  private Boolean checkQueryParms(
      DatasetRepository.RadarType radarType, QueryParams qp, Boolean level2) throws IOException {
    if (qp.hasBB) {
      if (radarType.equals(DatasetRepository.RadarType.nexrad))
        qp.stns = RadarServerUtil.getStationNames(qp.getBB(), DatasetRepository.nexradList);
      else qp.stns = RadarServerUtil.getStationNames(qp.getBB(), DatasetRepository.terminalList);

      if (qp.stns.size() == 0) {
        qp.errs.append("Bounding Box contains no stations ");
        return false;
      }
      if (!level2) qp.stns = RadarServerUtil.convert4to3stations(qp.stns);
    }

    if (qp.hasStns) {
      if (RadarServerUtil.isStationListEmpty(qp.stns, radarType)) {
        qp.errs.append("No valid stations specified, need 1 ");
        return false;
      } else if (level2) {
        for (String stn : qp.stns) {
          if (stn.length() == 3) {
            qp.errs.append("Need 4 character station names ");
            return false;
          }
        }
      } else if (!level2) qp.stns = RadarServerUtil.convert4to3stations(qp.stns);
    }

    if (qp.hasLatlonPoint) {
      qp.stns = new ArrayList<String>();
      if (radarType.equals(DatasetRepository.RadarType.nexrad))
        qp.stns.add(
            RadarServerUtil.findClosestStation(qp.lat, qp.lon, DatasetRepository.nexradList));
      else
        qp.stns.add(
            RadarServerUtil.findClosestStation(qp.lat, qp.lon, DatasetRepository.terminalList));
      if (!level2) qp.stns = RadarServerUtil.convert4to3stations(qp.stns);
    } else if (qp.fatal) {
      qp.errs.append("No valid stations specified 2 ");
      return false;
    }

    if (qp.stns == null || qp.stns.size() == 0) {
      qp.errs.append("No valid stations specified, need 1 ");
      return false;
    }
    boolean useAllStations = (qp.stns.get(0).toUpperCase().equals("ALL"));
    if (useAllStations) {
      if (radarType.equals(DatasetRepository.RadarType.nexrad))
        qp.stns =
            RadarServerUtil.getStationNames(DatasetRepository.nexradList); // need station names
      else
        qp.stns =
            RadarServerUtil.getStationNames(DatasetRepository.terminalList); // need station names
      if (!level2) qp.stns = RadarServerUtil.convert4to3stations(qp.stns);
    }

    if (qp.hasTimePoint) {
      if (qp.time.isPresent()) {
        try {
          qp.time_end = new DateType("present", null, null);
          qp.time_start = epicDateType;
        } catch (java.text.ParseException e) {
          qp.errs.append("Illegal param= 'time' must be valid ISO Duration");
          return false;
        }
      } else {
        qp.time_end = qp.time;
        qp.time_start = qp.time;
      }
    } else if (qp.hasDateRange) {
      DateRange dr = qp.getCalendarDateRange().toDateRange();
      qp.time_start = dr.getStart();
      qp.time_end = dr.getEnd();
    } else { // get all times
      qp.time_latest = 1;
      // qp.hasDateRange = true;
      try {
        qp.time = new DateType("present", null, null);
        qp.time_end = new DateType("present", null, null);
        qp.time_start = epicDateType;
      } catch (java.text.ParseException e) {
        qp.errs.append("Illegal param= 'time' must be valid ISO Duration ");
        return false;
      }
    }

    if (level2) {
      qp.vars = null; // level2 can't select vars
    } else if (qp.vars == null) { // level 3 with no vars
      qp.errs.append("No vars selected ");
      return false;
    } else if (qp.vars.get(0).contains("/")) { // remove desc from vars
      ArrayList<String> tmp = new ArrayList<String>();
      for (String var : qp.vars) {
        tmp.add(var.replaceFirst("/.*", ""));
      }
      qp.vars = tmp;
    }
    return true;
  }