Search in sources :

Example 1 with Grid

use of org.apache.sis.internal.netcdf.Grid in project sis by apache.

the class VariableWrapper method getGrid.

/**
 * Returns a builder for the grid geometry of this variable, or {@code null} if this variable is not a data cube.
 * This method searches for a grid previously computed by {@link DecoderWrapper#getGrids()}, keeping in mind that
 * the UCAR library sometime builds {@link CoordinateSystem} instances with axes in different order than what we
 * would expect. This method delegates to the super-class method only if the grid requires a different analysis
 * than the one performed by UCAR library.
 *
 * <p>This method should be invoked by {@link #getGridGeometry()} only once.
 * For that reason, it does not need to cache the value.</p>
 *
 * @see DecoderWrapper#getGrids()
 */
@Override
protected Grid getGrid(final GridAdjustment adjustment) throws IOException, DataStoreException {
    /*
         * In some netCDF files, more than one grid could be associated to a variable. If the names of the
         * variables to use as coordinate system axes have been specified, use those names for filtering.
         * Otherwise no filtering is applied (which is the common case). If more than one grid fit, take
         * the first grid having the largest number of dimensions.
         *
         * This block duplicates work done in super.getGrid(…), except that it focuses on the set of coordinate
         * systems identified by UCAR for this variable while super.getGrid(…) inspects all dimensions found in
         * the file. Note that those coordinate systems may have been set by the user.
         */
    if (variable instanceof VariableDS) {
        final List<CoordinateSystem> systems = ((VariableDS) variable).getCoordinateSystems();
        if (!systems.isEmpty()) {
            GridWrapper grid = null;
            final String[] axisNames = decoder.convention().namesOfAxisVariables(this);
            for (final Grid candidate : decoder.getGrids()) {
                final GridWrapper ordered = ((GridWrapper) candidate).forVariable(variable, systems, axisNames);
                if (ordered != null && (grid == null || ordered.getSourceDimensions() > grid.getSourceDimensions())) {
                    grid = ordered;
                }
            }
            if (grid != null) {
                return grid;
            }
        }
    }
    /*
         * If we reach this point, we did not found a grid using the dimensions of this variable.
         * But maybe there is a grid using other dimensions (typically with a decimation) that we
         * can map to the variable dimension using attribute values. This mechanism is described
         * in Convention.nameOfDimension(…).
         */
    return (GridWrapper) super.getGrid(adjustment);
}
Also used : CoordinateSystem(ucar.nc2.dataset.CoordinateSystem) VariableDS(ucar.nc2.dataset.VariableDS) Grid(org.apache.sis.internal.netcdf.Grid)

Example 2 with Grid

use of org.apache.sis.internal.netcdf.Grid in project sis by apache.

the class GridInfoTest method filter.

/**
 * Filters out the one-dimensional coordinate systems created by {@code GridGeometry}
 * but not by the UCAR library.
 *
 * @return the filtered grid geometries to test.
 */
@Override
protected Grid[] filter(final Grid[] geometries) {
    final Grid[] copy = new Grid[geometries.length];
    int count = 0;
    for (final Grid geometry : geometries) {
        if (geometry.getSourceDimensions() != 1 || geometry.getTargetDimensions() != 1) {
            copy[count++] = geometry;
        }
    }
    return ArraysExt.resize(copy, count);
}
Also used : Grid(org.apache.sis.internal.netcdf.Grid)

Example 3 with Grid

use of org.apache.sis.internal.netcdf.Grid in project sis by apache.

the class MetadataReader method read.

/**
 * Creates an ISO {@code Metadata} object from the information found in the netCDF file.
 * The returned metadata is unmodifiable, for allowing the caller to share a unique instance.
 *
 * @return the ISO metadata object.
 * @throws IOException if an I/O operation was necessary but failed.
 * @throws DataStoreException if a logical error occurred.
 * @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE}, or other overflow occurs.
 */
public Metadata read() throws IOException, DataStoreException {
    for (final CoordinateReferenceSystem crs : decoder.getReferenceSystemInfo()) {
        addReferenceSystem(crs);
        if (verticalCRS == null) {
            verticalCRS = CRS.getVerticalComponent(crs, false);
        }
    }
    addResourceScope(ScopeCode.DATASET, null);
    addIdentificationInfo(addCitation());
    for (final String service : SERVICES) {
        final String name = stringValue(service);
        if (name != null) {
            addResourceScope(ScopeCode.SERVICE, name);
        }
    }
    addAcquisitionInfo();
    addContentInfo();
    /*
         * Add the dimension information, if any. This metadata node
         * is built from the netCDF CoordinateSystem objects.
         */
    boolean hasGrids = false;
    for (final Grid cs : decoder.getGrids()) {
        if (cs.getSourceDimensions() >= Grid.MIN_DIMENSION && cs.getTargetDimensions() >= Grid.MIN_DIMENSION) {
            addSpatialRepresentationInfo(cs);
            hasGrids = true;
        }
    }
    setISOStandards(hasGrids);
    addFileIdentifier();
    /*
         * Deperture: UnidataDD2MI.xsl puts the source in Metadata.dataQualityInfo.lineage.statement.
         * However since ISO 19115:2014, Metadata.resourceLineage.statement seems a more appropriate place.
         * See https://issues.apache.org/jira/browse/SIS-361
         */
    for (final String path : searchPath) {
        decoder.setSearchPath(path);
        addLineage(stringValue(HISTORY));
        addSource(stringValue(SOURCE), null, null);
    }
    decoder.setSearchPath(searchPath);
    final DefaultMetadata metadata = build(false);
    addCompleteMetadata(createURI(stringValue(METADATA_LINK)));
    metadata.transitionTo(DefaultMetadata.State.FINAL);
    return metadata;
}
Also used : Grid(org.apache.sis.internal.netcdf.Grid) DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) InternationalString(org.opengis.util.InternationalString)

Aggregations

Grid (org.apache.sis.internal.netcdf.Grid)3 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1 InternationalString (org.opengis.util.InternationalString)1 CoordinateSystem (ucar.nc2.dataset.CoordinateSystem)1 VariableDS (ucar.nc2.dataset.VariableDS)1