Search in sources :

Example 1 with GridCoverageResource

use of org.apache.sis.storage.GridCoverageResource in project sis by apache.

the class ResourceExplorer method getSelectedData.

/**
 * Returns the set of currently selected data, or {@code null} if none.
 * This is invoked when the user selects the "New window" menu item.
 */
@Override
final SelectedData getSelectedData() {
    final Resource resource = getSelectedResource();
    if (resource == null) {
        return null;
    }
    FeatureTable table = null;
    CoverageExplorer grid = null;
    if (resource instanceof GridCoverageResource) {
        /*
             * Want the full coverage in all bands (sample dimensions).
             */
        if (coverage == null) {
            // For forcing creation of CoverageExplorer.
            updateDataTab(resource);
        }
        grid = coverage;
    } else if (resource instanceof FeatureSet) {
        /*
             * We will not set features in an initially empty `FeatureTable` (to be newly created),
             * but instead share the `FeatureLoader` created by the feature table of this explorer.
             * We do that even if the feature table is not currently visible. This will not cause
             * useless data loading since they share the same `FeatureLoader`.
             */
        if (features == null) {
            // For forcing creation of FeatureTable.
            updateDataTab(resource);
        }
        table = features;
    } else {
        return null;
    }
    String text;
    try {
        text = ResourceTree.findLabel(resource, resources.locale, true);
    } catch (DataStoreException | RuntimeException e) {
        text = Vocabulary.getResources(resources.locale).getString(Vocabulary.Keys.Unnamed);
    }
    return new SelectedData(text, table, grid, localized());
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) Resource(org.apache.sis.storage.Resource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) CoverageExplorer(org.apache.sis.gui.coverage.CoverageExplorer) FeatureSet(org.apache.sis.storage.FeatureSet)

Example 2 with GridCoverageResource

use of org.apache.sis.storage.GridCoverageResource in project sis by apache.

the class ResourceExplorer method updateDataTab.

/**
 * Assigns the given resource into the {@link #viewTab} or {@link #tableTab}, depending which one is visible.
 * Shall be invoked with a non-null resource only if a data tab is visible because data loading may be costly.
 *
 * @param  resource  the resource to set, or {@code null} if none.
 * @return {@code true} if the resource has been recognized.
 *
 * @see #dataShown
 * @see #updateDataTabWithDefault(Resource)
 */
private boolean updateDataTab(final Resource resource) {
    Region image = null;
    Region table = null;
    FeatureSet data = null;
    ImageRequest grid = null;
    TitledPane[] cpanes = null;
    final CoverageExplorer.View type = getCoverageView();
    if (resource instanceof GridCoverageResource) {
        // A null `type` value here would be a violation of method contract.
        if (coverage == null) {
            coverage = new CoverageExplorer(type);
        } else {
            coverage.setViewType(type);
        }
        final Region view = coverage.getDataView(type);
        switch(type) {
            case IMAGE:
                image = view;
                break;
            case TABLE:
                table = view;
                break;
        }
        grid = new ImageRequest((GridCoverageResource) resource, null, null);
        cpanes = coverage.getControls(type);
    } else if (resource instanceof FeatureSet) {
        data = (FeatureSet) resource;
        if (features == null) {
            features = new FeatureTable();
        }
        table = features;
    }
    /*
         * At least one of `grid` or `data` will be null. Invoking the following
         * setter methods with a null argument will release memory.
         */
    if (coverage != null)
        coverage.setCoverage(grid);
    if (features != null)
        features.setFeatures(data);
    if (image != null)
        viewTab.setContent(image);
    if (table != null)
        tableTab.setContent(table);
    final boolean isEmpty = (image == null & table == null);
    setNewWindowDisabled(isEmpty);
    /*
         * Add or remove controls for the selected view.
         * Information about the expanded pane needs to be saved before to remove controls,
         * and restored (for a potentially different view) after new controls have been added.
         */
    TitledPane expanded = controls.getExpandedPane();
    if (expanded != null && coverageView != null) {
        expandedPane.put(coverageView, expanded);
    }
    final ObservableList<TitledPane> items = controls.getPanes();
    final int size = items.size();
    items.remove(1, size);
    if (cpanes != null) {
        items.addAll(cpanes);
        if (!items.contains(expanded)) {
            expanded = expandedPane.get(type);
            if (expanded != null) {
                controls.setExpandedPane(expanded);
            }
        }
    }
    coverageView = type;
    return !isEmpty | (resource == null);
}
Also used : TitledPane(javafx.scene.control.TitledPane) ImageRequest(org.apache.sis.gui.coverage.ImageRequest) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) Region(javafx.scene.layout.Region) CoverageExplorer(org.apache.sis.gui.coverage.CoverageExplorer) FeatureSet(org.apache.sis.storage.FeatureSet)

Example 3 with GridCoverageResource

use of org.apache.sis.storage.GridCoverageResource in project sis by apache.

the class CoverageExplorer method getViewAndControls.

/**
 * Returns the view-control pair for the given view type.
 * The view-control pair is created when first needed.
 * Invoking this method may cause data to be loaded in a background thread.
 *
 * @param  type  type of view to obtain.
 * @param  load  whether to force loading of data in the new type.
 */
