Search in sources :

Example 1 with JP2ECWReader

use of org.geotools.coverageio.gdal.jp2ecw.JP2ECWReader in project geowave by locationtech.

the class AmazonImageryProvider method getCoverage.

/**
 * Fetch the coverage of the specified band in the specified workspace directory
 */
@Override
public RasterBandData getCoverage(final SimpleFeature band, final String workspaceDir) throws IOException {
    final File sceneDir = DownloadRunner.getSceneDirectory(band, workspaceDir);
    final String entityId = (String) band.getAttribute(SceneFeatureIterator.ENTITY_ID_ATTRIBUTE_NAME);
    final String productId = (String) band.getAttribute(SceneFeatureIterator.PRODUCT_ID_ATTRIBUTE_NAME);
    final String bandName = (String) band.getAttribute(BandFeatureIterator.BAND_ATTRIBUTE_NAME);
    final File file = new File(sceneDir + File.separator + AWS_SCENE_RESOURCE_NAMES.get(bandName));
    if (!file.exists()) {
        final String downloadUrl = (String) band.getAttribute(SceneFeatureIterator.SCENE_DOWNLOAD_ATTRIBUTE_NAME);
        downloadFile(downloadUrl, sceneDir, bandName);
    }
    if (file.exists()) {
        final JP2ECWReader reader = new JP2ECWReader(file);
        final GridCoverage2D coverage = reader.read(null);
        reader.dispose();
        return new RasterBandData(entityId + "_" + bandName, coverage, reader, NO_DATA_VALUE);
    }
    throw new IOException("The file of the '" + productId + "_" + bandName + "' coverage does not exist");
}
Also used : JP2ECWReader(org.geotools.coverageio.gdal.jp2ecw.JP2ECWReader) GridCoverage2D(org.geotools.coverage.grid.GridCoverage2D) IOException(java.io.IOException) File(java.io.File) RasterBandData(org.locationtech.geowave.format.sentinel2.RasterBandData)

Example 2 with JP2ECWReader

use of org.geotools.coverageio.gdal.jp2ecw.JP2ECWReader in project geowave by locationtech.

the class Tests method jp2ecwPluginIsWorking.

/**
 * Returns whether the JP2ECW plugin for GDAL is really working.
 */
public static boolean jp2ecwPluginIsWorking() {
    synchronized (Tests.LOGGER) {
        if (JP2ECW_PLUGIN_AVAILABLE_FLAG == 0) {
            System.err.println("Testing whether the JP2ECW plugin for GDAL is really working...");
            try {
                final File file = new File(JP2_TEST_FILE);
                final JP2ECWReader reader = new JP2ECWReader(file);
                reader.read(null);
                reader.dispose();
                System.err.println("JP2ECW plugin is working!");
                JP2ECW_PLUGIN_AVAILABLE_FLAG = 1;
            } catch (final Throwable e) {
                System.err.println("JP2ECW plugin fails, Error='" + e.getMessage() + "'");
                JP2ECW_PLUGIN_AVAILABLE_FLAG = 2;
            }
        }
    }
    return JP2ECW_PLUGIN_AVAILABLE_FLAG == 1;
}
Also used : JP2ECWReader(org.geotools.coverageio.gdal.jp2ecw.JP2ECWReader) File(java.io.File)

Aggregations

File (java.io.File)2 JP2ECWReader (org.geotools.coverageio.gdal.jp2ecw.JP2ECWReader)2 IOException (java.io.IOException)1 GridCoverage2D (org.geotools.coverage.grid.GridCoverage2D)1 RasterBandData (org.locationtech.geowave.format.sentinel2.RasterBandData)1