Exemplo n.º 1
0
  private GridProjected queryGrid(Dataset dataset, List<TimeSlice> tss) throws IOException {

    // Create a bounding box that encompasses all time slices.
    Box smbounds = timeSliceUtil.aggregateBounds(tss);
    if (smbounds == null) throw new IOException("Could not determine bounds: no time slices.");

    BoxReal bounds = new BoxReal(2);
    bounds.getMin().setX(smbounds.getXMin());
    bounds.getMin().setY(smbounds.getYMin());
    bounds.getMax().setX(smbounds.getXMax());
    bounds.getMax().setY(smbounds.getYMax());

    // Resolution.
    double cellSize = dataset.getResolution().toDouble();
    VectorReal resolution = VectorReal.createEmpty(2);
    resolution.setX(cellSize);
    resolution.setY(cellSize);

    // All files for a given dataset share a common coordinate system. So,
    // we can just open one of the blank files and take a peek at it.
    CoordinateSystem srs = null;
    List<Band> bands = datasetDao.getBands(dataset.getId());
    for (Band b : bands) {
      Path blankTilePath = bandUtil.getBlankTilePath(dataset, b);
      if (Files.notExists(blankTilePath)) continue;

      NetcdfDataset ncd = NetcdfDataset.openDataset(blankTilePath.toString());
      try {
        ncd.enhance();
        srs = ncd.getCoordinateSystems().get(0);
        break;
      } finally {
        ncd.close();
      }
    }
    if (srs == null) {
      throw new IOException(
          String.format(
              "Could not determine "
                  + "coordinate system for dataset %s. There may be no "
                  + "tiles, or the bounds in the database may not match the "
                  + "tiles stored on disk.",
              dataset));
    }

    return new GridProjected(bounds, resolution, srs);
  }
Exemplo n.º 2
0
  @Override
  public NetcdfDataset open(
      String uri,
      String referential,
      BoxReal boundsHint,
      DateTime timeMin,
      DateTime timeMax,
      List<String> bands)
      throws IOException {

    NetcdfDataset ds;
    VectorReal min = boundsHint.getMin();
    VectorReal max = boundsHint.getMax();
    Box bounds = new Box(min.getX(), min.getY(), max.getX(), max.getY());

    Dataset dataset = findDataset(uri, referential);
    if (dataset == null) {
      throw new IOException(String.format("Could not find dataset %s", uri));
    }

    if (ndgConfigManager.getConfig().isFilelockingOn()) {
      ReadWriteLock lock = getLock(dataset);

      // If filelockingOn, then ensure can get all required read locks
      if (lock.readLock().tryLock()) {
        try {
          ds = open(uri, dataset, bounds, timeMin, timeMax, bands);
          try {
            ds = new RsaNetcdfDataset(ds, lock);
          } catch (IOException | RuntimeException e) {
            if (ds != null) ds.close();
            throw e;
          }
        } catch (IOException | RuntimeException e) {
          lock.readLock().unlock();
          throw e;
        }
      } else {
        throw new IOException(String.format("Could not lock dataset %s", uri));
      }

    } else {
      ds = open(uri, dataset, bounds, timeMin, timeMax, bands);
    }
    return ds;
  }