Search in sources :

Example 6 with DataStoreException

use of org.apache.sis.storage.DataStoreException 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 7 with DataStoreException

use of org.apache.sis.storage.DataStoreException 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 8 with DataStoreException

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

the class Axis method read.

/**
 * Returns the coordinates in the localization grid, excluding some trailing NaN values if any.
 * This method typically returns a cached vector if the coordinates have already been read.
 *
 * @throws IOException if an error occurred while reading the data.
 * @throws DataStoreException if a logical error occurred.
 */
final Vector read() throws IOException, DataStoreException {
    final TransferFunction tr = coordinates.getTransferFunction();
    if (TransferFunctionType.LINEAR.equals(tr.getType())) {
        Vector data = coordinates.read();
        if (gridSizes != null) {
            // Trim trailing NaN values.
            data = data.subList(0, getSizeProduct(0));
        }
        // Apply scale and offset attributes, if any.
        data = data.transform(tr.getScale(), tr.getOffset());
        return data;
    } else {
        throw new DataStoreException(coordinates.resources().getString(Resources.Keys.CanNotUseAxis_1, getName()));
    }
}
Also used : TransferFunction(org.apache.sis.referencing.operation.transform.TransferFunction) DataStoreException(org.apache.sis.storage.DataStoreException) Vector(org.apache.sis.math.Vector)

Example 9 with DataStoreException

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

the class ImageMetadataBuilder method finish.

/**
 * Completes the metadata with the information stored in the fields of the IFD.
 * This method is invoked only if the user requested the ISO 19115 metadata.
 * It should be invoked last, after all other metadata have been set.
 *
 * @throws DataStoreException if an error occurred while reading metadata from the data store.
 */
void finish(final ImageFileDirectory image) throws DataStoreException {
    image.getIdentifier().ifPresent((id) -> addTitle(id.toString()));
    /*
         * Add information about the file format.
         *
         * Destination: metadata/identificationInfo/resourceFormat
         */
    final GeoTiffStore store = image.reader.store;
    if (store.hidden) {
        // Should be before `addCompression(…)`.
        store.setFormatInfo(this);
    }
    final Compression compression = image.getCompression();
    if (compression != null) {
        addCompression(CharSequences.upperCaseToSentence(compression.name()));
    }
    /*
         * Add the resolution into the metadata. Our current ISO 19115 implementation restricts
         * the resolution unit to metres, but it may be relaxed in a future SIS version.
         *
         * Destination: metadata/identificationInfo/spatialResolution/distance
         */
    if (!Double.isNaN(resolution) && resolutionUnit != null) {
        addResolution(resolutionUnit.getConverterTo(Units.METRE).convert(resolution));
    }
    /*
         * Cell size is relevant only if the Threshholding TIFF tag value is 2. By convention in
         * this implementation class, other Threshholding values are stored as negative cell sizes:
         *
         *   -1 means that Threshholding is 1 or unspecified.
         *   -2 means that Threshholding is 2 but the matrix size has not yet been specified.
         *   -3 means that Threshholding is 3 (randomized process such as error diffusion).
         *
         * Destination: metadata/resourceLineage/processStep/description
         */
    final int cellWidth = this.cellWidth;
    final int cellHeight = this.cellHeight;
    switch(Math.min(cellWidth, cellHeight)) {
        case -1:
            {
                // Nothing to report.
                break;
            }
        case -3:
            {
                addProcessDescription(Resources.formatInternational(Resources.Keys.RandomizedProcessApplied));
                break;
            }
        default:
            {
                addProcessDescription(Resources.formatInternational(Resources.Keys.DitheringOrHalftoningApplied_2, (cellWidth >= 0) ? cellWidth : '?', (cellHeight >= 0) ? cellHeight : '?'));
                break;
            }
    }
    /*
         * If there is XML metadata, append them last in order
         * to allow them to be merged with existing metadata.
         */
    while (complement != null) try {
        complement = complement.appendTo(this);
    } catch (Exception ex) {
        image.warning(image.reader.errors().getString(Errors.Keys.CanNotSetPropertyValue_1, complement.tag()), ex);
    }
}
Also used : Compression(org.apache.sis.internal.geotiff.Compression) DataStoreException(org.apache.sis.storage.DataStoreException)

Example 10 with DataStoreException

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

the class SQLStoreTest method verifyStreamOperations.

