예제 #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.");
 }
예제 #2
0
 /**
  * @param datasource
  * @param adapter
  * @return a corresponding raster
  */
 public static MultiResolutionRaster fromDatasource(
     MultiResolutionDataSource datasource, XMLAdapter adapter) {
   if (datasource != null) {
     String defCRS = datasource.getCrs();
     CRS crs = null;
     if (defCRS != null) {
       crs = new CRS(defCRS);
     }
     MultiResolutionRaster mrr = new MultiResolutionRaster();
     mrr.setCoordinateSystem(crs);
     for (Resolution resolution : datasource.getResolution()) {
       JAXBElement<? extends AbstractGeospatialDataSourceType> dsElement =
           resolution.getAbstractGeospatialDataSource();
       RasterDataSource ds = (RasterDataSource) dsElement.getValue();
       RasterFileSetType directory = ds.getRasterDirectory();
       File resolutionDir;
       try {
         resolutionDir = new File(adapter.resolve(directory.getValue()).getFile());
         RasterIOOptions options = new RasterIOOptions();
         if (crs != null) {
           options.add(RasterIOOptions.CRS, crs.getName());
         }
         AbstractRaster rasterLevel =
             buildTiledRaster(
                 resolutionDir, directory.getFilePattern(), directory.isRecursive(), options);
         // double res = RasterBuilder.getPixelResolution( resolution.getRes(), resolutionDir );
         mrr.addRaster(rasterLevel);
       } catch (MalformedURLException e) {
         LOG.warn(
             "Could not resolve the file {}, corresponding data will not be available.",
             directory.getValue());
       }
     }
     return mrr;
   }
   throw new NullPointerException("The configured multi resolution datasource may not be null.");
 }