Skip to content

Commit

Permalink
Handle opening datasetScan with NcML as a coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tdrwenski committed Dec 19, 2023
1 parent 2daae43 commit a9ba11a
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions tds/src/main/java/thredds/core/DatasetManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public NetcdfFile openNetcdfFile(HttpServletRequest req, HttpServletResponse res
}

private boolean hasDatasetScanNcml(DataRootMatch match) {
return match.dataRoot != null && match.dataRoot.getDatasetScan() != null
return match != null && match.dataRoot != null && match.dataRoot.getDatasetScan() != null
&& match.dataRoot.getDatasetScan().getNcmlElement() != null;
}

Expand Down Expand Up @@ -422,8 +422,14 @@ public CoverageCollection openCoverageDataset(HttpServletRequest req, HttpServle
}

// otherwise, assume it's a local file with a datasetRoot in the urlPath.
// try to open as a FeatureDatasetCoverage. This allows GRIB to be handled specially
String location = getLocationFromRequestPath(reqPath);

// Ncml in datasetScan
if (location != null && hasDatasetScanNcml(match)) {
return openCoverageFromDatasetScanNcml(location, match, reqPath);
}

// try to open as a FeatureDatasetCoverage. This allows GRIB to be handled specially
if (location != null) {
Optional<FeatureDatasetCoverage> opt = CoverageDatasetFactory.openCoverageDataset(location);
// hack - CoverageDatasetFactory bombs out on an object store location string during the grib check,
Expand Down Expand Up @@ -453,6 +459,20 @@ public CoverageCollection openCoverageDataset(HttpServletRequest req, HttpServle
return null;
}

private CoverageCollection openCoverageFromDatasetScanNcml(String location, DataRootMatch match, String reqPath)
throws IOException {
final NetcdfFile ncf = openNcmlDatasetScan(location, match);
final NetcdfDataset ncd = NetcdfDatasets.enhance(ncf, NetcdfDataset.getDefaultEnhanceMode(), null);
final DtCoverageDataset gds = new DtCoverageDataset(ncd);

if (gds.getGrids().isEmpty()) {
throw new FileNotFoundException("Error opening grid dataset " + reqPath + ". err= no grids found.");
}

final FeatureDatasetCoverage coverage = DtCoverageAdapter.factory(gds, new Formatter());
return coverage.getSingleCoverageCollection();
}

public SimpleGeometryFeatureDataset openSimpleGeometryDataset(HttpServletRequest req, HttpServletResponse res,
String reqPath) throws IOException {
// first look for a feature collection
Expand Down

0 comments on commit a9ba11a

Please sign in to comment.