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());
}
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);
}
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()));
}
}
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);
}
}
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());
}
}
Aggregations