private ViewAndControls getViewAndControls(final View type, boolean load) {
    ViewAndControls c = views.get(type);
    if (c == null) {
        switch(type) {
            case TABLE:
                c = new GridControls(this);
                break;
            case IMAGE:
                c = new CoverageControls(this);
                break;
            default:
                throw new AssertionError(type);
        }
        SplitPane.setResizableWithParent(c.view(), Boolean.TRUE);
        views.put(type, c);
        load = true;
    }
    /*
         * If this explorer is showing a coverage, load data in the newly created view.
         * Data may also be loaded because the view was previously unselected (hidden)
         * and became selected (visible).
         */
    if (load) {
        final GridCoverageResource resource = getResource();
        final GridCoverage coverage = getCoverage();
        if (resource != null || coverage != null) {
            c.load(new ImageRequest(resource, coverage));
        }
    }
    return c;
}
Also used : GridCoverage(org.apache.sis.coverage.grid.GridCoverage) GridCoverageResource(org.apache.sis.storage.GridCoverageResource)

Example 4 with GridCoverageResource

use of org.apache.sis.storage.GridCoverageResource in project sis by apache.

the class GeoTiffStore method findResource.

/**
 * Returns the image at the given index. Images numbering starts at 1.
 *
 * @param  sequence  string representation of the image index, starting at 1.
 * @return image at the given index.
 * @throws DataStoreException if the requested image can not be obtained.
 */
@Override
public GridCoverageResource findResource(final String sequence) throws DataStoreException {
    Exception cause;
    int index;
    try {
        index = Integer.parseInt(sequence);
        cause = null;
    } catch (NumberFormatException e) {
        index = 0;
        cause = e;
    }
    if (index > 0)
        try {
            GridCoverageResource image = reader().getImage(index - 1);
            if (image != null)
                return image;
        } catch (IOException e) {
            throw errorIO(e);
        }
    throw new IllegalNameException(StoreUtilities.resourceNotFound(this, sequence), cause);
}
Also used : GridCoverageResource(org.apache.sis.storage.GridCoverageResource) IOException(java.io.IOException) IllegalNameException(org.apache.sis.storage.IllegalNameException) MetadataStoreException(org.apache.sis.metadata.sql.MetadataStoreException) DataStoreClosedException(org.apache.sis.storage.DataStoreClosedException) IllegalNameException(org.apache.sis.storage.IllegalNameException) DataStoreException(org.apache.sis.storage.DataStoreException) BackingStoreException(org.apache.sis.util.collection.BackingStoreException) IOException(java.io.IOException)

Example 5 with GridCoverageResource

use of org.apache.sis.storage.GridCoverageResource in project sis by apache.

the class GeoTiffStore method getMetadata.

/**
 * Returns information about the dataset as a whole. The returned metadata object can contain information
 * such as the spatiotemporal extent of the dataset, contact information about the creator or distributor,
 * data quality, usage constraints and more.
 *
 * @return information about the dataset.
 * @throws DataStoreException if an error occurred while reading the data.
 */
@Override
public synchronized Metadata getMetadata() throws DataStoreException {
    if (metadata == null) {
        final Reader reader = reader();
        final MetadataBuilder builder = new MetadataBuilder();
        setFormatInfo(builder);
        int n = 0;
        try {
            GridCoverageResource dir;
            while ((dir = reader.getImage(n++)) != null) {
                builder.addFromComponent(dir.getMetadata());
            }
        } catch (IOException e) {
            throw errorIO(e);
        } catch (ArithmeticException e) {
            listeners.warning(e);
        }
        /*
             * Add the filename as an identifier only if the input was something convertible to URI (URL, File or Path),
             * otherwise reader.input.filename may not be useful; it may be just the InputStream classname. If the TIFF
             * file did not specified any ImageDescription tag, then we will add the filename as a title instead of an
             * identifier because the title is mandatory in ISO 19115 metadata.
             */
        getIdentifier().ifPresent((id) -> builder.addTitleOrIdentifier(id.toString(), MetadataBuilder.Scope.ALL));
        builder.setISOStandards(true);
        final DefaultMetadata md = builder.build(false);
        metadata = customizer.customize(-1, md);
        if (metadata == null)
            metadata = md;
        md.transitionTo(DefaultMetadata.State.FINAL);
    }
    return metadata;
}
Also used : MetadataBuilder(org.apache.sis.internal.storage.MetadataBuilder) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) IOException(java.io.IOException)

Aggregations

GridCoverageResource (org.apache.sis.storage.GridCoverageResource)9 DataStoreException (org.apache.sis.storage.DataStoreException)3 IOException (java.io.IOException)2 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)2 CoverageExplorer (org.apache.sis.gui.coverage.CoverageExplorer)2 FeatureSet (org.apache.sis.storage.FeatureSet)2 BackingStoreException (org.apache.sis.util.collection.BackingStoreException)2 ArrayList (java.util.ArrayList)1 TitledPane (javafx.scene.control.TitledPane)1 Region (javafx.scene.layout.Region)1 ImageRequest (org.apache.sis.gui.coverage.ImageRequest)1 MetadataBuilder (org.apache.sis.internal.storage.MetadataBuilder)1 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)1 MetadataStoreException (org.apache.sis.metadata.sql.MetadataStoreException)1 DataStoreClosedException (org.apache.sis.storage.DataStoreClosedException)1 IllegalNameException (org.apache.sis.storage.IllegalNameException)1 Resource (org.apache.sis.storage.Resource)1