Example usage for javax.imageio.spi ImageReaderSpi getClass

List of usage examples for javax.imageio.spi ImageReaderSpi getClass

Introduction

In this page you can find the example usage for javax.imageio.spi ImageReaderSpi getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.geoserver.opensearch.rest.CollectionsController.java

private void configureSeparateBandsMosaic(String collection, CollectionLayer layerConfiguration,
        String relativePath, Resource mosaicDirectory) throws Exception {
    // get the namespace URI for the store
    final FeatureSource<FeatureType, Feature> collectionSource = getOpenSearchAccess().getCollectionSource();
    final FeatureType schema = collectionSource.getSchema();
    final String nsURI = schema.getName().getNamespaceURI();

    // image mosaic won't automatically create the mosaic config for us in this case,
    // we have to setup both the mosaic property file and sample image for all bands
    for (int band : layerConfiguration.getBands()) {
        final String mosaicName = collection + OpenSearchAccess.BAND_LAYER_SEPARATOR + band;

        // get the sample granule
        File file = getSampleGranule(collection, nsURI, band, mosaicName);
        AbstractGridFormat format = (AbstractGridFormat) GridFormatFinder.findFormat(file,
                EXCLUDE_MOSAIC_HINTS);//from w  w  w . j  a  v a  2 s .  c  o m
        if (format == null) {
            throw new RestException(
                    "Could not find a coverage reader able to process " + file.getAbsolutePath(),
                    HttpStatus.PRECONDITION_FAILED);
        }
        ImageLayout imageLayout;
        double[] nativeResolution;
        AbstractGridCoverage2DReader reader = null;
        try {
            reader = format.getReader(file);
            if (reader == null) {
                throw new RestException(
                        "Could not find a coverage reader able to process " + file.getAbsolutePath(),
                        HttpStatus.PRECONDITION_FAILED);
            }
            imageLayout = reader.getImageLayout();
            nativeResolution = reader.getResolutionLevels()[0];
        } finally {
            if (reader != null) {
                reader.dispose();
            }
        }
        ImageReaderSpi spi = null;
        try (FileImageInputStream fis = new FileImageInputStream(file)) {
            ImageReader imageReader = ImageIOExt.getImageioReader(fis);
            if (imageReader != null) {
                spi = imageReader.getOriginatingProvider();
            }
        }

        // the mosaic configuration
        Properties mosaicConfig = new Properties();
        mosaicConfig.put("Levels", nativeResolution[0] + "," + nativeResolution[1]);
        mosaicConfig.put("Heterogeneous", "true");
        mosaicConfig.put("AbsolutePath", "true");
        mosaicConfig.put("Name", "" + band);
        mosaicConfig.put("TypeName", mosaicName);
        mosaicConfig.put("TypeNames", "false"); // disable typename scanning
        mosaicConfig.put("Caching", "false");
        mosaicConfig.put("LocationAttribute", "location");
        mosaicConfig.put("TimeAttribute", TIME_START);
        mosaicConfig.put("CanBeEmpty", "true");
        if (spi != null) {
            mosaicConfig.put("SuggestedSPI", spi.getClass().getName());
        }
        // TODO: the index is now always in 4326, so the mosaic has to be heterogeneous
        // in general, unless we know the data is uniformly in something else, in that
        // case we could reproject the view reporting the footprints...
        //            if (layerConfiguration.isHeterogeneousCRS()) {
        mosaicConfig.put("HeterogeneousCRS", "true");
        mosaicConfig.put("MosaicCRS", "EPSG:4326" /* layerConfiguration.getMosaicCRS() */);
        mosaicConfig.put("CrsAttribute", "crs");
        //            }
        Resource propertyResource = mosaicDirectory.get(band + ".properties");
        try (OutputStream os = propertyResource.out()) {
            mosaicConfig.store(os,
                    "DataStore configuration for collection '" + collection + "' and band '" + band + "'");
        }

        // create the sample image
        Resource sampleImageResource = mosaicDirectory.get(band + Utils.SAMPLE_IMAGE_NAME);
        Utils.storeSampleImage(sampleImageResource.file(), imageLayout.getSampleModel(null),
                imageLayout.getColorModel(null));
    }

    // this is ridicolous, but for the moment, multi-crs mosaics won't work if there
    // is no indexer.properties around, even if no collection is actually done
    buildIndexer(collection, mosaicDirectory);

    // mosaic datastore connection
    createDataStoreProperties(collection, mosaicDirectory);

    // the mosaic datastore itself
    CatalogBuilder cb = new CatalogBuilder(catalog);
    CoverageStoreInfo mosaicStoreInfo = createMosaicStore(cb, collection, layerConfiguration, relativePath);

    // and finally the layer, with a coverage view associated to it
    List<CoverageBand> coverageBands = buildCoverageBands(layerConfiguration);
    final String coverageName = layerConfiguration.getLayer();
    final CoverageView coverageView = new CoverageView(coverageName, coverageBands);
    CoverageInfo coverageInfo = coverageView.createCoverageInfo(coverageName, mosaicStoreInfo, cb);
    timeEnableResource(coverageInfo);
    final LayerInfo layerInfo = cb.buildLayer(coverageInfo);

    catalog.add(coverageInfo);
    catalog.add(layerInfo);

    // configure the style if needed
    createStyle(layerConfiguration, layerInfo);
}