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); }
sf.format("%nPointFeatureCollection %d %n", count); PointFeatureCollection pfc = (PointFeatureCollection) fc; sf.format(" %s %s %n", pfc.getCollectionFeatureType(), pfc.getName()); sf.format(" npts = %d %n", pfc.size()); sf.format(" bb = %s %n", pfc.getBoundingBox() == null ? "" : pfc.getBoundingBox().toString2()); sf.format(" dates = %s %n", pfc.getCalendarDateRange()); List<Variable> extra = pfc.getExtraVariables(); if (extra.size() > 0) { sf.format(" extra variables = "); sf.format("%n"); sf.format(" timeUnit = %s %n", pfc.getTimeUnit()); sf.format(" altUnit = %s %n", pfc.getAltUnits());
private static int writePointFeatureCollection(FeatureDatasetPoint fdpoint, PointFeatureCollection pfc, String fileOut, CFPointWriterConfig config) throws IOException { try (WriterCFPointCollection pointWriter = new WriterCFPointCollection(fileOut, fdpoint.getGlobalAttributes(), fdpoint.getDataVariables(), pfc.getExtraVariables(), pfc.getTimeUnit(), pfc.getAltUnits(), config)) { int count = 0; pfc.resetIteration(); while(pfc.hasNext()) { PointFeature pf = pfc.next(); if (count == 0) pointWriter.writeHeader(pf); pointWriter.writeRecord(pf, pf.getFeatureData()); count++; if (debug && count % 100 == 0) System.out.printf("%d ", count); if (debug && count % 1000 == 0) System.out.printf("%n "); } pointWriter.finish(); return count; } }
public static int write(PointFeatureCollection pointFeatCol, File outFile) throws IOException { String name = outFile.getCanonicalPath(); String timeUnitString = pointFeatCol.getTimeUnit().getUdUnit(); String altUnits = pointFeatCol.getAltUnits(); PointFeatureIterator pointFeatIter = pointFeatCol.getPointFeatureIterator(); try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outFile))) { return write(out, pointFeatIter, name, timeUnitString, altUnits); } finally { pointFeatIter.close(); } }
static int countObs(PointFeatureCollection pfc) throws IOException { int count = 0; pfc.resetIteration(); while (pfc.hasNext()) { PointFeature pf = pfc.next(); StructureData sd = pf.getDataAll(); count++; } return count; }
protected void finishCalcBounds() { if (!calcBounds) return; if ((bb != null) && bb.crossDateline() && (bb.getWidth() > 350.0)) { // call it global - less confusing double lat_min = bb.getLowerLeftPoint().getLatitude(); double deltaLat = bb.getUpperLeftPoint().getLatitude() - lat_min; bb = new LatLonRect(new LatLonPointImpl(lat_min, -180.0), deltaLat, 360.0); } if (collection != null) { if (collection.getBoundingBox() == null) collection.setBoundingBox(bb); if (collection.getCalendarDateRange() == null) { CalendarDateRange dr = getCalendarDateRange(); if (dr != null) collection.setCalendarDateRange(dr); } if (collection.size() <= 0) { if (count < 0) count = 0; collection.setSize(count); } } }
static int checkPointFeatureCollectionBB(PointFeatureCollection pfc, boolean show) throws IOException { if (show) { System.out.printf("----------- testPointFeatureCollection -----------------%n"); System.out.println(" test PointFeatureCollection " + pfc.getName()); System.out.println(" calcBounds"); System.out.println(" bb= " + pfc.getBoundingBox()); System.out.println(" dateRange= " + pfc.getCalendarDateRange()); System.out.println(" npts= " + pfc.size()); int n = pfc.size(); if (n == 0) { System.out.println(" empty " + pfc.getName()); return 0; // empty LatLonRect bb = pfc.getBoundingBox(); assert bb != null; CalendarDateRange dr = pfc.getCalendarDateRange(); assert dr != null; int count = 0; for (PointFeature pf : pfc) { checkPointFeature(pf, pfc.getTimeUnit()); if (!bb.contains(pf.getLocation().getLatLon())) System.out.printf(" point not in BB = %s on %s %n", pf.getLocation().getLatLon(), pfc.getName()); System.out.printf(" date out of Range= %s on %s %n", pf.getObservationTimeAsCalendarDate(), pfc.getName()); count++; PointFeatureCollection subset = pfc.subset(bb2, null);
public static boolean equals(PointFeatureCollection featCol1, PointFeatureCollection featCol2) throws IOException { if (featCol1 == featCol2) { return true; } else if (featCol1 == null || featCol2 == null) { return false; } // We must do this comparison first because some PointFeatureCollection implementations, e.g. // PointCollectionStreamAbstract, won't have final values for getTimeUnit() and getAltUnits() until // getPointFeatureIterator() is called. if (!equals(featCol1.getPointFeatureIterator(), featCol2.getPointFeatureIterator())) { return false; } if (!Objects.deepEquals(featCol1.getCollectionFeatureType(), featCol2.getCollectionFeatureType())) { return false; } else if (!Objects.deepEquals(featCol1.getTimeUnit().getUdUnit(), featCol2.getTimeUnit().getUdUnit())) { return false; } else if (!Objects.deepEquals(featCol1.getAltUnits(), featCol2.getAltUnits())) { return false; } // We don't care about FeatureCollection.getName(); it's an implementation detail. // We're also not going to worry about getExtraVariables(), since that method will likely be moved to // FeatureDatasetPoint in NetCDF-Java 5.0. return true; }
@Override public void getDetailInfo(java.util.Formatter sf) { super.getDetailInfo(sf); int count = 0; for (FeatureCollection fc : collectionList) { sf.format("%nFeatureCollection %d %n", count++); if (fc instanceof PointFeatureCollection) { PointFeatureCollection pfc = (PointFeatureCollection) fc; sf.format(" %s %s\n", pfc.getCollectionFeatureType(), pfc.getName()); sf.format(" npts = %d %n", pfc.size()); sf.format(" bb = %s %n", pfc.getBoundingBox() == null ? "" : pfc.getBoundingBox().toString2()); sf.format(" dates = %s %n", pfc.getDateRange() == null ? "" : pfc.getDateRange().toString()); } else if (fc instanceof StationTimeSeriesFeatureCollection) { StationTimeSeriesFeatureCollection npfc = (StationTimeSeriesFeatureCollection) fc; sf.format(" %s %s\n", npfc.getCollectionFeatureType(), npfc.getName()); sf.format(" npts = %d %n", npfc.size()); sf.format(" bb = %s %n", npfc.getBoundingBox() == null ? "" : npfc.getBoundingBox().toString2()); // sf.format(" dates = %s %n", npfc.getDateRange() == null ? "" : npfc.getDateRange().toString()); } } }
pfc.calcBounds(); if (bb == null) bb = pfc.getBoundingBox(); else bb.extend(pfc.getBoundingBox()); if (dates == null) dates = pfc.getCalendarDateRange(); else dates.extend(pfc.getCalendarDateRange()); pfc.calcBounds(); if (dates == null) dates = pfc.getCalendarDateRange(); else dates.extend(pfc.getCalendarDateRange());
private static int writePointFeatureCollection(FeatureDatasetPoint fdpoint, PointFeatureCollection pfc, String fileOut, CFPointWriterConfig config) throws IOException { try (WriterCFPointCollection pointWriter = new WriterCFPointCollection(fileOut, fdpoint.getGlobalAttributes(), fdpoint.getDataVariables(), pfc.getTimeUnit(), pfc.getAltUnits(), config)) { pointWriter.setExtraVariables( pfc.getExtraVariables()); int count = 0; for (PointFeature pf : pfc) { if (count == 0) pointWriter.writeHeader(pf); pointWriter.writeRecord(pf, pf.getFeatureData()); count++; if (debug && count % 100 == 0) System.out.printf("%d ", count); if (debug && count % 1000 == 0) System.out.printf("%n "); } pointWriter.finish(); return count; } }
private static int writePointFeatureCollection(FeatureDatasetPoint fdpoint, PointFeatureCollection pfc, String fileOut, NetcdfFileWriter.Version version) throws IOException { if (debug) System.out.printf("write to file %s%n ", fileOut); WriterCFPointCollection writer = new WriterCFPointCollection(version, fileOut, fdpoint.getGlobalAttributes()); int count = 0; while (pfc.hasNext()) { PointFeature pf = pfc.next(); if (count == 0) { writer.writeHeader(fdpoint.getDataVariables(), pf.getTimeUnit(), null); } writer.writeRecord(pf, pf.getData()); count++; if (debug && count % 100 == 0) System.out.printf("%d ", count); if (debug && count % 1000 == 0) System.out.printf("%n "); } writer.finish(); return count; }
case POINT: PointFeatureCollection firstPc = (PointFeatureCollection) first; CompositePointCollection pfc = new CompositePointCollection(dcm.getCollectionName(), firstPc.getTimeUnit(), firstPc.getAltUnits(), collection);
public CalendarDateRange getCalendarDateRange() { if (!calcBounds) return null; if (collection.getTimeUnit() == null) return null; return CalendarDateRange.of(collection.getTimeUnit().makeCalendarDate(minTime), collection.getTimeUnit().makeCalendarDate(maxTime)); }
countLocations(pfc); LatLonRect bb = pfc.getBoundingBox(); LatLonRect bb2 = new LatLonRect(bb.getLowerLeftPoint(), bb.getHeight() / 2, bb.getWidth() / 2); PointFeatureCollection subset = pfc.subset(bb2, (CalendarDateRange) null); countLocations(subset);
static int countLocations(PointFeatureCollection pfc) throws IOException { int count = 0; Set<MyLocation> locs = new HashSet<>(80000); pfc.resetIteration(); while (pfc.hasNext()) { PointFeature pf = pfc.next(); MyLocation loc = new MyLocation(pf.getLocation()); if (!locs.contains(loc)) locs.add(loc); count++; //if (count % 1000 == 0) System.out.printf("Count %d%n", count); } System.out.printf("Count Points = %d Unique points = %d %n", count, locs.size()); return locs.size(); //The problem is that all the locations are coming up with the same value. This: //always returns the same lat/lon/alt (of the first observation). //(pos was populated going through the PointFeatureIterator). }
protected void finishCalcBounds() { if (!calcBounds) return; if ((bb != null) && bb.crossDateline() && (bb.getWidth() > 350.0)) { // call it global - less confusing double lat_min = bb.getLowerLeftPoint().getLatitude(); double deltaLat = bb.getUpperLeftPoint().getLatitude() - lat_min; bb = new LatLonRect(new LatLonPointImpl(lat_min, -180.0), deltaLat, 360.0); } if (collection != null) { if (collection.getBoundingBox() == null) collection.setBoundingBox(bb); if (collection.getCalendarDateRange() == null) { CalendarDateRange dr = getCalendarDateRange(); if (dr != null) collection.setCalendarDateRange(dr); } if (collection.size() <= 0) { if (count < 0) count = 0; collection.setSize(count); } } }
pfc.calcBounds(); if (bb == null) bb = pfc.getBoundingBox(); else bb.extend(pfc.getBoundingBox()); if (dates == null) dates = pfc.getCalendarDateRange(); else dates.extend(pfc.getCalendarDateRange()); pfc.calcBounds(); if (dates == null) dates = pfc.getCalendarDateRange(); else dates.extend(pfc.getCalendarDateRange());
private static int writeStationFeatureCollection(FeatureDatasetPoint fdpoint, StationTimeSeriesFeatureCollection fds, String fileOut, NetcdfFileWriter.Version version) throws IOException { if (debug) System.out.printf("write to file %s%n ", fileOut); WriterCFStationCollection writer = new WriterCFStationCollection(version, fileOut, fdpoint.getGlobalAttributes()); ucar.nc2.ft.PointFeatureCollection pfc = fds.flatten(null, (CalendarDateRange) null); int count = 0; while (pfc.hasNext()) { PointFeature pf = pfc.next(); if (count == 0) { writer.writeHeader(fds.getStations(), fdpoint.getDataVariables(), pf.getTimeUnit(), ""); } StationPointFeature spf = (StationPointFeature) pf; writer.writeRecord(spf.getStation(), pf, pf.getData()); count++; if (debug && count % 100 == 0) System.out.printf("%d ", count); if (debug && count % 1000 == 0) System.out.printf("%n "); } writer.finish(); return count; }
case POINT: PointFeatureCollection firstPc = (PointFeatureCollection) first; CompositePointCollection pfc = new CompositePointCollection(dcm.getCollectionName(), firstPc.getTimeUnit(), firstPc.getAltUnits(), collection);