ucar.nc2.ft.FeatureDatasetFactoryManager Java Examples
The following examples show how to use
ucar.nc2.ft.FeatureDatasetFactoryManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CFPointObWriter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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; }
Example #2
Source File: CompositePointCollection.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
private PointFeatureIterator getNextIterator() throws IOException { if (!iter.hasNext()) return null; TimedCollection.Dataset td = iter.next(); Formatter errlog = new Formatter(); currentDataset = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(FeatureType.POINT, td.getLocation(), null, errlog); if (currentDataset == null) throw new IllegalStateException("Cant open FeatureDatasetPoint " + td.getLocation()); if (CompositeDatasetFactory.debug) System.out.printf("CompositePointFeatureIterator open dataset %s%n", td.getLocation()); List<DsgFeatureCollection> fcList = currentDataset.getPointFeatureCollectionList(); PointFeatureCollection pc = (PointFeatureCollection) fcList.get(0); return pc.getPointFeatureIterator(); }
Example #3
Source File: CompositePointCollection.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void readMetadata() { // must open a prototype in order to get the data variable TimedCollection.Dataset td = pointCollections.getPrototype(); if (td == null) throw new RuntimeException("No datasets in the collection"); Formatter errlog = new Formatter(); try (FeatureDatasetPoint openDataset = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(FeatureType.POINT, td.getLocation(), null, errlog)) { if (openDataset != null) { dataVariables = openDataset.getDataVariables(); globalAttributes = openDataset.attributes(); } } catch (IOException ioe) { throw new RuntimeException(ioe); } }
Example #4
Source File: CompositeStationCollection.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
private PointFeatureIterator getNextIterator() throws IOException { if (!iter.hasNext()) return null; TimedCollection.Dataset td = iter.next(); Formatter errlog = new Formatter(); currentDataset = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(FeatureType.STATION, td.getLocation(), null, errlog); if (currentDataset == null) throw new IllegalStateException("Cant open FeatureDatasetPoint " + td.getLocation()); List<DsgFeatureCollection> fcList = currentDataset.getPointFeatureCollectionList(); StationTimeSeriesFeatureCollection stnCollection = (StationTimeSeriesFeatureCollection) fcList.get(0); StationFeature s = stnCollection.findStationFeature(getName()); if (s == null) { log.debug("CompositeStationFeatureIterator dataset: {} missing station {}", td.getLocation(), getName()); // close (or just release if cache is enabled) current dataset and check for station in // next dataset in collection currentDataset.close(); return getNextIterator(); } StationTimeSeriesFeature stnFeature = stnCollection.getStationTimeSeriesFeature(s); if (CompositeDatasetFactory.debug) System.out.printf("CompositeStationFeatureIterator open dataset: %s for %s%n", td.getLocation(), s.getName()); return stnFeature.getPointFeatureIterator(); }
Example #5
Source File: RadarDataInventory.java From tds with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { try (RadialDatasetSweep rds = (RadialDatasetSweep) FeatureDatasetFactoryManager.open(FeatureType.RADIAL, file.toString(), null, new Formatter())) { if (rds == null) { return FileVisitResult.CONTINUE; } EarthLocation loc = rds.getCommonOrigin(); if (loc == null) { return FileVisitResult.CONTINUE; } StationList.Station added = stations.addStation(rds.getRadarID(), loc.getLatLon()); added.setElevation(loc.getAltitude()); added.setName(rds.getRadarName()); return FileVisitResult.TERMINATE; } catch (IOException e) { return FileVisitResult.CONTINUE; } }
Example #6
Source File: TableAnalyzer.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
public boolean featureTypeOk(FeatureType ftype, Formatter errlog) { for (NestedTable nt : leaves) { if (!nt.hasCoords()) { errlog.format("Table %s featureType %s: lat/lon/time coord not found%n", nt.getName(), nt.getFeatureType()); writeConfigXML(errlog); } if (!FeatureDatasetFactoryManager.featureTypeOk(ftype, nt.getFeatureType())) errlog.format("Table %s featureType %s doesnt match desired type %s%n", nt.getName(), nt.getFeatureType(), ftype); if (nt.hasCoords() && FeatureDatasetFactoryManager.featureTypeOk(ftype, nt.getFeatureType())) return true; } return false; }
Example #7
Source File: UnidataPointObs.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
public boolean isMine(FeatureType wantFeatureType, NetcdfDataset ds) { if ((wantFeatureType != FeatureType.ANY_POINT) && (wantFeatureType != FeatureType.STATION) && (wantFeatureType != FeatureType.POINT)) return false; FeatureType ft = FeatureDatasetFactoryManager.findFeatureType(ds); if (((ft != FeatureType.STATION) && (ft != FeatureType.POINT))) return false; String conv = ds.getRootGroup().findAttributeString(CDM.CONVENTIONS, null); if (conv == null) return false; StringTokenizer stoke = new StringTokenizer(conv, ","); while (stoke.hasMoreTokens()) { String toke = stoke.nextToken().trim(); if (toke.equalsIgnoreCase("Unidata Observation Dataset v1.0")) return true; } return false; }
Example #8
Source File: DecoderWrapper.java From sis with Apache License 2.0 | 6 votes |
/** * 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; }
Example #9
Source File: TestGridAsPointP.java From tds with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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); } }
Example #10
Source File: TestGridAsPointP.java From tds with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void checkGridAsPointNetcdfOld(byte[] content, String varName) throws JDOMException, IOException { // 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); } }
Example #11
Source File: CdmRemoteController.java From tds with BSD 3-Clause "New" or "Revised" License | 5 votes |
@RequestMapping(value = "/**", method = RequestMethod.GET, params = "req=capabilities") public ModelAndView handleCapabilitiesRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { if (!allowedServices.isAllowed(StandardService.cdmRemote)) throw new ServiceNotAllowed(StandardService.cdmRemote.toString()); String datasetPath = TdsPathUtils.extractPath(request, "/cdmremote"); String absPath = getAbsolutePath(request); try (NetcdfFile ncfile = TdsRequestedDataset.getNetcdfFile(request, response, datasetPath)) { if (ncfile == null) return null; Element rootElem = new Element("cdmRemoteCapabilities"); Document doc = new Document(rootElem); rootElem.setAttribute("location", absPath); Element elem = new Element("featureDataset"); FeatureType ftFromMetadata = FeatureDatasetFactoryManager.findFeatureType(ncfile); // LOOK BAD - must figure out // what is the featureType and // save it if (ftFromMetadata != null) elem.setAttribute("type", ftFromMetadata.toString()); elem.setAttribute("url", absPath); rootElem.addContent(elem); return new ModelAndView("threddsXmlView", "Document", doc); } }
Example #12
Source File: TestGridAsPointP.java From tds with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void checkGridAsPointNetcdfNew(byte[] content, String varName) throws JDOMException, IOException { // Open the binary response in memory Formatter errlog = new Formatter(); try (NetcdfFile nf = NetcdfFiles.openInMemory("checkGridAsPointNetcdf.nc", content)) { FeatureDataset fd = FeatureDatasetFactoryManager.wrap(FeatureType.STATION, NetcdfDatasets.enhance(nf, NetcdfDataset.getDefaultEnhanceMode(), null), null, errlog); assertNotNull(errlog.toString(), fd); VariableSimpleIF v = fd.getDataVariable(varName); assertNotNull(varName, v); } }
Example #13
Source File: NcCollectionTypeTest.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testCreateCollection() throws Exception { File pointFile = new File(getClass().getResource("multiStationMultiVar.ncml").toURI()); try (FeatureDatasetPoint fdPoint = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(FeatureType.STATION, pointFile.getAbsolutePath(), null, new Formatter())) { MarshallingUtil.marshalPointDataset(fdPoint, new ByteArrayOutputStream()); } }
Example #14
Source File: ThreddsDataFactory.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
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) { Optional<FeatureDataset> opt = CdmrFeatureDataset.factory(wantFeatureType, access.getStandardUrlName()); if (opt.isPresent()) result.featureDataset = opt.get(); else result.errLog.format("%s", opt.getErrorMessage()); } 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(); result.featureType = result.featureDataset.getFeatureType(); } return result; }
Example #15
Source File: TestConventionFeatureTypes.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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()); } } }
Example #16
Source File: TestCFRadial.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private RadialDatasetSweep arrayLatLonData() throws IOException { String filename = TestDir.cdmUnitTestDir + "conventions/cfradial/cfrad.20171127_202111.203_to_20171127_202123.085_DOW7_v275_s04_el7.00_SUR.nc"; System.out.printf("arrayLatLonData= %s%n", filename); Formatter buf = new Formatter(); return (RadialDatasetSweep) FeatureDatasetFactoryManager.open(FeatureType.RADIAL, filename, null, buf); }
Example #17
Source File: TestRadialDatasetNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testDates() throws IOException { String fullpath = TestDir.cdmUnitTestDir + filename; Formatter errlog = new Formatter(); RadialDatasetSweep rds = (RadialDatasetSweep) FeatureDatasetFactoryManager.open(FeatureType.RADIAL, fullpath, null, errlog); Assert.assertEquals(start, rds.getCalendarDateStart()); Assert.assertEquals(end, rds.getCalendarDateEnd()); }
Example #18
Source File: TestFeatureDatasetFactory.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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); } }
Example #19
Source File: DataFactory.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private DataFactory.Result openFeatureDataset(FeatureType wantFeatureType, Access 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().getType() == ServiceType.CdmrFeature) { Optional<FeatureDataset> opt = CdmrFeatureDataset.factory(wantFeatureType, access.getStandardUrlName()); if (opt.isPresent()) result.featureDataset = opt.get(); else result.errLog.format("%s", opt.getErrorMessage()); } 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(); result.featureType = result.featureDataset.getFeatureType(); } return result; }
Example #20
Source File: TableAnalyzer.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void checkIfTrajectory(TableConfig st) { // deal with possible trajectory - only do this if dataset has metadata FeatureType ft = FeatureDatasetFactoryManager.findFeatureType(ds); if (ft == FeatureType.TRAJECTORY) { st.featureType = FeatureType.TRAJECTORY; TableConfig pc = new TableConfig(Table.Type.Top, "single"); st.parent = pc; pc.addChild(st); } else st.featureType = FeatureType.POINT; }
Example #21
Source File: CompositeStationCollection.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override protected StationHelper createStationHelper() throws IOException { TimedCollection.Dataset td = dataCollection.getPrototype(); if (td == null) throw new RuntimeException("No datasets in the collection"); Formatter errlog = new Formatter(); try (FeatureDatasetPoint openDataset = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(FeatureType.STATION, td.getLocation(), null, errlog)) { if (openDataset == null) throw new IllegalStateException("Cant open FeatureDatasetPoint " + td.getLocation()); StationHelper stationHelper = new StationHelper(); List<DsgFeatureCollection> fcList = openDataset.getPointFeatureCollectionList(); StationTimeSeriesCollectionImpl openCollection = (StationTimeSeriesCollectionImpl) fcList.get(0); List<StationFeature> stns = openCollection.getStationFeatures(); for (StationFeature stnFeature : stns) { stationHelper.addStation(new CompositeStationFeature(stnFeature, timeUnit, altUnits, stnFeature.getFeatureData(), this.dataCollection)); } dataVariables = openDataset.getDataVariables(); globalAttributes = openDataset.attributes(); return stationHelper; } }
Example #22
Source File: CompositeStationCollectionFlattened.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private PointFeatureIterator getNextIterator() throws IOException { if (!iter.hasNext()) return null; TimedCollection.Dataset td = iter.next(); Formatter errlog = new Formatter(); // open the next dataset currentDataset = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(FeatureType.STATION, td.getLocation(), null, errlog); if (currentDataset == null) { logger.error("FeatureDatasetFactoryManager failed to open: " + td.getLocation() + " \nerrlog = " + errlog); return getNextIterator(); } if (CompositeDatasetFactory.debug) System.out.printf("CompositeStationCollectionFlattened.Iterator open new dataset: %s%n", td.getLocation()); // it will have a StationTimeSeriesFeatureCollection List<DsgFeatureCollection> fcList = currentDataset.getPointFeatureCollectionList(); StationTimeSeriesFeatureCollection stnCollection = (StationTimeSeriesFeatureCollection) fcList.get(0); PointFeatureCollection pc; if (wantStationsubset) { pc = stnCollection.flatten(stationsSubset, dateRange, varList); } else if (bbSubset == null) { pc = stnCollection.flatten(null, dateRange, null); } else { List<StationFeature> stations = stnCollection.getStationFeatures(bbSubset); List<String> names = new ArrayList<>(); for (StationFeature s : stations) names.add(s.getName()); pc = stnCollection.flatten(names, dateRange, null); } return pc.getPointFeatureIterator(); }
Example #23
Source File: CFPointWriter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void main(String[] args) throws Exception { String progName = CFPointWriter.class.getName(); try { CommandLine cmdLine = new CommandLine(progName, args); if (cmdLine.help) { cmdLine.printUsage(); return; } FeatureType wantFeatureType = FeatureType.ANY_POINT; String location = cmdLine.inputFile.getAbsolutePath(); CancelTask cancel = null; Formatter errlog = new Formatter(); try (FeatureDatasetPoint fdPoint = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(wantFeatureType, location, cancel, errlog)) { if (fdPoint == null) { System.err.println(errlog); } else { System.out.printf("CFPointWriter: reading from %s, writing to %s%n", cmdLine.inputFile, cmdLine.outputFile); writeFeatureCollection(fdPoint, cmdLine.outputFile.getAbsolutePath(), cmdLine.getCFPointWriterConfig()); System.out.println("Done."); } } } catch (ParameterException e) { System.err.println(e.getMessage()); System.err.printf("Try \"%s --help\" for more information.%n", progName); } }
Example #24
Source File: CompositeDatasetFactory.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static FeatureDataset factory(String location, FeatureType wantFeatureType, MFileCollectionManager dcm, Formatter errlog) throws IOException { TimedCollection collection = new TimedCollection(dcm, errlog); if (collection.getDatasets().isEmpty()) { throw new FileNotFoundException("Collection is empty; spec=" + dcm); } DsgFeatureCollection first; TimedCollection.Dataset d = collection.getPrototype(); try (FeatureDatasetPoint proto = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(wantFeatureType, d.getLocation(), null, errlog)) { if (proto == null) { throw new FileNotFoundException("Collection dataset is not a FeatureDatasetPoint; spec=" + dcm); } if (wantFeatureType == FeatureType.ANY_POINT) wantFeatureType = proto.getFeatureType(); List<DsgFeatureCollection> fcList = proto.getPointFeatureCollectionList(); if (fcList.isEmpty()) { throw new FileNotFoundException("FeatureCollectionList is empty; spec=" + dcm); } first = fcList.get(0); // LatLonRect bb = null; DsgFeatureCollection fc; switch (wantFeatureType) { case POINT: PointFeatureCollection firstPc = (PointFeatureCollection) first; CompositePointCollection pfc = new CompositePointCollection(dcm.getCollectionName(), firstPc.getTimeUnit(), firstPc.getAltUnits(), collection); // bb = pfc.getBoundingBox(); fc = pfc; break; case STATION: PointFeatureCC firstNpc = (PointFeatureCC) first; CompositeStationCollection sfc = new CompositeStationCollection(dcm.getCollectionName(), firstNpc.getTimeUnit(), firstNpc.getAltUnits(), collection); // bb = sfc.getBoundingBox(); fc = sfc; break; default: return null; } return new CompositePointDataset(location, wantFeatureType, fc, collection, null); } }
Example #25
Source File: TestCompositeStationCollectionsWithCaches.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void testOpenFileHandles() throws IOException { if (checkRafCache) { if (RandomAccessFile.getGlobalFileCache() != null) { RandomAccessFile.getGlobalFileCache().enable(); } else { RandomAccessFile.enableDefaultGlobalFileCache(); } } else { RandomAccessFile.getGlobalFileCache().clearCache(true); RandomAccessFile.shutdown(); // RandomAccessFile.getGlobalFileCache().disable(); } if (checkNetcdfFileCache) { // FeatureCollections still use NetcdfDataset, so work with that cache. NetcdfDataset.getNetcdfFileCache().enable(); } else { NetcdfDataset.getNetcdfFileCache().clearCache(true); NetcdfDataset.getNetcdfFileCache().disable(); } // open the collection String collection = ucar.nc2.ft.point.collection.CompositeDatasetFactory.SCHEME + TestDir.cdmUnitTestDir + "/ft/station/gempak/collection_with_missing_station_features/#yyMMdd#.sf$"; FeatureDataset fds = FeatureDatasetFactoryManager.open(FeatureType.STATION, collection, null, null); assertThat(fds instanceof FeatureDatasetPoint); FeatureDatasetPoint fdp = (FeatureDatasetPoint) fds; // the collection dataset should have one feature collection, and it should // be a CompositeStationCollection assertThat(fdp.getPointFeatureCollectionList()).hasSize(1); DsgFeatureCollection dfc = fdp.getPointFeatureCollectionList().get(0); assertThat(dfc instanceof CompositeStationCollection); CompositeStationCollection csc = (CompositeStationCollection) dfc; // now it gets tricky. We have to tickle the PointFeatureIterator for each station trigger // the bug, but the iterator is hidden within the station collection because the collection // is made up of multiple files. Here, we use the StationHelper to get at the PointFeatureIterator // at the individual file level of the collection. StationHelper helper = csc.createStationHelper(); List<Station> stations = helper.getStations(); // Ensure the RandomAccessFile cache does not contain any locked files if (checkRafCache) { testRafCache(); } if (checkNetcdfFileCache) { testNetcdfFileCache(); } // Now, iterate over the stations. Each station cycles through one or more files of the collection, // and the bug is that the file isn't closed or released if it does not contain the given station. for (int station = 0; station < 2; station++) { // Get the PointFeatureIterator for the given station PointFeatureIterator pointFeatureIterator = ((StationTimeSeriesFeature) stations.get(station)).getPointFeatureIterator(); // all we have to do is call .hasNext(), and if not, the underlying code will cycle through the // datasets of the collection but not close them pointFeatureIterator.hasNext(); pointFeatureIterator.close(); } if (checkRafCache) { testRafCache(); } if (checkNetcdfFileCache) { testNetcdfFileCache(); } }
Example #26
Source File: TestCFRadial.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private RadialDatasetSweep rhiData() throws IOException { String filename = TestDir.cdmUnitTestDir + "conventions/cfradial/cfrad.20140717_003008.286_to_20140717_003049.699_SPOL_v140_rhi_sim_RHI.nc"; Formatter buf = new Formatter(); return (RadialDatasetSweep) FeatureDatasetFactoryManager.open(FeatureType.RADIAL, filename, null, buf); }
Example #27
Source File: TestCFRadial.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private RadialDatasetSweep oneDData() throws IOException { String filename = TestDir.cdmUnitTestDir + "conventions/cfradial/cfrad.20140608_220305.809_to_20140608_220710.630_KFTG_v348_Surveillance_SUR.nc"; Formatter buf = new Formatter(); return (RadialDatasetSweep) FeatureDatasetFactoryManager.open(FeatureType.RADIAL, filename, null, buf); }
Example #28
Source File: SortingStationPointFeatureCache.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void addAll(File datasetFile) throws IOException { try (FeatureDatasetPoint fdPoint = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(FeatureType.STATION, datasetFile.getAbsolutePath(), null, new Formatter())) { addAll(fdPoint); } }
Example #29
Source File: DatasetManager.java From tds with BSD 3-Clause "New" or "Revised" License | 4 votes |
public FeatureDatasetPoint openPointDataset(HttpServletRequest req, HttpServletResponse res, String reqPath) throws IOException { // first look for a feature collection DataRootManager.DataRootMatch match = dataRootManager.findDataRootMatch(reqPath); if ((match != null) && (match.dataRoot.getFeatureCollection() != null)) { // see if its under resource control if (!resourceAuthorized(req, res, match.dataRoot.getRestrict())) return null; FeatureCollectionRef featCollection = match.dataRoot.getFeatureCollection(); if (log.isDebugEnabled()) log.debug(" -- DatasetHandler found FeatureCollection= " + featCollection); InvDatasetFeatureCollection fc = featureCollectionCache.get(featCollection); FeatureDatasetPoint fd = fc.getPointDataset(match.remaining); if (fd == null) throw new IllegalArgumentException("Not a Point Dataset " + fc.getName()); return fd; } // fetch it as a NetcdfFile; this deals with possible NcML NetcdfFile ncfile = openNetcdfFile(req, res, reqPath); if (ncfile == null) return null; Formatter errlog = new Formatter(); NetcdfDataset ncd = null; try { if (useNetcdfJavaBuilders || isLocationObjectStore(ncfile.getLocation())) { ncd = NetcdfDatasets.enhance(ncfile, NetcdfDataset.getDefaultEnhanceMode(), null); } else { ncd = NetcdfDataset.wrap(ncfile, NetcdfDataset.getDefaultEnhanceMode()); } return (FeatureDatasetPoint) FeatureDatasetFactoryManager.wrap(FeatureType.ANY_POINT, ncd, null, errlog); } catch (Throwable t) { if (ncd == null) ncfile.close(); else ncd.close(); if (t instanceof IOException) throw (IOException) t; String msg = ncd == null ? "Problem wrapping NetcdfFile in NetcdfDataset; " : "Problem calling FeatureDatasetFactoryManager; "; msg += errlog.toString(); log.error("openGridDataset(): " + msg, t); throw new IOException(msg + t.getMessage()); } }
Example #30
Source File: DatasetManager.java From tds with BSD 3-Clause "New" or "Revised" License | 4 votes |
public SimpleGeometryFeatureDataset openSimpleGeometryDataset(HttpServletRequest req, HttpServletResponse res, String reqPath) throws IOException { // first look for a feature collection DataRootManager.DataRootMatch match = dataRootManager.findDataRootMatch(reqPath); if ((match != null) && (match.dataRoot.getFeatureCollection() != null)) { // see if its under resource control if (!resourceAuthorized(req, res, match.dataRoot.getRestrict())) return null; FeatureCollectionRef featCollection = match.dataRoot.getFeatureCollection(); if (log.isDebugEnabled()) log.debug(" -- DatasetHandler found FeatureCollection= " + featCollection); InvDatasetFeatureCollection fc = featureCollectionCache.get(featCollection); SimpleGeometryFeatureDataset fd = fc.getSimpleGeometryDataset(match.remaining); if (fd == null) throw new IllegalArgumentException("Not a Simple Geometry Dataset " + fc.getName()); return fd; } // fetch it as a NetcdfFile; this deals with possible NcML NetcdfFile ncfile = openNetcdfFile(req, res, reqPath); if (ncfile == null) return null; Formatter errlog = new Formatter(); NetcdfDataset ncd = null; try { if (useNetcdfJavaBuilders || isLocationObjectStore(ncfile.getLocation())) { ncd = NetcdfDatasets.enhance(ncfile, NetcdfDataset.getDefaultEnhanceMode(), null); } else { ncd = NetcdfDataset.wrap(ncfile, NetcdfDataset.getDefaultEnhanceMode()); } return (SimpleGeometryFeatureDataset) FeatureDatasetFactoryManager.wrap(FeatureType.SIMPLE_GEOMETRY, ncd, null, errlog); } catch (Throwable t) { if (ncd == null) ncfile.close(); else ncd.close(); if (t instanceof IOException) throw (IOException) t; String msg = ncd == null ? "Problem wrapping NetcdfFile in NetcdfDataset; " : "Problem calling FeatureDatasetFactoryManager; "; msg += errlog.toString(); log.error("openSimpleGeometryDataset(): " + msg, t); throw new IOException(msg + t.getMessage()); } }