/**
 * Checks that operations stacked on feature stream are well executed.
 * This test focuses on mapping and peeking actions overloaded by SQL streams.
 * Operations used here are meaningless; we just want to ensure that the pipeline does not skip any operation.
 *
 * @param  cities  a feature set containing all cities defined for the test class.
 */
private void verifyStreamOperations(final FeatureSet cities) throws DataStoreException {
    try (Stream<AbstractFeature> features = cities.features(false)) {
        final AtomicInteger peekCount = new AtomicInteger();
        final AtomicInteger mapCount = new AtomicInteger();
        final long actualPopulations = features.peek(f -> peekCount.incrementAndGet()).peek(f -> peekCount.incrementAndGet()).map(f -> {
            mapCount.incrementAndGet();
            return f;
        }).peek(f -> peekCount.incrementAndGet()).map(f -> {
            mapCount.incrementAndGet();
            return f;
        }).map(f -> f.getPropertyValue("population")).mapToDouble(obj -> ((Number) obj).doubleValue()).peek(f -> peekCount.incrementAndGet()).peek(f -> peekCount.incrementAndGet()).boxed().mapToDouble(d -> {
            mapCount.incrementAndGet();
            return d;
        }).mapToObj(d -> {
            mapCount.incrementAndGet();
            return d;
        }).mapToDouble(d -> {
            mapCount.incrementAndGet();
            return d;
        }).map(d -> {
            mapCount.incrementAndGet();
            return d;
        }).mapToLong(d -> (long) d).sum();
        long expectedPopulations = 0;
        for (City city : City.values()) expectedPopulations += city.population;
        assertEquals("Overall population count via Stream pipeline", expectedPopulations, actualPopulations);
        assertEquals("Number of mapping (by element in the stream)", 24, mapCount.get());
        assertEquals("Number of peeking (by element in the stream)", 20, peekCount.get());
    }
}
Also used : Arrays(java.util.Arrays) HashMap(java.util.HashMap) FeatureQuery(org.apache.sis.storage.FeatureQuery) Assert(org.apache.sis.test.Assert) TableReference(org.apache.sis.internal.sql.feature.TableReference) HashSet(java.util.HashSet) DefaultFeatureType(org.apache.sis.feature.DefaultFeatureType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestUtilities(org.apache.sis.test.TestUtilities) Map(java.util.Map) TestCase(org.apache.sis.test.TestCase) DataStoreException(org.apache.sis.storage.DataStoreException) DefaultAssociationRole(org.apache.sis.feature.DefaultAssociationRole) SchemaModifier(org.apache.sis.internal.sql.feature.SchemaModifier) DefaultAttributeType(org.apache.sis.feature.DefaultAttributeType) Collection(java.util.Collection) Test(org.junit.Test) Stream(java.util.stream.Stream) AbstractIdentifiedType(org.apache.sis.feature.AbstractIdentifiedType) AttributeConvention(org.apache.sis.internal.feature.AttributeConvention) FeatureSet(org.apache.sis.storage.FeatureSet) TestDatabase(org.apache.sis.test.sql.TestDatabase) AbstractFeature(org.apache.sis.feature.AbstractFeature) StorageConnector(org.apache.sis.storage.StorageConnector) DefaultFilterFactory(org.apache.sis.filter.DefaultFilterFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractFeature(org.apache.sis.feature.AbstractFeature)

Aggregations

DataStoreException (org.apache.sis.storage.DataStoreException)39 IOException (java.io.IOException)16 DataStore (org.apache.sis.storage.DataStore)8 Path (java.nio.file.Path)6 DataStoreContentException (org.apache.sis.storage.DataStoreContentException)5 FeatureSet (org.apache.sis.storage.FeatureSet)5 GridCoverageResource (org.apache.sis.storage.GridCoverageResource)4 IllegalNameException (org.apache.sis.storage.IllegalNameException)4 Resource (org.apache.sis.storage.Resource)4 BackingStoreException (org.apache.sis.util.collection.BackingStoreException)4 FactoryException (org.opengis.util.FactoryException)4 Reader (java.io.Reader)3 UncheckedIOException (java.io.UncheckedIOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 URISyntaxException (java.net.URISyntaxException)3 ByteBuffer (java.nio.ByteBuffer)3 ProbeResult (org.apache.sis.storage.ProbeResult)3 BufferedReader (java.io.BufferedReader)2 Closeable (java.io.Closeable)2 File (java.io.File)2