Package org.geotools.data

Examples of org.geotools.data.DataSourceException


      final IOException ex = new IOException(
          "WorldImage:No source set to read this coverage.");
      LOGGER.logp(Level.SEVERE, WorldImageReader.class.toString(),
          "WorldImageReader", ex.getLocalizedMessage(), ex);
      throw new DataSourceException(ex);
    }
    this.source=input;
   
    // //
    //
    // managing hints
    //
    // //
    if (this.hints == null)
      this.hints= new Hints()
    if (hints != null) {
            this.hints.add(hints);
    }

                // GridCoverageFactory initialization
                if (this.hints.containsKey(Hints.GRID_COVERAGE_FACTORY)) {
                    final Object factory = this.hints.get(Hints.GRID_COVERAGE_FACTORY);
                    if (factory != null && factory instanceof GridCoverageFactory) {
                        this.coverageFactory = (GridCoverageFactory) factory;
                    }
                }
                if (this.coverageFactory == null) {
                    this.coverageFactory = CoverageFactoryFinder.getGridCoverageFactory(this.hints);
                }
               
    coverageName = "image_coverage";
    try {
      boolean closeMe = true;

      // /////////////////////////////////////////////////////////////////////
      //
      // Source management
      //
      // /////////////////////////////////////////////////////////////////////
      if (input instanceof URL) {
        // URL that point to a file
        final URL sourceURL = ((URL) input);
        if (sourceURL.getProtocol().compareToIgnoreCase("file") == 0) {
          String auth = sourceURL.getAuthority();
          String path = sourceURL.getPath();
          if (auth != null && !auth.equals("")) {
            path = "//"+auth+path;
          }
          this.source = input = new File(URLDecoder.decode(path, "UTF-8"));
        } else if (sourceURL.getProtocol().equalsIgnoreCase("http")) {
          // // getting a stream to the reader
          // this.source = sourceURL.openStream();

          // /////////////////////////////////////////////////////////////////////
          //
          // WMS Request? I want to be able to handle that case too
          //
          // /////////////////////////////////////////////////////////////////////
          wmsRequest = WMSRequest(input);
        }
      }

      // //
      //
      // Name, path, etc...
      //
      // //
      if (input instanceof File) {
        final File sourceFile = (File) input;
        final String filename = sourceFile.getName();
        final int i = filename.lastIndexOf('.');
        final int length = filename.length();
        if (i > 0 && i < length - 1) {
          extension = filename.substring(i + 1).toLowerCase();
        }
        this.parentPath = sourceFile.getParent();
        this.coverageName = filename;
        final int dotIndex = coverageName.lastIndexOf(".");
        coverageName = (dotIndex == -1) ? coverageName : coverageName
            .substring(0, dotIndex);
      } else if (input instanceof URL)
        input = ((URL) input).openStream();
      // //
      //
      // Get a stream in order to read from it for getting the basic
      // information for this coverfage
      //
      // //
      if (input instanceof ImageInputStream){
          closeMe = false;
      }else{
          inStreamSPI= ImageIOExt.getImageInputStreamSPI(source);
          if (inStreamSPI == null)
              throw new DataSourceException(
                      "No input stream for the provided source");
                      inStream = inStreamSPI.createInputStreamInstance( this.source, ImageIO.getUseCache(), ImageIO.getCacheDirectory());
                            
                       
      }
     
      if (inStream == null)
        throw new IllegalArgumentException(
            "No input stream for the provided source");

      // /////////////////////////////////////////////////////////////////////
      //
      // CRS
      //
      // /////////////////////////////////////////////////////////////////////
                        if (!wmsRequest) {
                            final Object tempCRS = this.hints.get(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM);
                            if (tempCRS != null) {
                                this.crs = (CoordinateReferenceSystem) tempCRS;
                                LOGGER.log(Level.WARNING,  "Using forced coordinate reference system ");
                            } else
                                readCRS();
                        }

      // /////////////////////////////////////////////////////////////////////
      //
      // Informations about multiple levels and such
      //
      // /////////////////////////////////////////////////////////////////////
      getHRInfo();

      // release the stream
      if (closeMe)
        inStream.close();
    } catch (IOException e) {
      LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
      throw new DataSourceException(e);
    } catch (TransformException e) {
      LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
      throw new DataSourceException(e);
    }
  }
View Full Code Here


    // TODO optimize this using image file extension when possible
    //
    // //
    final Iterator<ImageReader> it = ImageIO.getImageReaders(inStream);
    if (!it.hasNext())
      throw new DataSourceException("No reader avalaible for this source");
    final ImageReader reader = (ImageReader) it.next();
    readerSPI = reader.getOriginatingProvider();
    reader.setInput(inStream);
   
    //
View Full Code Here

    final ImageReadParam readP = new ImageReadParam();
    if (!wmsRequest) {
      try {
        imageChoice = setReadParams(overviewPolicy,readP, requestedEnvelope, dim);
      } catch (TransformException e) {
        new DataSourceException(e);
      }
    }
    // /////////////////////////////////////////////////////////////////////
    //
    // Reading the source layer
