public static void main(String args[]) throws IOException { String endpoint = "http://localhost:8080/thredds/cdmrfeature/idd/metar/ncdecodedLocalHome"; FeatureDatasetPoint fd = (FeatureDatasetPoint) CdmrFeatureDataset.factory(FeatureType.ANY, endpoint); FeatureCollection fc = fd.getPointFeatureCollectionList().get(0); System.out.printf("Result= %s %n %s %n", fd, fc); /* StationTimeSeriesFeatureCollection sfc = (StationTimeSeriesFeatureCollection) fc; PointFeatureIterator pfIter = sfc.get(-1); try { while (pfIter.hasNext()) { PointFeature pf = pfIter.next(); System.out.println("pf= " + pf); } } finally { pfIter.finish(); } */ }
public static void main(String args[]) throws IOException { String endpoint = "http://localhost:8080/thredds/cdmrfeature/idd/metar/ncdecodedLocalHome"; FeatureDatasetPoint fd = (FeatureDatasetPoint) CdmrFeatureDataset.factory(FeatureType.ANY, endpoint); FeatureCollection fc = fd.getPointFeatureCollectionList().get(0); System.out.printf("Result= %s %n %s %n", fd, fc); /* StationTimeSeriesFeatureCollection sfc = (StationTimeSeriesFeatureCollection) fc; PointFeatureIterator pfIter = sfc.get(-1); try { while (pfIter.hasNext()) { PointFeature pf = pfIter.next(); System.out.println("pf= " + pf); } } finally { pfIter.finish(); } */ }
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 (CompositeDatasetFactory.debug) System.out.printf("CompositePointFeatureIterator open dataset %s%n", td.getLocation()); List<FeatureCollection> fcList = currentDataset.getPointFeatureCollectionList(); PointFeatureCollection pc = (PointFeatureCollection) fcList.get(0); return pc.getPointFeatureIterator(bufferSize); }
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 (CompositeDatasetFactory.debug) System.out.printf("CompositePointFeatureIterator open dataset %s%n", td.getLocation()); List<FeatureCollection> fcList = currentDataset.getPointFeatureCollectionList(); PointFeatureCollection pc = (PointFeatureCollection) fcList.get(0); return pc.getPointFeatureIterator(bufferSize); }
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 (CompositeDatasetFactory.debug) System.out.printf("CompositePointFeatureIterator open dataset %s%n", td.getLocation()); List<FeatureCollection> fcList = currentDataset.getPointFeatureCollectionList(); PointFeatureCollection pc = (PointFeatureCollection) fcList.get(0); return pc.getPointFeatureIterator(bufferSize); }
public FlattenedDatasetPointIterator(FeatureDatasetPoint fdPoint) { this.dsgFeatColIter = fdPoint.getPointFeatureCollectionList().iterator(); setCalculateBounds(FlattenedDatasetPointCollection.this.getInfo()); }
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 (CompositeDatasetFactory.debug) System.out.printf("CompositePointFeatureIterator open dataset %s%n", td.getLocation()); List<FeatureCollection> fcList = currentDataset.getPointFeatureCollectionList(); PointFeatureCollection pc = (PointFeatureCollection) fcList.get(0); return pc.getPointFeatureIterator(bufferSize); }
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(); }
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<FeatureCollection> fcList = currentDataset.getPointFeatureCollectionList(); StationTimeSeriesFeatureCollection stnCollection = (StationTimeSeriesFeatureCollection) fcList.get(0); PointFeatureCollection pc = null; if (wantStationsubset) pc = stnCollection.flatten(stationsSubset, dateRange, varList); else pc = stnCollection.flatten(bbSubset, dateRange); return pc.getPointFeatureIterator(bufferSize); }
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<FeatureCollection> fcList = currentDataset.getPointFeatureCollectionList(); StationTimeSeriesFeatureCollection stnCollection = (StationTimeSeriesFeatureCollection) fcList.get(0); PointFeatureCollection pc = null; if (wantStationsubset) pc = stnCollection.flatten(stationsSubset, dateRange, varList); else pc = stnCollection.flatten(bbSubset, dateRange); PointFeatureIterator result = pc.getPointFeatureIterator(bufferSize); if (calcBounds) result.setCalculateBounds(pc); // LOOK barf return result; }
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); List<FeatureCollection> fcList = currentDataset.getPointFeatureCollectionList(); StationTimeSeriesFeatureCollection stnCollection = (StationTimeSeriesFeatureCollection) fcList.get(0); Station s = stnCollection.getStation(getName()); if (s == null) { System.out.printf("CompositeStationFeatureIterator dataset: %s missing station %s%n", td.getLocation(), getName()); return getNextIterator(); } StationTimeSeriesFeature stnFeature = stnCollection.getStationFeature(s); if (CompositeDatasetFactory.debug) System.out.printf("CompositeStationFeatureIterator open dataset: %s for %s%n", td.getLocation(), s.getName()); return stnFeature.getPointFeatureIterator(bufferSize); }
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); List<FeatureCollection> fcList = currentDataset.getPointFeatureCollectionList(); StationTimeSeriesFeatureCollection stnCollection = (StationTimeSeriesFeatureCollection) fcList.get(0); Station s = stnCollection.getStation(getName()); if (s == null) { System.out.printf("CompositeStationFeatureIterator dataset: %s missing station %s%n", td.getLocation(), getName()); return getNextIterator(); } StationTimeSeriesFeature stnFeature = stnCollection.getStationFeature(s); if (CompositeDatasetFactory.debug) System.out.printf("CompositeStationFeatureIterator open dataset: %s for %s%n", td.getLocation(), s.getName()); return stnFeature.getPointFeatureIterator(bufferSize); }
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) { System.out.printf("CompositeStationFeatureIterator dataset: %s missing station %s%n", td.getLocation(), getName()); 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(); }
@Test public void testAltUnits() throws Exception { String file = TestDir.cdmLocalTestDataDir + "point/stationRaggedContig.ncml"; Formatter buf = new Formatter(); try (FeatureDatasetPoint pods = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(ucar.nc2.constants.FeatureType.STATION, file, null, buf)) { List<DsgFeatureCollection> collectionList = pods.getPointFeatureCollectionList(); assert (collectionList.size() == 1) : "Can't handle point data with multiple collections"; DsgFeatureCollection fc = collectionList.get(0); assert fc.getAltUnits() != null : "no Alt Units"; assert fc.getAltUnits().equalsIgnoreCase("m") : "Alt Units should be 'm'"; } }
@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.getGlobalAttributes(); return stationHelper; } }
@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)) { StationHelper stationHelper = new StationHelper(); List<FeatureCollection> fcList = openDataset.getPointFeatureCollectionList(); StationTimeSeriesCollectionImpl openCollection = (StationTimeSeriesCollectionImpl) fcList.get(0); List<Station> stns = openCollection.getStations(); for (Station s : stns) { StationTimeSeriesFeature stnFeature = openCollection.getStationFeature(s); stationHelper.addStation(new CompositeStationFeature(s, timeUnit, altUnits, stnFeature.getFeatureData(), this.dataCollection)); } dataVariables = openDataset.getDataVariables(); globalAttributes = openDataset.getGlobalAttributes(); return stationHelper; } }
@Test public void testStationVarRagged() throws Exception { String file = TestDir.cdmLocalTestDataDir + "point/stationRaggedContig.ncml"; Formatter buf = new Formatter(); try (FeatureDatasetPoint pods = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(ucar.nc2.constants.FeatureType.STATION, file, null, buf)) { List<DsgFeatureCollection> collectionList = pods.getPointFeatureCollectionList(); assert (collectionList.size() == 1) : "Can't handle point data with multiple collections"; DsgFeatureCollection fc = collectionList.get(0); assert fc instanceof StationTimeSeriesFeatureCollection; StationTimeSeriesFeatureCollection sc = (StationTimeSeriesFeatureCollection) fc; List<StationFeature> stations = sc.getStationFeatures(); assert (stations.size() == 3) : "Should be 3 stations"; for (Station s : stations) { System.out.printf("%s%n", s); assert !Double.isNaN(s.getAltitude()) : "No altitude on station"; assert s.getDescription() != null && !s.getDescription().isEmpty() : "No description on station"; assert s.getWmoId() != null && !s.getWmoId().isEmpty() : "No wmoId on station"; } } }
@Test public void testStationVarMulti() throws Exception { String file = TestDir.cdmLocalTestDataDir + "point/stationMultidim.ncml"; Formatter buf = new Formatter(); try (FeatureDatasetPoint pods = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(ucar.nc2.constants.FeatureType.STATION, file, null, buf)) { List<DsgFeatureCollection> collectionList = pods.getPointFeatureCollectionList(); assert (collectionList.size() == 1) : "Can't handle point data with multiple collections"; DsgFeatureCollection fc = collectionList.get(0); assert fc instanceof StationTimeSeriesFeatureCollection; StationTimeSeriesFeatureCollection sc = (StationTimeSeriesFeatureCollection) fc; List<StationFeature> stations = sc.getStationFeatures(); assert (stations.size() == 5) : "Should be 5 stations"; for (Station s : stations) { System.out.printf("%s%n", s); assert !Double.isNaN(s.getAltitude()) : "No altitude on station"; assert s.getDescription() != null && !s.getDescription().isEmpty() : "No description on station"; assert s.getWmoId() != null && !s.getWmoId().isEmpty() : "No wmoId on station"; } } }
@Test public void testStationProfileMultidim1dTime() throws IOException { FeatureType type = FeatureType.STATION_PROFILE; String location = TestCFPointDatasets.CFpointObs_topdir + "stationProfileMultidim1dTime.ncml"; ucar.nc2.util.CancelTask task = null; Formatter out = new Formatter(); FeatureDataset featDset = FeatureDatasetFactoryManager.open(type, location, task, out); assert featDset != null && featDset instanceof FeatureDatasetPoint; FeatureDatasetPoint featDsetPoint = (FeatureDatasetPoint) featDset; List<DsgFeatureCollection> featCols = featDsetPoint.getPointFeatureCollectionList(); assert !featCols.isEmpty(); DsgFeatureCollection featCol = featCols.get(0); // We only care about the first one. assert featCol instanceof StationProfileFeatureCollection; StationProfileFeatureCollection stationProfileFeatCol = (StationProfileFeatureCollection) featCol; assert stationProfileFeatCol.hasNext(); StationProfileFeature stationProfileFeat = stationProfileFeatCol.next(); // We only care about the first one. List<CalendarDate> timesList = stationProfileFeat.getTimes(); Set<CalendarDate> timesSet = new TreeSet<>(stationProfileFeat.getTimes()); // Nukes dupes. Assert.assertEquals(timesList.size(), timesSet.size()); // Assert that the times are unique. }
@Test public void testAltUnits() throws Exception { // Ignore this test if NetCDF-4 isn't present. Assume.assumeTrue("NetCDF-4 C library not present.", Nc4Iosp.isClibraryPresent()); String file = TestDir.cdmLocalTestDataDir + "point/stationRaggedContig.ncml"; Formatter buf = new Formatter(); try (FeatureDatasetPoint pods = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(ucar.nc2.constants.FeatureType.STATION, file, null, buf)) { List<DsgFeatureCollection> collectionList = pods.getPointFeatureCollectionList(); assert (collectionList.size() == 1) : "Can't handle point data with multiple collections"; DsgFeatureCollection fc1 = collectionList.get(0); assert fc1.getAltUnits() != null : "no Alt Units"; assert fc1.getAltUnits().equalsIgnoreCase("m") : "Alt Units should be 'm'"; FeatureDatasetPoint rewrite = rewriteDataset(pods, "nc4", new CFPointWriterConfig(NetcdfFileWriter.Version.netcdf4)); collectionList = rewrite.getPointFeatureCollectionList(); DsgFeatureCollection fc2 = collectionList.get(0); assert fc2 instanceof PointFeatureCC; assert fc2.getAltUnits() != null : "no Alt Units"; assert fc2.getAltUnits().equalsIgnoreCase("m") : "Alt Units should be 'm'"; rewrite.close(); } }