/** * Open a ucar.nc2.ft.PointFeatureCollection, write out in CF point format. * * @param fileIn open through TypedDatasetFactory.open(FeatureType.POINT, ..) * @param fileOut write to this netcdf-3 file * @param inMemory if true, read file into memory for efficiency * @return true on success * @throws IOException on read/write error */ public static boolean rewritePointFeatureDataset(String fileIn, String fileOut, boolean inMemory) throws IOException { System.out.println("Rewrite2 .nc files from " + fileIn + " to " + fileOut + " inMemory= " + inMemory); long start = System.currentTimeMillis(); // do it in memory for speed NetcdfFile ncfile = inMemory ? NetcdfFile.openInMemory(fileIn) : NetcdfFile.open(fileIn); NetcdfDataset ncd = new NetcdfDataset(ncfile); Formatter errlog = new Formatter(); FeatureDataset fd = FeatureDatasetFactoryManager.wrap(FeatureType.ANY_POINT, ncd, null, errlog); if (fd == null) return false; if (fd instanceof FeatureDatasetPoint) { writePointFeatureCollection((FeatureDatasetPoint) fd, fileOut); fd.close(); long took = System.currentTimeMillis() - start; System.out.println(" that took " + (took - start) + " msecs"); return true; } return false; }
/** * Open a ucar.nc2.ft.PointFeatureCollection, write out in CF point format. * * @param fileIn open through TypedDatasetFactory.open(FeatureType.POINT, ..) * @param fileOut write to this netcdf-3 file * @param inMemory if true, read file into memory for efficiency * @return true on success * @throws IOException on read/write error */ public static boolean rewritePointFeatureDataset(String fileIn, String fileOut, boolean inMemory) throws IOException { System.out.println("Rewrite2 .nc files from " + fileIn + " to " + fileOut + " inMemory= " + inMemory); long start = System.currentTimeMillis(); // do it in memory for speed NetcdfFile ncfile = inMemory ? NetcdfFile.openInMemory(fileIn) : NetcdfFile.open(fileIn); NetcdfDataset ncd = new NetcdfDataset(ncfile); Formatter errlog = new Formatter(); FeatureDataset fd = FeatureDatasetFactoryManager.wrap(FeatureType.ANY_POINT, ncd, null, errlog); if (fd == null) return false; if (fd instanceof FeatureDatasetPoint) { writePointFeatureCollection((FeatureDatasetPoint) fd, fileOut); fd.close(); long took = System.currentTimeMillis() - start; System.out.println(" that took " + (took - start) + " msecs"); return true; } return false; }
/** * Open a ucar.nc2.ft.PointFeatureCollection, write out in CF point format. * * @param fileIn open through TypedDatasetFactory.open(FeatureType.POINT, ..) * @param fileOut write to this netcdf-3 file * @param inMemory if true, read file into memory for efficiency * @return true on success * @throws IOException on read/write error */ public static boolean rewritePointFeatureDataset(String fileIn, String fileOut, boolean inMemory) throws IOException { System.out.println("Rewrite2 .nc files from " + fileIn + " to " + fileOut + " inMemory= " + inMemory); long start = System.currentTimeMillis(); // do it in memory for speed NetcdfFile ncfile = inMemory ? NetcdfFile.openInMemory(fileIn) : NetcdfFile.open(fileIn); NetcdfDataset ncd = new NetcdfDataset(ncfile); Formatter errlog = new Formatter(); FeatureDataset fd = FeatureDatasetFactoryManager.wrap(FeatureType.ANY_POINT, ncd, null, errlog); if (fd == null) return false; if (fd instanceof FeatureDatasetPoint) { writePointFeatureCollection((FeatureDatasetPoint) fd, fileOut); fd.close(); long took = System.currentTimeMillis() - start; System.out.println(" that took " + (took - start) + " msecs"); return true; } return false; }
FeatureDataset featureDataset = FeatureDatasetFactoryManager.wrap(null, ds, null, errlog); info.append("FeatureDatasetFactoryManager errlog = "); info.append(errlog.toString());
FeatureDataset featureDataset = FeatureDatasetFactoryManager.wrap(null, ds, null, errlog); info.append("FeatureDatasetFactoryManager errlog = "); info.append(errlog.toString());
static private FeatureDataset wrapUnknown(NetcdfDataset ncd, ucar.nc2.util.CancelTask task, Formatter errlog) throws IOException { FeatureType ft = findFeatureType(ncd); if (ft != null) return wrap(ft, ncd, task, errlog);
FeatureDataset featureDataset = FeatureDatasetFactoryManager.wrap(null, ds, null, errlog); info.append("FeatureDatasetFactoryManager errlog = "); info.append(errlog.toString());
/** * If this decoder can handle the file content as features, returns handlers for them. * * @return {@inheritDoc} * @throws IOException if an I/O operation was necessary but failed. * @throws DataStoreException if the library of geometric objects is not available. */ @Override @SuppressWarnings("null") public DiscreteSampling[] getDiscreteSampling() throws IOException, DataStoreException { if (features == null && file instanceof NetcdfDataset) { features = FeatureDatasetFactoryManager.wrap(null, (NetcdfDataset) file, this, new Formatter(new LogAdapter(listeners), listeners.getLocale())); } List<FeatureCollection> fc = null; if (features instanceof FeatureDatasetPoint) { fc = ((FeatureDatasetPoint) features).getPointFeatureCollectionList(); } final FeaturesWrapper[] wrappers = new FeaturesWrapper[(fc != null) ? fc.size() : 0]; try { for (int i=0; i<wrappers.length; i++) { wrappers[i] = new FeaturesWrapper(fc.get(i), geomlib, listeners); } } catch (IllegalArgumentException e) { throw new DataStoreException(e.getLocalizedMessage(), e); } return wrappers; }
return wrap(wantFeatureType, ncd, task, errlog);
/** * If this decoder can handle the file content as features, returns handlers for them. * * @return {@inheritDoc} * @throws IOException if an I/O operation was necessary but failed. * @throws DataStoreException if the library of geometric objects is not available. */ @Override @SuppressWarnings("null") public DiscreteSampling[] getDiscreteSampling() throws IOException, DataStoreException { if (features == null && file instanceof NetcdfDataset) { features = FeatureDatasetFactoryManager.wrap(null, (NetcdfDataset) file, this, new Formatter(new LogAdapter(listeners), listeners.getLocale())); } List<FeatureCollection> fc = null; if (features instanceof FeatureDatasetPoint) { fc = ((FeatureDatasetPoint) features).getPointFeatureCollectionList(); } final FeaturesWrapper[] wrappers = new FeaturesWrapper[(fc != null) ? fc.size() : 0]; try { for (int i=0; i<wrappers.length; i++) { wrappers[i] = new FeaturesWrapper(fc.get(i), geomlib, listeners); } } catch (IllegalArgumentException e) { throw new DataStoreException(e.getLocalizedMessage(), e); } return wrappers; }
@Test public void testTryWithWrap() throws IOException { String location = TestDir.cdmLocalTestDataDir + "testWrite.nc"; NetcdfDataset ncd = NetcdfDataset.openDataset(location); Formatter errlog = new Formatter(); try (FeatureDataset fdataset = FeatureDatasetFactoryManager.wrap(null, ncd, null, errlog)) { assert (fdataset == null); } ncd.close(); }
static private FeatureDataset wrapUnknown(NetcdfDataset ncd, ucar.nc2.util.CancelTask task, Formatter errlog) throws IOException { FeatureType ft = findFeatureType(ncd); if (ft != null) return wrap(ft, ncd, task, errlog);
static private FeatureDataset wrapUnknown(NetcdfDataset ncd, ucar.nc2.util.CancelTask task, Formatter errlog) throws IOException { FeatureType ft = findFeatureType(ncd); if (ft != null) return wrap(ft, ncd, task, errlog);
FeatureDataset fd2 = ucar.nc2.ft.FeatureDatasetFactoryManager.wrap(ucar.nc2.constants.FeatureType.STATION, nc2, null, new Formatter(System.out)); assert fd2 != null; // no longer fails System.out.printf("---FeatureDataset not failed%n"); FeatureDataset fd3 = ucar.nc2.ft.FeatureDatasetFactoryManager.wrap(ucar.nc2.constants.FeatureType.STATION, nc3, null, new Formatter(System.out)); assert fd3 != null; System.out.printf("---FeatureDataset not failed %d%n", i); FeatureDataset fd4 = ucar.nc2.ft.FeatureDatasetFactoryManager.wrap(ucar.nc2.constants.FeatureType.STATION, nc4, null, new Formatter(System.err)); assert fd4 != null; System.out.printf("---FeatureDataset not failed%n");
result.featureDataset = FeatureDatasetFactoryManager.wrap(result.featureType, ncd, task, result.errLog);
result.featureDataset = FeatureDatasetFactoryManager.wrap(result.featureType, ncd, task, result.errLog);
@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); } } }
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; }
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; }
result.featureDataset = FeatureDatasetFactoryManager.wrap(result.featureType, ncd, task, result.errLog);