View Full Code Here

    } else {
      // looking for another extension
      final Set<String> ext=WorldImageFormat.getWorldExtension(extension);
      final Iterator<String> it=ext.iterator();
      if(!it.hasNext())
        throw new DataSourceException("Unable to parse extension "+extension);
      do{
      file2Parse = new File(new StringBuffer(base).append((String)it.next()
          ).toString());
      }while(!file2Parse.exists()&&it.hasNext());
     
View Full Code Here

    //
    // Check source
    //
    // //
    if (source == null) {
      throw new DataSourceException("ImagePyramidReader:null source set to read this coverage.");
    }
    this.source = source;
    this.sourceURL = Utils.checkSource(source, uHints);
    if(sourceURL == null) {
        throw new DataSourceException("This plugin accepts only a URL, a File or a String pointing to a directory with a structure similar to the one of gdal_retile!");
    }
   
    // //
    // //
    //
    // get the crs if able to
    //
    // //   
    final URL prjURL = DataUtilities.changeUrlExt(sourceURL, "prj");
    PrjFileReader crsReader=null;
    try {
      crsReader = new PrjFileReader(Channels.newChannel(prjURL.openStream()));
    } catch (FactoryException e) {
      throw new DataSourceException(e);
    }finally{
      try{
        crsReader.close();
      }
      catch (Throwable e) {
View Full Code Here

            if (LOGGER.isLoggable(Level.FINE))
              LOGGER.fine(new StringBuilder("Reprojected envelope ").append(requestedEnvelope.toString()).append(" crs ").append(crs.toWKT()).toString());
          }
        } catch (TransformException e) {
          throw new DataSourceException("Unable to create a coverage for this source", e);
                }
      }
      if (!requestedEnvelope.intersects(this.originalEnvelope, false))
        return null;

      // intersect the requested area with the bounds of this layer
      requestedEnvelope.intersect(originalEnvelope);

    } else {
      requestedEnvelope = new GeneralEnvelope(originalEnvelope);

    }
    requestedEnvelope.setCoordinateReferenceSystem(this.crs);
    // ok we got something to return
    try {
      return loadRequestedTiles(requestedEnvelope, dim, params,overviewPolicy);
    } catch (TransformException e) {
      throw new DataSourceException(e);
    }

  }
View Full Code Here

        checkTypeName(sourceURL, configuration);
        if (hints != null && hints.containsKey(Hints.MOSAIC_LOCATION_ATTRIBUTE)) {
            final String hintLocation = (String) hints
                    .get(Hints.MOSAIC_LOCATION_ATTRIBUTE);
            if (!catalogBean.getLocationAttribute().equalsIgnoreCase(hintLocation)) {
                throw new DataSourceException("wrong location attribute");
            }
        }
        // Create the catalog
        GranuleCatalog catalog = GranuleCatalogFactory.createGranuleCatalog(sourceURL, catalogBean, null,hints);
        File parent = DataUtilities.urlToFile(sourceURL).getParentFile();
View Full Code Here

                    state.setRequestEnvelopeTransformed(new GeneralEnvelope(tmp));
                    state.getRequestEnvelopeTransformed().setCoordinateReferenceSystem(crs);
                } else if (indexX == indexRequestedX && indexY == indexRequestedY) {
                    // everything is fine
                } else {
                    throw new DataSourceException("Unable to resolve the X Axis problem");
                }
            }

            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.fine(new StringBuffer("Reprojected envelope ").append(
                        state.getRequestedEnvelope().toString()).append(" crs ")
                        .append(crs.toWKT()).toString());
            }
        } catch (Exception e) {
            throw new DataSourceException("Unable to create a coverage for this source", e);
        }
    }
View Full Code Here

      try {
        super.outStream = ImageIOExt.createImageOutputStream(null, destination);
      } catch (IOException e) {
        if (LOGGER.isLoggable(Level.SEVERE))
          LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
        throw new DataSourceException(e);
      }
    else if (destination instanceof URL) {
      final URL dest = (URL) destination;
      if (dest.getProtocol().equalsIgnoreCase("file")) {
        File destFile;
        destFile = DataUtilities.urlToFile(dest);
        try {
          super.outStream = ImageIOExt.createImageOutputStream(null, destFile);
        } catch (IOException e) {
          if (LOGGER.isLoggable(Level.SEVERE))
            LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
          throw new DataSourceException(e);
        }
      }

    } else if (destination instanceof OutputStream) {

      try {
        super.outStream = ImageIOExt
            .createImageOutputStream(null, (OutputStream) destination);
      } catch (IOException e) {
        if (LOGGER.isLoggable(Level.SEVERE))
          LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
        throw new DataSourceException(e);
      }

    } else if (destination instanceof ImageOutputStream)
      this.destination = outStream = (ImageOutputStream) destination;
    else
      throw new DataSourceException(
          "The provided destination cannot be used!");
    // //
    //
    // managing hints
    //
View Full Code Here

    public NetCDFReader(Object input, Hints uHints) throws DataSourceException{
        super(input, uHints);
        sourceURL = checkSource(input);

        if (!DRIVER.canProcess(DriverCapabilities.CONNECT, sourceURL, null)) {
            throw new DataSourceException("unable to connect to the specified source " + sourceURL);
        }

        // getting access to the source
        try {
            access = (NetCDFAccess) DRIVER.process(DriverCapabilities.CONNECT, sourceURL, null, uHints, null);
        } catch (IOException e) {
            throw new DataSourceException("Unable to connect", e);
        }
        if (access == null) {
            throw new DataSourceException("Unable to connect");
        }

        LOGGER.info("ACCEPTED: " + source.toString());

        // get the names
View Full Code Here

TOP

Related Classes of org.geotools.data.DataSourceException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.