ucar.nc2.ft.FeatureDatasetPoint Java Examples

The following examples show how to use ucar.nc2.ft.FeatureDatasetPoint. 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: PointSubsetWriterNetcdf.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public PointSubsetWriterNetcdf(FeatureDatasetPoint fdPoint, SubsetParams ncssParams, NcssDiskCache ncssDiskCache,
    OutputStream out, Version version) throws NcssException, IOException {
  super(fdPoint, ncssParams);

  this.ncssDiskCache = ncssDiskCache;
  this.out = out;
  this.version = version;

  this.netcdfResult = ncssDiskCache.getDiskCache().createUniqueFile("ncss-point", ".nc");
  List<Attribute> attribs = new ArrayList<>();
  attribs.add(new Attribute(CDM.TITLE, "Extracted data from TDS Feature Collection " + fdPoint.getLocation()));

  // get the timeUnit and altUnit from the first FeatureCollection
  assert fdPoint.getPointFeatureCollectionList().size() > 0;
  DsgFeatureCollection fc = fdPoint.getPointFeatureCollectionList().get(0);
  CalendarDateUnit timeUnit = fc.getTimeUnit();
  String altUnit = fc.getAltUnits();

  this.cfWriter = new WriterCFPointCollection(netcdfResult.getAbsolutePath(), attribs, wantedVariables, timeUnit,
      altUnit, new CFPointWriterConfig(version));
}
 
Example #2
Source File: CompositeStationCollection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #3
Source File: MetadataExtractor.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static ThreddsMetadata.Variables extractVariables(FeatureDatasetPoint fd) {
  ThreddsMetadata.Variables vars = new ThreddsMetadata.Variables("CF-1.5");
  List<VariableSimpleIF> dataVars = fd.getDataVariables();
  if (dataVars == null)
    return vars;

  for (VariableSimpleIF v : dataVars) {
    ThreddsMetadata.Variable tv = new ThreddsMetadata.Variable();
    vars.addVariable(tv);

    tv.setName(v.getShortName());
    tv.setDescription(v.getDescription());
    tv.setUnits(v.getUnitsString());

    ucar.nc2.Attribute att = v.findAttributeIgnoreCase("standard_name");
    if (att != null)
      tv.setVocabularyName(att.getStringValue());
  }
  vars.sort();
  return vars;
}
 
Example #4
Source File: FlattenedDatasetPointCollection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Constructs a FlattenedDatasetPointCollection.
 *
 * @param fdPoint a point dataset.
 * @throws IllegalArgumentException if any of the feature collections in the dataset are not of type
 *         {@code PointFeatureCollection} or {@code NestedPointFeatureCollection}.
 */
public FlattenedDatasetPointCollection(FeatureDatasetPoint fdPoint) throws IllegalArgumentException {
  super(fdPoint.getLocation(), CalendarDateUnit.unixDateUnit, null); // Default dateUnit and altUnits.
  this.fdPoint = fdPoint;

  List<DsgFeatureCollection> featCols = fdPoint.getPointFeatureCollectionList();

  if (!featCols.isEmpty()) {
    DsgFeatureCollection firstFeatCol = featCols.get(0);

    // Replace this.dateUnit, this.altUnits, and this.extras with "typical" values from firstFeatCol.
    // We can't be certain that those values are representative of ALL collections in the dataset, but it's
    // a decent bet because in practice, firstFeatCol is so often the ONLY collection.
    copyFieldsFrom(firstFeatCol);
  }
}
 
Example #5
Source File: PointConfigXML.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void writeConfigXML(FeatureDatasetPoint pfd, java.util.Formatter f) {
  if (!(pfd instanceof PointDatasetStandardFactory.PointDatasetStandard)) {
    f.format("%s not instance of PointDatasetStandard%n", pfd.getLocation());
    return;
  }
  PointDatasetStandardFactory.PointDatasetStandard spfd = (PointDatasetStandardFactory.PointDatasetStandard) pfd;
  TableAnalyzer analyser = spfd.getTableAnalyzer();
  TableConfig config = analyser.getTableConfig();
  TableConfigurer tc = analyser.getTableConfigurer();
  if (tc == null) {
    f.format("%s has no TableConfig%n", pfd.getLocation());
    return;
  }

  PointConfigXML writer = new PointConfigXML();
  try {
    writer.writeConfigXML(config, tc.getClass().getName(), f);
  } catch (Exception e) {
    f.format("%s error writing=%s%n", pfd.getLocation(), e.getMessage());
  }
}
 
