AbstractGridFormat lookupGridFormat(Object obj) { AbstractGridFormat format = GridFormatFinder.findFormat(obj); if (format == null) { throw new RuntimeException("No format for " + obj); } return format; }
private void addCoverageFromPath(QName name, File coverage, String relpath, String styleName) throws Exception { coverageInfo(name, coverage, styleName); // setup the meta information to be written in the catalog AbstractGridFormat format = (AbstractGridFormat) GridFormatFinder.findFormat(coverage); namespaces.put(name.getPrefix(), name.getNamespaceURI()); coverageStoresNamespaces.put(name.getLocalPart(), name.getPrefix()); Map params = new HashMap(); params.put(CatalogWriter.COVERAGE_TYPE_KEY, format.getName()); params.put(CatalogWriter.COVERAGE_URL_KEY, relpath); coverageStores.put(name.getLocalPart(), params); }
@Override public void createIndividuals() { LOG.info("Loading population from raster file {}", sourceFilename); try { File rasterFile = new File(sourceFilename); // determine file format and CRS, then load raster AbstractGridFormat format = GridFormatFinder.findFormat(rasterFile); AbstractGridCoverage2DReader reader = format.getReader(rasterFile); GridCoverage2D coverage = reader.read(null); this.coverageCRS = coverage.getCoordinateReferenceSystem(); GridGeometry2D gridGeometry = coverage.getGridGeometry(); GridEnvelope2D gridEnvelope = gridGeometry.getGridRange2D(); gridGeometry.getGridToCRS(); // because we may want to produce an empty raster rather than loading one, alongside the coverage we // store the row/col dimensions and the referenced envelope in the original coordinate reference system. this.cols = gridEnvelope.width; this.rows = gridEnvelope.height; this.createIndividuals0(); } catch (Exception ex) { throw new IllegalStateException("Error loading population from raster file: ", ex); } LOG.info("Done loading raster from file."); }
/** Keys for overriding default layer properties */ public static class StyleProperty<T> { T get(Map<StyleProperty, Object> map, T def) { return map != null && map.containsKey(this) ? (T) map.get(this) : def; } public static StyleProperty<String> FORMAT = new StyleProperty<String>(); public static StyleProperty<Version> FORMAT_VERSION = new StyleProperty<Version>(); public static StyleProperty<LegendInfo> LEGEND_INFO = new StyleProperty<LegendInfo>(); }
(gridFormat != null ? CoverageStoreUtils.acquireFormat(gridFormat) : GridFormatFinder.findFormat(coverageFile)); GridCoverage2DReader reader; try {
/** * Returns a {@link Format} that is able to read a certain object. If no {@link Format} is able * to read such an {@link Object} we return an {@link UnknownFormat} object. * * <p>It is worth to point out that this method will try to convert each format implementation * to {@link AbstractGridFormat} because the original {@link Format} interface did not allow for * an accept method hence we had to subclass the interface to add such method and we did so by * the {@link AbstractGridFormat} abstract class. * * @param o the object to check for acceptance. * @return an {@link AbstractGridFormat} that has stated to accept this {@link Object} o or * <code>null</code> in no plugins was able to accept it. */ public static synchronized AbstractGridFormat findFormat(Object o) { return findFormat(o, GeoTools.getDefaultHints()); }
AbstractGridFormat format = (AbstractGridFormat) GridFormatFinder.findFormat(file, Utils.EXCLUDE_MOSAIC_HINTS); reader = format.getReader(file); DatasetLayout layout = reader.getDatasetLayout();
format = GridFormatFinder.findFormat(fileBeingProcessed, excludeMosaicHints); } else { if (cachedFormat.accepts(fileBeingProcessed)) { format = cachedFormat; } else { format = GridFormatFinder.findFormat(fileBeingProcessed, excludeMosaicHints);
delete = !checkForReferences(coverageName); AbstractGridFormat format = GridFormatFinder.findFormat(rasterPath, excludeMosaicHints); if (format != null) { GridCoverage2DReader coverageReader = null;
? GridFormatFinder.findFormat(granuleUrl, EXCLUDE_MOSAIC) : suggestedFormat;
@Override public boolean supportsFile(final URL file) { AbstractGridFormat format = null; try { format = GridFormatFinder.findFormat(file); } catch (final Exception e) { LOGGER.info("Unable to support as raster file", e); } // the null check is enough and we don't need to check the format // accepts this file because the finder should have previously validated // this return (format != null); }
GridFormatFinder.findFormat(file, Utils.EXCLUDE_MOSAIC_HINTS); AbstractGridCoverage2DReader reader = format.getReader(file);
public static GridCoverage2D openGridCoverage(File gridFile) { GridCoverage2D gc2D = null; // Reading the coverage through a file AbstractGridFormat format = GridFormatFinder.findFormat(gridFile); try { AbstractGridCoverage2DReader reader = format.getReader(gridFile); gc2D = reader.read(null); } catch (IllegalArgumentException e) { LOGGER.log(Level.FINE, e.getMessage(), e); } catch (IOException e) { LOGGER.log(Level.FINE, e.getMessage(), e); } catch (Exception e) { LOGGER.log(Level.FINE, e.getMessage(), e); } return gc2D; }
/** * Returns a {@link Format} that is able to read a certain object. If no * {@link Format} is able to read such an {@link Object} we return an * {@link UnknownFormat} object. * * <p> * It is worth to point out that this method will try to convert each format * implementation to {@link AbstractGridFormat} because the original * {@link Format} interface did not allow for an accept method hence we had * to subclass the interface to add such method and we did so by the * {@link AbstractGridFormat} abstract class. * * @param o * the object to check for acceptance. * @return an {@link AbstractGridFormat} that has stated to accept this * {@link Object} o or <code>null</code> in no plugins was able to * accept it. */ public static synchronized AbstractGridFormat findFormat(Object o) { return findFormat(o, GeoTools.getDefaultHints()); }
public RasterFileDataSource(String id, String file, double noData) throws KlabUnsupportedOperationException { this.id = id; this.noData = noData; File f = new File(file); if (f.exists()) { _file = f; try { _format = GridFormatFinder.findFormat(file); } catch (Throwable e) { /* * stupid SPI throws exceptions when optional formats are not available * because we haven't bought ARC. Just ignore, and _format will be null if * any real problem happened. */ } } if (_format == null) { throw new KlabUnsupportedOperationException("file " + file + " cannot be read or does not have a supported raster format"); } }
@Override public Object decode(InputStream input) throws Exception { // in order to read a grid coverage we need to first store it on disk File root = new File(System.getProperty("java.io.tmpdir", ".")); File f = File.createTempFile("wps", "tiff", root); FileOutputStream os = null; try { os = new FileOutputStream(f); IOUtils.copy(input, os); } finally { IOUtils.closeQuietly(os); } // and then we try to read it as a geotiff AbstractGridFormat format = GridFormatFinder.findFormat(f); if (format instanceof UnknownFormat) { throw new WPSException( "Could not find the GeoTIFF GT2 format, please check it's in the classpath"); } return format.getReader(f).read(null); }
@Override public Object decode(InputStream input) throws Exception { // in order to read a grid coverage we need to first store it on disk File root = new File(System.getProperty("java.io.tmpdir", ".")); File f = File.createTempFile("wps", "tiff", root); FileOutputStream os = null; try { os = new FileOutputStream(f); IOUtils.copy(input, os); } finally { IOUtils.closeQuietly(os); } // and then we try to read it as a geotiff AbstractGridFormat format = GridFormatFinder.findFormat(f); if (format instanceof UnknownFormat) { throw new WPSException( "Could not find the GeoTIFF GT2 format, please check it's in the classpath"); } return format.getReader(f).read(null); }
/** * return a gridcoverage for Raster file. Use a Map containing key "url" * @param params * @return GridCoverage */ public static GridCoverageReader getGridCoverageReader(Map params){ URL url = (URL) params.get("url"); if (url != null) { File file = DataUtilities.urlToFile(url); if (file != null&&file.exists()&&file.canRead()) { // try a geotiff gridcoverage GridFormatFinder.scanForPlugins(); final Format format=GridFormatFinder.findFormat(file); if(format!=null&&!(format instanceof UnknownFormat)) return ((AbstractGridFormat)format).getReader(file); } } return null; } }
(AbstractGridFormat) GridFormatFinder.findFormat(file, EXCLUDE_MOSAIC_HINTS); if (format == null) { throw new RestException(
AbstractGridFormat format = GridFormatFinder.findFormat(rasterFile); AbstractGridCoverage2DReader reader = null;