Java Code Examples for ucar.nc2.constants.FeatureType#isPointFeatureType()

The following examples show how to use ucar.nc2.constants.FeatureType#isPointFeatureType() . 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: 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 2
Source File: AllowedServices.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Service getStandardServices(FeatureType featType) {
  ServiceType compoundService = ServiceType.Compound;
  if (featType.isCoverageFeatureType()) {
    return new Service("GridServices", "", compoundService.toString(), compoundService.getDescription(), null,
        allowedGridServices, null, compoundService.getAccessType());
  }

  if (featType.isPointFeatureType()) {
    return new Service("PointServices", "", compoundService.toString(), compoundService.getDescription(), null,
        allowedPointServices, null, compoundService.getAccessType());
  }

  if (featType == FeatureType.RADIAL) {
    return new Service("RadialServices", "", compoundService.toString(), compoundService.getDescription(), null,
        allowedRadialServices, null, compoundService.getAccessType());
  }

  return null;
}
 
Example 3
Source File: FeatureDatasetFactoryManager.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Determine if factory type matches wanted feature type.
 *
 * @param want want this FeatureType
 * @param facType factory is of this type
 * @return true if match
 */
public static boolean featureTypeOk(FeatureType want, FeatureType facType) {
  if (want == null)
    return true;
  if (want == facType)
    return true;

  if (want == FeatureType.ANY_POINT) {
    return facType.isPointFeatureType();
  }

  if (facType == FeatureType.ANY_POINT) {
    return want.isPointFeatureType();
  }

  if (want == FeatureType.COVERAGE) {
    return facType.isCoverageFeatureType();
  }

  if (want == FeatureType.GRID) { // for backwards compatibility
    return facType.isCoverageFeatureType();
  }

  if (want == FeatureType.SIMPLE_GEOMETRY) {
    return facType.isCoverageFeatureType();
  }

  if (want == FeatureType.UGRID) {
    return facType.isUnstructuredGridFeatureType();
  }

  return false;
}
 
Example 4
Source File: AllowedServices.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Service getStandardCollectionServices(FeatureType featType) {
  ServiceType compoundService = ServiceType.Compound;
  if (featType.isCoverageFeatureType()) {
    return new Service("GridCollectionServices", "", compoundService.toString(), compoundService.getDescription(),
        null, allowedGridServices, null, compoundService.getAccessType());
  }

  if (featType.isPointFeatureType()) {
    return new Service("PointCollectionServices", "", compoundService.toString(), null, null,
        allowedPointCollectionServices, null, compoundService.getAccessType());
  }

  return null;
}
 
Example 5
Source File: PointDatasetStandardFactory.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Check if this is a POINT datatype. If so, a TableAnalyser is used to analyze its structure.
 * The TableAnalyser is reused when the dataset is opened.
 * <ol>
 * <li>Can handle ANY_POINT FeatureType.
 * <li>Must have time, lat, lon axis (from CoordSysBuilder)
 * <li>Call TableAnalyzer.factory() to create a TableAnalyzer
 * <li>TableAnalyzer must agree it can handle the requested FeatureType
 * </ol>
 *
 * @param wantFeatureType desired feature type, null means FeatureType.ANY_POINT
 * @param ds analyse this dataset
 * @param errlog log error messages here (may not be null)
 * @return if successful, return non-null. This object is then passed back into open(), so analysis can be reused.
 */
@Override
public Object isMine(FeatureType wantFeatureType, NetcdfDataset ds, Formatter errlog) {
  if (wantFeatureType == null)
    wantFeatureType = FeatureType.ANY_POINT;
  if (wantFeatureType != FeatureType.ANY_POINT) {
    if (!wantFeatureType.isPointFeatureType())
      return null;
  }

  TableConfigurer tc = TableAnalyzer.getTableConfigurer(wantFeatureType, ds);

  // if no explicit tc, then check whatever we can before expensive analysis)
  if (tc == null) {
    boolean hasTime = false;
    boolean hasLat = false;
    boolean hasLon = false;
    for (CoordinateAxis axis : ds.getCoordinateAxes()) {
      if (axis.getAxisType() == AxisType.Time) // && (axis.getRank() == 1))
        hasTime = true;
      if (axis.getAxisType() == AxisType.Lat) // && (axis.getRank() == 1))
        hasLat = true;
      if (axis.getAxisType() == AxisType.Lon) // && (axis.getRank() == 1))
        hasLon = true;
    }

    // minimum we need
    if (!(hasTime && hasLon && hasLat)) {
      errlog.format("PointDataset must have lat,lon,time");
      return null;
    }
  } else if (showTables) {
    System.out.printf("TableConfigurer = %s%n", tc.getClass().getName());
  }

  try {
    // gotta do some work
    TableAnalyzer analyser = TableAnalyzer.factory(tc, wantFeatureType, ds);
    if (analyser == null)
      return null;

    if (!analyser.featureTypeOk(wantFeatureType, errlog)) {
      return null;
    }
    return analyser;

  } catch (Throwable t) {
    return null;
  }
}
 
Example 6
Source File: CdmrFeatureDataset.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static Optional<FeatureDataset> factory(FeatureType wantFeatureType, String endpoint) throws IOException {
  if (endpoint.startsWith(SCHEME))
    endpoint = endpoint.substring(SCHEME.length());

  FeatureType featureType;
  try {
    featureType = isCdmrfEndpoint(endpoint);
    if (featureType == null)
      return Optional.empty("Not a valid CdmrFeatureDataset endpoint=" + endpoint);

  } catch (IOException ioe) {
    return Optional
        .empty(String.format("Error opening CdmrFeatureDataset endpoint=%s err=%s", endpoint, ioe.getMessage()));
  }

  if (!FeatureDatasetFactoryManager.featureTypeOk(wantFeatureType, featureType))
    return Optional.empty(String.format("Not a compatible featureType=%s, want=%s, endpoint=%s", featureType,
        wantFeatureType, endpoint));

  if (featureType.isCoverageFeatureType()) {
    CdmrfReader reader = new CdmrfReader(endpoint);
    CoverageCollection covColl = reader.open();
    return Optional.of(new FeatureDatasetCoverage(endpoint, covColl, covColl));
  }

  if (featureType.isPointFeatureType()) {
    Document doc = getCapabilities(endpoint);
    Element root = doc.getRootElement();
    Element elem = root.getChild("featureDataset");
    String fType = elem.getAttribute("type").getValue(); // LOOK, may be multiple types

    endpoint = elem.getAttribute("url").getValue();
    wantFeatureType = FeatureType.getType(fType);
    if (debug)
      System.out.printf("CdmrFeatureDataset endpoint %s%n ftype= '%s' url=%s%n", endpoint, fType, endpoint);

    List<VariableSimpleIF> dataVars = FeatureDatasetCapabilitiesWriter.getDataVariables(doc);
    LatLonRect bb = FeatureDatasetCapabilitiesWriter.getSpatialExtent(doc);
    CalendarDateRange dr = FeatureDatasetCapabilitiesWriter.getTimeSpan(doc);
    CalendarDateUnit timeUnit = FeatureDatasetCapabilitiesWriter.getTimeUnit(doc);
    String altUnits = FeatureDatasetCapabilitiesWriter.getAltUnits(doc);

    return Optional.of(new PointDatasetRemote(wantFeatureType, endpoint, timeUnit, altUnits, dataVars, bb, dr));
  }

  return Optional.empty(
      String.format("Unimplemented featureType=%s, want=%s, endpoint=%s", featureType, wantFeatureType, endpoint));
}