Example #6
Source File: CompositePointCollection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #7
Source File: DecoderWrapper.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #8
Source File: CompositePointCollection.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #9
Source File: InvDatasetFcPoint.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
InvDatasetFcPoint(FeatureCollectionRef parent, FeatureCollectionConfig config) {
  super(parent, config);
  makeCollection();

  Formatter errlog = new Formatter();
  try {
    fd = (FeatureDatasetPoint) CompositeDatasetFactory.factory(name, fcType.getFeatureType(), datasetCollection,
        errlog);

  } catch (Exception e) {

    if (e.getCause() != null)
      throw new RuntimeException("Failed to create InvDatasetFcPoint, cause=", e.getCause());
    else
      throw new RuntimeException("Failed to create InvDatasetFcPoint", e);
  }

  state = new State(null);
  this.wantDatasets = config.pointConfig.datasets;
}
 
Example #10
Source File: CFPointWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Write a FeatureDatasetPoint to a netcd3/4 file.
 *
 * @param fdpoint the FeatureDatasetPoint; do first FeatureCollection contained within.
 * @param fileOut write to the is file
 * @param config configuration
 * @return count of number of pointFeatures written.
 */
public static int writeFeatureCollection(FeatureDatasetPoint fdpoint, String fileOut, CFPointWriterConfig config)
    throws IOException {
  for (DsgFeatureCollection fc : fdpoint.getPointFeatureCollectionList()) {
    if (fc instanceof PointFeatureCollection) {
      return writePointFeatureCollection(fdpoint, (PointFeatureCollection) fc, fileOut, config);

    } else if (fc instanceof StationTimeSeriesFeatureCollection) {
      return writeStationFeatureCollection(fdpoint, (StationTimeSeriesFeatureCollection) fc, fileOut, config);

    } else if (fc instanceof ProfileFeatureCollection) {
      return writeProfileFeatureCollection(fdpoint, (ProfileFeatureCollection) fc, fileOut, config);

    } else if (fc instanceof TrajectoryFeatureCollection) {
      return writeTrajectoryFeatureCollection(fdpoint, (TrajectoryFeatureCollection) fc, fileOut, config);

    } else if (fc instanceof StationProfileFeatureCollection) {
      return writeStationProfileFeatureCollection(fdpoint, (StationProfileFeatureCollection) fc, fileOut, config);

    } else if (fc instanceof TrajectoryProfileFeatureCollection) {
      return writeTrajectoryProfileFeatureCollection(fdpoint, (TrajectoryProfileFeatureCollection) fc, fileOut,
          config);
    }
  }
  return 0;
}
 
