コード例 #1
0
ファイル: RsaDatasetProvider.java プロジェクト: sixy6e/rsa
  @Override
  public DatasetMetadata queryMetadata(String uri, String referential) throws IOException {

    DatasetMetadata md = new DatasetMetadata();

    // Coordinate system
    Dataset dataset = findDataset(uri, referential);
    if (dataset == null) {
      throw new IOException(String.format("Could not find dataset %s", uri));
    }
    log.trace("Querying spatial axes of {}", dataset);
    List<TimeSlice> tss = datasetDao.getTimeSlices(dataset.getId());

    GridProjected grid = queryGrid(dataset, tss);
    TimeAxis timeAxis = queryTimeAxis(dataset, tss);
    md.setCsys(new QueryCoordinateSystem(grid, timeAxis));

    // Variable names
    log.trace("Querying variable names of {}", dataset);
    List<String> bandNames = new ArrayList<>();
    for (Band b : datasetDao.getBands(dataset.getId())) {
      bandNames.add(b.getName());
    }
    // In the current RSA, all datasets have coordinate axes (1D variables)
    // x, y and time
    bandNames.add("time");
    bandNames.add("y");
    bandNames.add("x");
    md.setVariables(bandNames);

    return md;
  }
コード例 #2
0
ファイル: RsaDatasetProvider.java プロジェクト: sixy6e/rsa
  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);
  }