예제 #1
0
 /**
  * @param datasource
  * @param adapter
  * @return a corresponding raster, null if files could not be fund
  */
 public static AbstractRaster fromDatasource(RasterDataSource datasource, XMLAdapter adapter) {
   if (datasource != null) {
     String defCRS = datasource.getCrs();
     CRS crs = null;
     if (defCRS != null) {
       crs = new CRS(defCRS);
     }
     RasterFileSetType directory = datasource.getRasterDirectory();
     RasterFileType file = datasource.getRasterFile();
     try {
       if (directory != null) {
         File rasterFiles = new File(adapter.resolve(directory.getValue()).getFile());
         boolean recursive = directory.isRecursive() == null ? false : directory.isRecursive();
         RasterIOOptions options = new RasterIOOptions();
         if (crs != null) {
           options.add(RasterIOOptions.CRS, crs.getName());
         }
         return buildTiledRaster(rasterFiles, directory.getFilePattern(), recursive, options);
       }
       if (file != null) {
         final File loc = new File(adapter.resolve(file.getValue()).getFile());
         AbstractRaster raster = loadRasterFromFile(loc);
         raster.setCoordinateSystem(crs);
         return raster;
       }
     } catch (MalformedURLException e) {
       if (directory != null) {
         LOG.warn(
             "Could not resolve the file {}, corresponding data will not be available.",
             directory.getValue());
       } else {
         LOG.warn(
             "Could not resolve the file {}, corresponding data will not be available.",
             file.getValue());
       }
     } catch (IOException e) {
       LOG.warn(
           "Could not load the file {}, corresponding data will not be available.",
           file.getValue());
     }
   }
   throw new NullPointerException("The configured raster datasource may not be null.");
 }