Example #11
Source File: CFPointWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static int writePointFeatureCollection(FeatureDatasetPoint fdpoint, PointFeatureCollection pfc,
    String fileOut, CFPointWriterConfig config) throws IOException {

  try (WriterCFPointCollection pointWriter = new WriterCFPointCollection(fileOut, fdpoint.attributes(),
      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;
  }
}
 
Example #12
Source File: NcssPointController.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@RequestMapping(value = {"**/dataset.xml", "**/pointDataset.xml"})
public ModelAndView getDatasetDescriptionXml(HttpServletRequest req, HttpServletResponse res) throws IOException {
  String datasetPath = getDatasetPath(req);

  try (FeatureDatasetPoint fdp = TdsRequestedDataset.getPointDataset(req, res, datasetPath)) {
    if (fdp == null)
      return null; // restricted dataset

    String datasetUrlPath = buildDatasetUrl(datasetPath);
    SupportedOperation supportedOperation = getSupportedOperation(fdp);

    FeatureDatasetCapabilitiesWriter xmlWriter = new FeatureDatasetCapabilitiesWriter(fdp, datasetUrlPath);
    Document doc = xmlWriter.getCapabilitiesDocument();
    Element root = doc.getRootElement();
    root.setAttribute("location", datasetUrlPath);
    root.addContent(makeAcceptXML(supportedOperation)); // must add the accept elements

    return new ModelAndView("threddsXmlView", "Document", doc);
  }
}
 
Example #13
Source File: NcssGridController.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void handleRequestGridAsPoint(HttpServletResponse res, NcssGridParamsBean params, String datasetPath,
    CoverageCollection gcd) throws Exception {
  SupportedFormat sf = SupportedOperation.POINT_REQUEST.getSupportedFormat(params.getAccept());

  CoverageAsPoint covp = new CoverageAsPoint(gcd, params.getVar(), params.makeSubset(gcd));
  try (FeatureDatasetPoint fd = covp.asFeatureDatasetPoint()) {

    // all subsetting is done in CoverageAsPoint
    // SubsetParams ncssParams = params.makeSubset(gcd);
    SubsetParams ncssParams =
        new SubsetParams().set(SubsetParams.timeAll, true).set(SubsetParams.variables, params.getVar());
    DsgSubsetWriter pds =
        DsgSubsetWriterFactory.newInstance(fd, ncssParams, ncssDiskCache, res.getOutputStream(), sf);
    setResponseHeaders(res, pds.getHttpHeaders(datasetPath, sf.isStream()));
    pds.respond(res, fd, datasetPath, ncssParams, sf);
  }
}
 
Example #14
Source File: DsgSubsetWriterFactory.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static DsgSubsetWriter newInstance(FeatureDatasetPoint fdPoint, SubsetParams ncssParams,
    NcssDiskCache ncssDiskCache, OutputStream out, SupportedFormat format)
    throws NcssException, XMLStreamException, IOException {
  FeatureType featureType = fdPoint.getFeatureType();

  if (!featureType.isPointFeatureType()) {
    throw new NcssException(String.format("Expected a point feature type, not %s", featureType));
  }

  switch (featureType) {
    case POINT:
      return newPointInstance(fdPoint, ncssParams, ncssDiskCache, out, format);
    case STATION:
      return newStationInstance(fdPoint, ncssParams, ncssDiskCache, out, format);
    default:
      throw new UnsupportedOperationException(String.format("%s feature type is not yet supported.", featureType));
  }
}
 
Example #15
Source File: StationSubsetWriterNetcdf.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public StationSubsetWriterNetcdf(FeatureDatasetPoint fdPoint, SubsetParams ncssParams, NcssDiskCache ncssDiskCache,
    OutputStream out, NetcdfFileWriter.Version version) throws NcssException, IOException {
  super(fdPoint, ncssParams);

  this.ncssDiskCache = ncssDiskCache;
  this.out = out;
  this.version = version;

  this.netcdfResult = ncssDiskCache.getDiskCache().createUniqueFile("ncss-station", ".nc");
  List<Attribute> attribs = new ArrayList<>();
  attribs.add(new Attribute(CDM.TITLE, "Extracted data from TDS Feature Collection " + fdPoint.getLocation()));

  // get the timeUnit and altUnit from the first FeatureCollection
  assert fdPoint.getPointFeatureCollectionList().size() > 0;
  DsgFeatureCollection fc = fdPoint.getPointFeatureCollectionList().get(0);
  CalendarDateUnit timeUnit = fc.getTimeUnit();
  String altUnit = fc.getAltUnits();

  this.cfWriter = new WriterCFStationCollection(netcdfResult.getAbsolutePath(), attribs, wantedVariables, timeUnit,
      altUnit, new CFPointWriterConfig(version));
}
 
Example #16
Source File: DsgSubsetWriterFactory.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static DsgSubsetWriter newPointInstance(FeatureDatasetPoint fdPoint, SubsetParams ncssParams,
    NcssDiskCache ncssDiskCache, OutputStream out, SupportedFormat format)
    throws XMLStreamException, NcssException, IOException {
  switch (format) {
    case XML_STREAM:
    case XML_FILE:
      return new PointSubsetWriterXML(fdPoint, ncssParams, out);
    case CSV_STREAM:
    case CSV_FILE:
      return new PointSubsetWriterCSV(fdPoint, ncssParams, out);
    case NETCDF3:
      return new PointSubsetWriterNetcdf(fdPoint, ncssParams, ncssDiskCache, out, Version.netcdf3);
    case NETCDF4:
      return new PointSubsetWriterNetcdf(fdPoint, ncssParams, ncssDiskCache, out, Version.netcdf4_classic);
    case NETCDF4EXT:
      return new PointSubsetWriterNetcdf(fdPoint, ncssParams, ncssDiskCache, out, Version.netcdf4);
    case WATERML2:
      throw new UnsupportedResponseFormatException(
          String.format("%s format not supported for %s feature type.", format, fdPoint.getFeatureType()));
    default:
      throw new UnsupportedResponseFormatException("Unknown result type = " + format.getFormatName());
  }
}
 
Example #17
Source File: ThreddsMetadataExtractor.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public ThreddsMetadata.VariableGroup extractVariables(FeatureDatasetPoint fd) {
  List<ThreddsMetadata.Variable> vars = new ArrayList<>();

  List<VariableSimpleIF> dataVars = fd.getDataVariables();
  if (dataVars == null)
    return null;

  for (VariableSimpleIF v : dataVars) {
    String name = v.getShortName();
    String desc = v.getDescription();
    String units = v.getUnitsString();
    String vname = null;
    String id = null;

    ucar.nc2.Attribute att = v.attributes().findAttributeIgnoreCase("standard_name");
    if (att != null)
      vname = att.getStringValue();
    vars.add(new ThreddsMetadata.Variable(name, desc, vname, units, id));
  }

  Collections.sort(vars);
  // String vocab, String vocabHref, URI vocabUri, URI mapUri, List<Variable> variables
  return new ThreddsMetadata.VariableGroup("CF-1.0", null, null, vars);
}
 
Example #18
Source File: NcCollectionType.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static StationTimeSeriesFeatureCollection getStationFeatures(FeatureDatasetPoint fdPoint) {
  String datasetFileName = new File(fdPoint.getNetcdfFile().getLocation()).getName();

  if (fdPoint.getFeatureType() != FeatureType.STATION) {
    throw new IllegalArgumentException(String.format("In %s, expected feature type to be STATION, not %s.",
        datasetFileName, fdPoint.getFeatureType()));
  }

  List<DsgFeatureCollection> featCollList = fdPoint.getPointFeatureCollectionList();

  if (featCollList.size() != 1) {
    throw new IllegalArgumentException(
        String.format("Expected %s to contain 1 FeatureCollection, not %s.", datasetFileName, featCollList.size()));
  } else if (!(featCollList.get(0) instanceof StationTimeSeriesFeatureCollection)) {
    String expectedClassName = StationTimeSeriesFeatureCollection.class.getName();
    String actualClassName = featCollList.get(0).getClass().getName();

    throw new IllegalArgumentException(String.format("Expected %s's FeatureCollection to be a %s, not a %s.",
        datasetFileName, expectedClassName, actualClassName));
  }

  return (StationTimeSeriesFeatureCollection) featCollList.get(0);
}
 
Example #19
Source File: CFPointObWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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 #20
Source File: DsgSubsetWriterFactory.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static DsgSubsetWriter newStationInstance(FeatureDatasetPoint fdPoint, SubsetParams ncssParams,
    NcssDiskCache ncssDiskCache, OutputStream out, SupportedFormat format)
    throws XMLStreamException, NcssException, IOException {
  switch (format) {
    case XML_STREAM:
    case XML_FILE:
      return new StationSubsetWriterXML(fdPoint, ncssParams, out);
    case CSV_STREAM:
    case CSV_FILE:
      return new StationSubsetWriterCSV(fdPoint, ncssParams, out);
    case NETCDF3:
      return new StationSubsetWriterNetcdf(fdPoint, ncssParams, ncssDiskCache, out, Version.netcdf3);
    case NETCDF4:
      return new StationSubsetWriterNetcdf(fdPoint, ncssParams, ncssDiskCache, out, Version.netcdf4_classic);
    case NETCDF4EXT:
      return new StationSubsetWriterNetcdf(fdPoint, ncssParams, ncssDiskCache, out, Version.netcdf4);
    case WATERML2:
      return new StationSubsetWriterWaterML(fdPoint, ncssParams, out);
    default:
      throw new UnsupportedResponseFormatException("Unknown result type = " + format.getFormatName());
  }
}
 
Example #21
Source File: TestCFPointWriter.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
static void compare(FeatureDatasetPoint org, FeatureDatasetPoint copy) {

    FeatureType fcOrg = org.getFeatureType();
    FeatureType fcCopy = copy.getFeatureType();
    assert fcOrg == fcCopy;

    List<VariableSimpleIF> orgVars = org.getDataVariables();
    List<VariableSimpleIF> copyVars = copy.getDataVariables();
    Formatter f = new Formatter();
    boolean ok = CompareNetcdf2.compareLists(getNames(orgVars, Lists.newArrayList("profileId")),
        getNames(copyVars, Lists.newArrayList("profileId")), f);
    if (ok)
      System.out.printf("Data Vars OK%n");
    else {
      System.out.printf("Data Vars NOT OK%n %s%n", f);
      if (failOnDataVarsDifferent)
        assert false;
    }
  }
 
Example #22
Source File: SortingStationPointFeatureCacheTest.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void test3() throws URISyntaxException, NoFactoryFoundException, IOException {
  // Sort in reverse order of station name length.
  Comparator<StationPointFeature> longestStationNameFirst = new Comparator<StationPointFeature>() {
    @Override
    public int compare(StationPointFeature o1, StationPointFeature o2) {
      return -Integer.compare(o1.getStation().getName().length(), o2.getStation().getName().length());
    }
  };
  SortingStationPointFeatureCache cache = new SortingStationPointFeatureCache(longestStationNameFirst);

  try (FeatureDatasetPoint fdInput = PointTestUtil.openPointDataset("cacheTestInput1.ncml");
      FeatureDatasetPoint fdExpected = PointTestUtil.openPointDataset("cacheTestExpected1.ncml")) {
    cache.addAll(fdInput);

    PointFeatureIterator pointIterExpected =
        new FlattenedDatasetPointCollection(fdExpected).getPointFeatureIterator();
    PointFeatureIterator pointIterActual = cache.getPointFeatureIterator();
    Assert.assertTrue(PointTestUtil.equals(pointIterExpected, pointIterActual));
  }
}
 
Example #23
Source File: ThreddsMetadataExtractor.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ThreddsMetadata.GeospatialCoverage extractGeospatial(FeatureDatasetPoint fd) {
  LatLonRect llbb = fd.getBoundingBox();
  if (llbb != null) {
    return new ThreddsMetadata.GeospatialCoverage(llbb, null, 0.0, 0.0);
  }
  return null;
}
 
Example #24
Source File: TdsRequestedDataset.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static FeatureDatasetPoint getPointDataset(HttpServletRequest request, HttpServletResponse response,
    String path) throws IOException {
  TdsRequestedDataset trd = new TdsRequestedDataset(request, null);
  if (path != null)
    trd.path = path;
  return trd.openAsPointDataset(request, response);
}
 
Example #25
Source File: PointSubsetWriterXML.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public PointSubsetWriterXML(FeatureDatasetPoint fdPoint, SubsetParams ncssParams, OutputStream out)
    throws XMLStreamException, NcssException, IOException {
  super(fdPoint, ncssParams);

  XMLOutputFactory factory = XMLOutputFactory.newInstance();
  staxWriter = factory.createXMLStreamWriter(out, "UTF-8");
}
 
Example #26
Source File: MarshallingUtil.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void marshalPointDataset(FeatureDatasetPoint fdPoint, List<VariableSimpleIF> dataVars,
    OutputStream outputStream) throws IOException, XmlException {
  resetIds();

  CollectionDocument collectionDoc = CollectionDocument.Factory.newInstance();
  NcCollectionType.initCollection(collectionDoc.addNewCollection(), fdPoint, dataVars);
  writeObject(collectionDoc, outputStream, true);
}
 
Example #27
Source File: NcCollectionType.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static CollectionType initCollection(CollectionType collection, FeatureDatasetPoint fdPoint,
    List<VariableSimpleIF> dataVars) throws IOException {
  // @gml:id
  String id = MarshallingUtil.createIdForType(CollectionType.class);
  collection.setId(id);

  // wml2:metadata
  NcDocumentMetadataPropertyType.initMetadata(collection.addNewMetadata());

  // wml2:observationMember[0..*]
  StationTimeSeriesFeatureCollection stationFeatColl = getStationFeatures(fdPoint);
  try {
    while (stationFeatColl.hasNext()) {
      StationTimeSeriesFeature stationFeat = stationFeatColl.next();

      for (VariableSimpleIF dataVar : dataVars) {
        if (dataVar.getDataType().isNumeric()) {
          // wml2:observationMember
          NcOMObservationPropertyType.initObservationMember(collection.addNewObservationMember(), stationFeat,
              dataVar);
        }
      }
    }
  } finally {
    stationFeatColl.finish();
  }

  return collection;
}
 
Example #28
Source File: MetadataExtractor.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static ThreddsMetadata.GeospatialCoverage extractGeospatial(FeatureDatasetPoint fd) {
  LatLonRect llbb = fd.getBoundingBox();
  if (llbb != null) {
    ThreddsMetadata.GeospatialCoverage gc = new ThreddsMetadata.GeospatialCoverage();
    gc.setBoundingBox(llbb);
    return gc;
  }
  return null;
}
 
Example #29
Source File: StationSubsetWriterXML.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public StationSubsetWriterXML(FeatureDatasetPoint fdPoint, SubsetParams ncssParams, OutputStream out)
    throws XMLStreamException, NcssException, IOException {
  super(fdPoint, ncssParams);

  XMLOutputFactory factory = XMLOutputFactory.newInstance();
  staxWriter = factory.createXMLStreamWriter(out, "UTF-8");
}
 
Example #30
Source File: StationSubsetWriterWaterML.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public StationSubsetWriterWaterML(FeatureDatasetPoint fdPoint, SubsetParams ncssParams, OutputStream out)
    throws XMLStreamException, NcssException, IOException {
  super(fdPoint, ncssParams);

  this.out = out;
  this.collectionDoc = CollectionDocument.Factory.newInstance();
  this.collection = collectionDoc.addNewCollection();
}