public void addStation( StationFeature s) { stations.add(s); stationHash.put(s.getName(), s); }
public void addStation( StationFeature s) { stations.add(s); stationHash.put(s.getName(), s); }
public StationTimeSeriesFeatureImpl(StationFeature s, CalendarDateUnit timeUnit, String altUnits, int nfeatures) { super(s.getName(), timeUnit, altUnits); this.s = s; if (nfeatures >= 0) { getInfo(); // create the object info.nfeatures = nfeatures; } }
@Override public String makeQuery() { StringBuilder query = new StringBuilder("stns="); for (StationFeature s : getStationHelper().getStationFeatures()) { query.append(s.getName()); query.append(","); } return PointDatasetRemote.makeQuery(query.toString(), boundingBoxSubset, dateRangeSubset); } }
public StationPointFeature deepCopy(StationPointFeature from) throws IOException { StationFeature s = from.getStation(); StationFeatureImpl sUse = stationMap.get(s.getName()); if (sUse == null) { sUse = new StationFeatureImpl(s); stationMap.put(s.getName(), sUse); } sUse.incrNobs(); StationPointFeatureCopy deep = new StationPointFeatureCopy(sUse, from); deep.data = StructureDataDeep.copy(from.getFeatureData(), sm); return deep; }
public StationPointFeature deepCopy(StationPointFeature from) throws IOException { StationFeature s = from.getStation(); StationFeatureImpl sUse = stationMap.get(s.getName()); if (sUse == null) { sUse = new StationFeatureImpl(s); stationMap.put(s.getName(), sUse); } sUse.incrNobs(); StationPointFeatureCopy deep = new StationPointFeatureCopy(sUse, from); deep.data = StructureDataDeep.copy(from.getFeatureData(), sm); return deep; }
public void setStations(List<StationFeature> stns) throws IOException { this.stnList = stns; // see if there's altitude, wmoId for any stations for (StationFeature stn : stnList) { if (!Double.isNaN(stn.getAltitude())) useAlt = true; if ((stn.getWmoId() != null) && (stn.getWmoId().trim().length() > 0)) useWmoId = true; if ((stn.getDescription() != null) && (stn.getDescription().trim().length() > 0)) useDesc = true; // find string lengths id_strlen = Math.max(id_strlen, stn.getName().length()); if (stn.getDescription() != null) desc_strlen = Math.max(desc_strlen, stn.getDescription().length()); if (stn.getWmoId() != null) wmo_strlen = Math.max(wmo_strlen, stn.getWmoId().length()); } llbb = CFPointWriterUtils.getBoundingBox(stnList); // gets written in super.finish(); }
public void setStations(List<StationFeature> stns) throws IOException { this.stnList = stns; // see if there's altitude, wmoId for any stations for (StationFeature stn : stnList) { if (!Double.isNaN(stn.getAltitude())) useAlt = true; if ((stn.getWmoId() != null) && (stn.getWmoId().trim().length() > 0)) useWmoId = true; if ((stn.getDescription() != null) && (stn.getDescription().trim().length() > 0)) useDesc = true; // find string lengths id_strlen = Math.max(id_strlen, stn.getName().length()); if (stn.getDescription() != null) desc_strlen = Math.max(desc_strlen, stn.getDescription().length()); if (stn.getWmoId() != null) wmo_strlen = Math.max(wmo_strlen, stn.getWmoId().length()); } llbb = CFPointWriterUtils.getBoundingBox(stnList); // gets written in super.finish(); }
@Override protected PointFeature makeFeature(int recnum, StructureData sdata) throws IOException { extract.extract(sdata); String stationId = extract.getStationId(); //System.out.printf(" '%s' '%s' (%d) %n", s.getName(), stationId, countRecords++); //if (count > 10) return null; if (!stationId.equals(s.getName())) return null; CalendarDate date = extract.makeCalendarDate(); return new BufrStationPoint(s, date.getMillis(), 0, munger.munge(sdata)); // LOOK obsTime, nomTime } }
for (StationFeature stn : stnList) { writeStationData(stn); stationIndexMap.put(stn.getName(), count); count++;
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(); }
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(); }
for (StationFeature stn : stnList) { writeStationData(stn); stationIndexMap.put(stn.getName(), count); count++;
@Override public PointFeatureIterator getPointFeatureIterator() throws IOException { String query = PointDatasetRemote.makeQuery("stn=" + s.getName(), null, getInfo().getCalendarDateRange(this.getTimeUnit())); InputStream in = null; try { in = CdmRemote.sendQuery(null, uri, query); PointStream.MessageType mtype = PointStream.readMagic(in); if (mtype == PointStream.MessageType.End) { // no obs were found in.close(); return new PointIteratorEmpty(); // return empty iterator } if (mtype != PointStream.MessageType.PointFeatureCollection) { throw new RuntimeException("Station Request: bad response = " + mtype); } int len = NcStream.readVInt(in); byte[] b = new byte[len]; NcStream.readFully(in, b); PointStreamProto.PointFeatureCollection pfc = PointStreamProto.PointFeatureCollection.parseFrom(b); riter = new PointIteratorStream(StationFeatureStream.this, in, new PointStream.ProtobufPointFeatureMaker(pfc)); return riter; } catch (Throwable t) { if (in != null) in.close(); throw new IOException(t.getMessage(), t); } } }
@Test public void test2() throws IOException, NoFactoryFoundException, URISyntaxException { File testFile = new File(getClass().getResource("orthogonal.ncml").toURI()); Comparator<StationPointFeature> reverseStationNameComparator = Ordering.from(SortingStationPointFeatureCache.stationNameComparator).reverse(); SortingStationPointFeatureCache cache = new SortingStationPointFeatureCache(reverseStationNameComparator); cache.addAll(testFile); List<String> expectedStationNames = Arrays.asList("CCC", "BBB", "AAA"); List<String> actualStationNames = new LinkedList<>(); try (PointFeatureIterator iter = cache.getPointFeatureIterator()) { while (iter.hasNext()) { StationPointFeature stationPointFeat = (StationPointFeature) iter.next(); actualStationNames.add(stationPointFeat.getStation().getName()); } } Assert.assertEquals(expectedStationNames, actualStationNames); }
private void writeStationData(StationFeature stn) throws IOException { StructureDataScalar stnCoords = new StructureDataScalar("Coords"); stnCoords.addMember(latName, null, null, DataType.DOUBLE, stn.getLatLon().getLatitude()); stnCoords.addMember(lonName, null, null, DataType.DOUBLE, stn.getLatLon().getLongitude()); if (useAlt) stnCoords.addMember(stationAltName, null, null, DataType.DOUBLE, stn.getAltitude()); stnCoords.addMemberString(stationIdName, null, null, stn.getName().trim(), id_strlen); if (useDesc) stnCoords.addMemberString(descName, null, null, stn.getDescription().trim(), desc_strlen); if (useWmoId) stnCoords.addMemberString(wmoName, null, null, stn.getWmoId().trim(), wmo_strlen); StructureDataComposite sdall = new StructureDataComposite(); sdall.add(stnCoords); // coords first so it takes precedence sdall.add(stn.getFeatureData()); stnRecno = super.writeStructureData(stnRecno, stationStruct, sdall, stationVarMap); }
private void writeStationData(StationFeature stn) throws IOException { StructureDataScalar stnCoords = new StructureDataScalar("Coords"); stnCoords.addMember(latName, null, null, DataType.DOUBLE, false, stn.getLatLon().getLatitude()); stnCoords.addMember(lonName, null, null, DataType.DOUBLE, false, stn.getLatLon().getLongitude()); stnCoords.addMember(stationAltName, null, null, DataType.DOUBLE, false, stn.getAltitude()); stnCoords.addMemberString(stationIdName, null, null, stn.getName().trim(), id_strlen); if (useDesc) stnCoords.addMemberString(descName, null, null, stn.getDescription().trim(), desc_strlen); if (useWmoId) stnCoords.addMemberString(wmoName, null, null, stn.getWmoId().trim(), wmo_strlen); StructureDataComposite sdall = new StructureDataComposite(); sdall.add(stnCoords); // coords first so it takes precedence sdall.add(stn.getFeatureData()); stnRecno = super.writeStructureData(stnRecno, stationStruct, sdall, featureVarMap); }
private void writeStationData(StationFeature stn) throws IOException { StructureDataScalar stnCoords = new StructureDataScalar("Coords"); stnCoords.addMember(latName, null, null, DataType.DOUBLE, false, stn.getLatLon().getLatitude()); stnCoords.addMember(lonName, null, null, DataType.DOUBLE, false, stn.getLatLon().getLongitude()); if (useAlt) stnCoords.addMember(stationAltName, null, null, DataType.DOUBLE, false, stn.getAltitude()); stnCoords.addMemberString(stationIdName, null, null, stn.getName().trim(), id_strlen); if (useDesc) stnCoords.addMemberString(descName, null, null, stn.getDescription().trim(), desc_strlen); if (useWmoId) stnCoords.addMemberString(wmoName, null, null, stn.getWmoId().trim(), wmo_strlen); StructureDataComposite sdall = new StructureDataComposite(); sdall.add(stnCoords); // coords first so it takes precedence sdall.add(stn.getFeatureData()); stnRecno = super.writeStructureData(stnRecno, stationStruct, sdall, stationVarMap); }
private void writeStationData(StationFeature stn) throws IOException { StructureDataScalar stnCoords = new StructureDataScalar("Coords"); stnCoords.addMember(latName, null, null, DataType.DOUBLE, stn.getLatLon().getLatitude()); stnCoords.addMember(lonName, null, null, DataType.DOUBLE, stn.getLatLon().getLongitude()); stnCoords.addMember(stationAltName, null, null, DataType.DOUBLE, stn.getAltitude()); stnCoords.addMemberString(stationIdName, null, null, stn.getName().trim(), id_strlen); if (useDesc) stnCoords.addMemberString(descName, null, null, stn.getDescription().trim(), desc_strlen); if (useWmoId) stnCoords.addMemberString(wmoName, null, null, stn.getWmoId().trim(), wmo_strlen); StructureDataComposite sdall = new StructureDataComposite(); sdall.add(stnCoords); // coords first so it takes precedence sdall.add(stn.getFeatureData()); stnRecno = super.writeStructureData(stnRecno, stationStruct, sdall, featureVarMap); }