public String getUdUnit() { return dateUnit.getUdUnit(); }
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(); } }
public void writeHeader(PointFeature pf) throws IOException { List<VariableSimpleIF> coords = new ArrayList<>(); coords.add(VariableSimpleImpl.makeScalar(timeName, "time of measurement", timeUnit.getUdUnit(), DataType.DOUBLE) .add(new Attribute(CF.CALENDAR, timeUnit.getCalendar().toString()))); coords.add(VariableSimpleImpl.makeScalar(latName, "latitude of measurement", CDM.LAT_UNITS, DataType.DOUBLE)); coords.add(VariableSimpleImpl.makeScalar(lonName, "longitude of measurement", CDM.LON_UNITS, DataType.DOUBLE)); Formatter coordNames = new Formatter().format("%s %s %s", timeName, latName, lonName); if (altUnits != null) { coords.add( VariableSimpleImpl.makeScalar(altName, "altitude of measurement", altUnits, DataType.DOUBLE) .add(new Attribute(CF.POSITIVE, CF1Convention.getZisPositive(altName, altUnits)))); coordNames.format(" %s", altName); } super.writeHeader(coords, null, pf.getDataAll(), coordNames.toString()); }
private void writeHeader(TrajectoryFeature feature, PointFeature obs) throws IOException { // obs data List<VariableSimpleIF> coords = new ArrayList<>(); coords.add(VariableSimpleImpl.makeScalar(timeName, "time of measurement", timeUnit.getUdUnit(), DataType.DOUBLE) .add(new Attribute(CF.CALENDAR, timeUnit.getCalendar().toString()))); coords.add(VariableSimpleImpl.makeScalar(latName, "latitude of measurement", CDM.LAT_UNITS, DataType.DOUBLE)); coords.add(VariableSimpleImpl.makeScalar(lonName, "longitude of measurement", CDM.LON_UNITS, DataType.DOUBLE)); Formatter coordNames = new Formatter().format("%s %s %s", timeName, latName, lonName); if (altUnits != null) { coords.add( VariableSimpleImpl.makeScalar(altName, "altitude of measurement", altUnits, DataType.DOUBLE) .add(new Attribute(CF.POSITIVE, CF1Convention.getZisPositive(altName, altUnits)))); coordNames.format(" %s", altName); } super.writeHeader(coords, feature.getFeatureData(), obs.getFeatureData(), coordNames.toString()); }
private Element writeTimeUnit(CalendarDateUnit dateUnit) { Element elem = new Element("TimeUnit"); elem.addContent(dateUnit.getUdUnit()); elem.setAttribute("calendar", dateUnit.getCalendar().toString()); return elem; }
coords.add(VariableSimpleImpl.makeScalar(timeName, "time of measurement", timeUnit.getUdUnit(), DataType.DOUBLE) .add(new Attribute(CF.CALENDAR, timeUnit.getCalendar().toString())));
private static StationPointFeature makeStationPointFeature(DsgFeatureCollection dsg, StationFeature stationFeat, CalendarDateUnit timeUnit, double obsTime, double nomTime, double tasmax) { StructureDataScalar featureData = new StructureDataScalar("StationPointFeature"); featureData.addMember("obsTime", "Observation time", timeUnit.getUdUnit(), DataType.DOUBLE, obsTime); featureData.addMember("nomTime", "Nominal time", timeUnit.getUdUnit(), DataType.DOUBLE, nomTime); featureData.addMember("tasmax", "Max temperature", "Celsius", DataType.DOUBLE, tasmax); return new SimpleStationPointFeature(dsg, stationFeat, obsTime, nomTime, timeUnit, featureData); }
protected void makeFeatureVariables(StructureData featureData, boolean isExtended) throws IOException { // LOOK why not unlimited here ? Dimension profileDim = writer.addDimension(null, profileDimName, nfeatures); // Dimension profileDim = isExtendedModel ? writer.addUnlimitedDimension(profileDimName) : writer.addDimension(null, profileDimName, nprofiles); // add the profile Variables using the profile dimension List<VariableSimpleIF> profileVars = new ArrayList<>(); profileVars.add(VariableSimpleImpl.makeScalar(latName, "profile latitude", CDM.LAT_UNITS, DataType.DOUBLE)); profileVars.add(VariableSimpleImpl.makeScalar(lonName, "profile longitude", CDM.LON_UNITS, DataType.DOUBLE)); profileVars.add(VariableSimpleImpl.makeString(profileIdName, "profile identifier", null, id_strlen) .add(new Attribute(CF.CF_ROLE, CF.PROFILE_ID))); // profileId:cf_role = "profile_id"; profileVars.add(VariableSimpleImpl.makeScalar(numberOfObsName, "number of obs for this profile", null, DataType.INT) .add(new Attribute(CF.SAMPLE_DIMENSION, recordDimName))); // rowSize:sample_dimension = "obs" profileVars.add(VariableSimpleImpl.makeScalar(profileTimeName, "nominal time of profile", timeUnit.getUdUnit(), DataType.DOUBLE) .add(new Attribute(CF.CALENDAR, timeUnit.getCalendar().toString()))); for (StructureMembers.Member m : featureData.getMembers()) { VariableSimpleIF dv = getDataVar(m.getName()); if (dv != null) profileVars.add(dv); } if (isExtended) { profileStruct = (Structure) writer.addVariable(null, profileStructName, DataType.STRUCTURE, profileDimName); addCoordinatesExtended(profileStruct, profileVars); } else { addCoordinatesClassic(profileDim, profileVars, featureVarMap); } }
@Override protected void makeMiddleVariables(StructureData profileData, boolean isExtended) throws IOException { Dimension profileDim = writer.addDimension(null, profileDimName, nfeatures); // add the profile Variables using the profile dimension List<VariableSimpleIF> profileVars = new ArrayList<>(); profileVars.add(VariableSimpleImpl.makeString(profileIdName, "profile identifier", null, id_strlen) .add(new Attribute(CF.CF_ROLE, CF.PROFILE_ID)) // profileId:cf_role = "profile_id"; .add(new Attribute(CDM.MISSING_VALUE, String.valueOf(idMissingValue)))); profileVars.add(VariableSimpleImpl.makeScalar(latName, "profile latitude", CDM.LAT_UNITS, DataType.DOUBLE)); profileVars.add(VariableSimpleImpl.makeScalar(lonName, "profile longitude", CDM.LON_UNITS, DataType.DOUBLE)); profileVars.add(VariableSimpleImpl.makeScalar(profileTimeName, "nominal time of profile", timeUnit.getUdUnit(), DataType.DOUBLE) .add(new Attribute(CF.CALENDAR, timeUnit.getCalendar().toString()))); profileVars.add(VariableSimpleImpl.makeScalar(trajectoryIndexName, "trajectory index for this profile", null, DataType.INT) .add(new Attribute(CF.INSTANCE_DIMENSION, trajDimName))); profileVars.add(VariableSimpleImpl.makeScalar(numberOfObsName, "number of obs for this profile", null, DataType.INT) .add(new Attribute(CF.SAMPLE_DIMENSION, recordDimName))); for (StructureMembers.Member m : profileData.getMembers()) { VariableSimpleIF dv = getDataVar(m.getName()); if (dv != null) profileVars.add(dv); } if (isExtended) { profileStruct = (Structure) writer.addVariable(null, profileStructName, DataType.STRUCTURE, profileDimName); addCoordinatesExtended(profileStruct, profileVars); } else { addCoordinatesClassic(profileDim, profileVars, profileVarMap); } }
@Override protected void makeMiddleVariables(StructureData profileData, boolean isExtended) throws IOException { Dimension profileDim = writer.addDimension(null, profileDimName, nfeatures); // add the profile Variables using the profile dimension List<VariableSimpleIF> profileVars = new ArrayList<>(); profileVars.add(VariableSimpleImpl.makeString(profileIdName, "profile identifier", null, id_strlen) .add(new Attribute(CF.CF_ROLE, CF.PROFILE_ID)) // profileId:cf_role = "profile_id"; .add(new Attribute(CDM.MISSING_VALUE, String.valueOf(idMissingValue)))); profileVars.add(VariableSimpleImpl.makeScalar(numberOfObsName, "number of obs for this profile", null, DataType.INT) .add(new Attribute(CF.SAMPLE_DIMENSION, recordDimName))); // rowSize:sample_dimension = "obs" profileVars.add(VariableSimpleImpl.makeScalar(profileTimeName, "nominal time of profile", timeUnit.getUdUnit(), DataType.DOUBLE) .add(new Attribute(CF.CALENDAR, timeUnit.getCalendar().toString()))); profileVars.add(VariableSimpleImpl.makeScalar(stationIndexName, "station index for this profile", null, DataType.INT) .add(new Attribute(CF.INSTANCE_DIMENSION, stationDimName))); for (StructureMembers.Member m : profileData.getMembers()) { VariableSimpleIF dv = getDataVar(m.getName()); if (dv != null) profileVars.add(dv); } if (isExtended) { profileStruct = (Structure) writer.addVariable(null, profileStructName, DataType.STRUCTURE, profileDimName); addCoordinatesExtended(profileStruct, profileVars); } else { addCoordinatesClassic(profileDim, profileVars, profileVarMap); } }
} catch (IllegalArgumentException e) { String message = String.format("Invalid time unit found in stream (%s). Using default (%s).", pfc.getTimeUnit(), this.timeUnit.getUdUnit()); logger.error(message, e);
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; }