featureType = featureDataset.getFeatureType(); if (featureType != null) ftype = featureType.toString(); ftImpl = featureDataset.getImplementationName(); Formatter infof = new Formatter(); featureDataset.getDetailInfo(infof); info.append(infof.toString()); } else {
@Override public void close() throws IOException { if (featureDataset != null) featureDataset.close(); } }
private ThreddsDataFactory.Result openFeatureDataset(FeatureType wantFeatureType, InvAccess access, ucar.nc2.util.CancelTask task, Result result) throws IOException { result.featureType = wantFeatureType; result.accessUsed = access; // special handling for IMAGE if (result.featureType == FeatureType.IMAGE) { result.imageURL = access.getStandardUrlName(); result.location = result.imageURL; return result; } if (access.getService().getServiceType() == ServiceType.CdmrFeature) { result.featureDataset = CdmrFeatureDataset.factory(wantFeatureType, access.getStandardUrlName()); } else { // all other datatypes NetcdfDataset ncd = openDataset(access, true, task, result); if (null != ncd) { result.featureDataset = FeatureDatasetFactoryManager.wrap(result.featureType, ncd, task, result.errLog); } } if (null == result.featureDataset) result.fatalError = true; else { result.location = result.featureDataset.getLocation(); if ((result.featureType == null) && (result.featureDataset != null)) result.featureType = result.featureDataset.getFeatureType(); } return result; }
/** * Tests a non-CF compliant trajectory file * * This tests a non-CF compliant trajectory file * which is read in using the ucar.nc2.ft.point.standard.plug.SimpleTrajectory * plug. */ @Test public void testSimpleTrajectory() throws IOException { FeatureType type = FeatureType.ANY; Path location_path = Paths.get(TestDir.cdmLocalTestDataDir, "trajectory", "aircraft", "uw_kingair-2005-01-19-113957.nc"); FeatureDataset featureDataset = FeatureDatasetFactoryManager.open(type, location_path.toString(), null, null); assert featureDataset != null; assert featureDataset.getFeatureType() == FeatureType.TRAJECTORY; }
public static int checkPointFeatureDataset(String location, FeatureType type, boolean show) throws IOException { File fileIn = new File(location); String absIn = fileIn.getCanonicalPath(); absIn = StringUtil2.replace(absIn, "\\", "/"); System.out.printf("================ TestPointFeatureCollection read %s %n", absIn); Formatter out = new Formatter(); try (FeatureDataset fdataset = FeatureDatasetFactoryManager.open(type, location, null, out)) { if (fdataset == null) { System.out.printf("**failed on %s %n --> %s %n", location, out); assert false; } // FeatureDataset if (showAll) { System.out.printf("----------- testPointDataset getDetailInfo -----------------%n"); fdataset.getDetailInfo(out); System.out.printf("%s %n", out); } else { System.out.printf(" Feature Type %s %n", fdataset.getFeatureType()); } return checkPointFeatureDataset(fdataset, show); } }
try (FeatureDataset fd = FeatureDatasetFactoryManager.open(FeatureType.ANY_POINT, tempFile.getPath(), null, errlog)) { Assert.assertNotNull(tempFile.getPath(), fd); Assert.assertEquals(FeatureType.STATION, fd.getFeatureType()); Assert.assertNotNull(covName, fd.getDataVariable(covName));
int count = 0; CalendarDate d1 = fdataset.getCalendarDateStart(); CalendarDate d2 = fdataset.getCalendarDateEnd(); if ((d1 != null) && (d2 != null)) Assert.assertTrue("calendar date min <= max", d1.isBefore(d2) || d1.equals(d2)); List<VariableSimpleIF> dataVars = fdataset.getDataVariables(); Assert.assertNotNull("fdataset.getDataVariables()", dataVars); for (VariableSimpleIF v : dataVars) { Assert.assertNotNull(v.getShortName(), fdataset.getDataVariable(v.getShortName()));
result.getDetailInfo(out); System.out.printf("%s %n", out);
@Test public void writeGridAsPointNetcdf() throws JDOMException, IOException { String endpoint = TestOnLocalServer.withHttpPath(ds+"?var="+varName+query+"&accept=netcdf"); File tempFile = tempFolder.newFile(); logger.debug(" write {} to {}", endpoint, tempFile.getAbsolutePath()); try (HTTPSession session = HTTPFactory.newSession(endpoint)) { HTTPMethod method = HTTPFactory.Get(session); int statusCode = method.execute(); if (statusCode != 200) { logger.debug("statusCode = {} '{}'", statusCode, method.getResponseAsString()); return; } IO.appendToFile(method.getResponseAsStream(), tempFile.getAbsolutePath()); } logger.debug(" file length {} bytes exists={} {}", tempFile.length(), tempFile.exists(), tempFile.getAbsolutePath()); // Open the result file as Station feature dataset Formatter errlog = new Formatter(); try (FeatureDataset fd = FeatureDatasetFactoryManager.open(FeatureType.STATION, tempFile.getAbsolutePath(), null, errlog)) { assertNotNull(errlog.toString(), fd); VariableSimpleIF v = fd.getDataVariable(varName); assertNotNull(varName, v); } }
private ThreddsDataFactory.Result openFeatureDataset(FeatureType wantFeatureType, InvAccess access, ucar.nc2.util.CancelTask task, Result result) throws IOException { result.featureType = wantFeatureType; result.accessUsed = access; // special handling for IMAGE if (result.featureType == FeatureType.IMAGE) { result.imageURL = access.getStandardUrlName(); result.location = result.imageURL; return result; } if (access.getService().getServiceType() == ServiceType.CdmrFeature) { result.featureDataset = CdmrFeatureDataset.factory(wantFeatureType, access.getStandardUrlName()); } else { // all other datatypes NetcdfDataset ncd = openDataset(access, true, task, result); if (null != ncd) { result.featureDataset = FeatureDatasetFactoryManager.wrap(result.featureType, ncd, task, result.errLog); } } if (null == result.featureDataset) result.fatalError = true; else { result.location = result.featureDataset.getLocation(); if ((result.featureType == null) && (result.featureDataset != null)) result.featureType = result.featureDataset.getFeatureType(); } return result; }
@Test public void testFeatureDatasets() throws IOException { for (File f : getAllFilesInDirectoryStandardFilter(dir)) { logger.debug("Open FeatureDataset {}", f.getPath()); try (FeatureDataset fd = FeatureDatasetFactoryManager.open(type, f.getPath(), null, new Formatter())) { Assert.assertNotNull(f.getPath(), fd); if (type == FeatureType.GRID) Assert.assertTrue(f.getPath(), fd.getFeatureType().isCoverageFeatureType()); else if (type == FeatureType.POINT) Assert.assertTrue(f.getPath(), fd.getFeatureType().isPointFeatureType()); } } }
@Test public void checkGridAsPointNetcdf() throws JDOMException, IOException { String endpoint = TestOnLocalServer.withHttpPath(ds+"?var="+varName+query+"&accept=netcdf"); byte[] content = TestOnLocalServer.getContent(endpoint, 200, ContentType.netcdf); Assert.assertNotNull(content); logger.debug("return size = {}", content.length); // Open the binary response in memory Formatter errlog = new Formatter(); try (NetcdfFile nf = NetcdfFile.openInMemory("checkGridAsPointNetcdf.nc", content)) { FeatureDataset fd = FeatureDatasetFactoryManager.wrap(FeatureType.STATION, new NetcdfDataset(nf), null, errlog); assertNotNull(errlog.toString(), fd); VariableSimpleIF v = fd.getDataVariable(varName); assertNotNull(varName, v); } } }
result.fatalError = true; else { result.location = result.featureDataset.getLocation(); result.featureType = result.featureDataset.getFeatureType();
featureType = featureDataset.getFeatureType(); if (featureType != null) ftype = featureType.toString(); ftImpl = featureDataset.getImplementationName(); Formatter infof = new Formatter(); featureDataset.getDetailInfo(infof); info.append(infof.toString()); } else {
/** * Closes the netCDF file. * * @throws IOException if an error occurred while closing the file. */ @Override public void close() throws IOException { if (features != null) { features.close(); features = null; } file.close(); }
@Test public void testOpen() throws IOException, InvalidRangeException { System.out.printf("FeatureDatasetFactoryManager.open %s%n", ds); Formatter errlog = new Formatter(); try (FeatureDataset fd = FeatureDatasetFactoryManager.open(what, ds, null, errlog)) { Assert.assertNotNull(errlog.toString()+" "+ds, fd); if (fd.getFeatureType().isCoverageFeatureType()) testCoverage(ds); } }
result.fatalError = true; else { result.location = result.featureDataset.getLocation(); result.featureType = result.featureDataset.getFeatureType();
featureType = featureDataset.getFeatureType(); if (featureType != null) ftype = featureType.toString(); ftImpl = featureDataset.getImplementationName(); Formatter infof = new Formatter(); featureDataset.getDetailInfo(infof); info.append(infof.toString()); } else {
/** * Closes the netCDF file. * * @throws IOException if an error occurred while closing the file. */ @Override public void close() throws IOException { if (features != null) { features.close(); features = null; } file.close(); }
@Test public void testOpenFromDataFactory() throws IOException { DataFactory fac = new DataFactory(); try (DataFactory.Result result = fac.openFeatureDataset(path, null)) { if (result.fatalError) { logger.debug("Dataset fatalError = {}", result.errLog); assert false; } else { logger.debug("Dataset '{}' opened as type = {}", path, result.featureDataset.getFeatureType()); Assert.assertEquals(expectService, result.accessUsed.getService().getType()); Assert.assertEquals(expectFeature, result.featureDataset.getFeatureType()); } } } }