Package org.geotools.data

Examples of org.geotools.data.DataSourceException


        try {
            requestedWorldToGrid = (MathTransform2D) PixelTranslation.translate(
                    ProjectiveTransform.create(requestedGridToWorld), PixelInCell.CELL_CENTER,
                    PixelInCell.CELL_CORNER).inverse();
        } catch (NoninvertibleTransformException e) {
            throw new DataSourceException(e);
        }

        if (destinationToSourceTransform == null || destinationToSourceTransform.isIdentity()) {

            // now get the requested bbox which have been already adjusted and project it back to
            // raster space
            try {
                destinationRasterArea = new GeneralGridEnvelope(CRS.transform(requestedWorldToGrid,
                        new GeneralEnvelope(cropBBox)), PixelInCell.CELL_CORNER, false)
                        .toRectangle();
            } catch (IllegalStateException e) {
                throw new DataSourceException(e);
            } catch (TransformException e) {
                throw new DataSourceException(e);
            }
        } else {
            //
            // reproject the crop bbox back and then crop, notice that we are imposing
            //
            try {
                final GeneralEnvelope cropBBOXInRequestCRS = new GeneralEnvelope(CRS.transform(
                        cropBBox, requestCRS));
                cropBBOXInRequestCRS.setCoordinateReferenceSystem(requestedBBox
                        .getCoordinateReferenceSystem());
                // make sure it falls within the requested envelope
                cropBBOXInRequestCRS.intersect(requestedBBox);

                // now go back to raster space
                destinationRasterArea = new GeneralGridEnvelope(CRS.transform(requestedWorldToGrid,
                        cropBBOXInRequestCRS), PixelInCell.CELL_CORNER, false).toRectangle();
                // intersect with the original requested raster space to be sure that we stay within
                // the requested raster area
                XRectangle2D.intersect(destinationRasterArea, requestedRasterArea,
                        destinationRasterArea);
            } catch (NoninvertibleTransformException e) {
                throw new DataSourceException(e);
            } catch (TransformException e) {
                throw new DataSourceException(e);
            }
        }
        // is it empty??
        if (destinationRasterArea.isEmpty()) {
            if (LOGGER.isLoggable(Level.FINE)) {
View Full Code Here


        // Setting input
        //
        if (input == null) {
            final IOException ex = new IOException(Errors.format(ErrorKeys.NULL_ARGUMENT_$1,
                    "input"));
            throw new DataSourceException(ex);
        }
        this.source = input;

    }
View Full Code Here

                requestedRes[0] = envelope.getSpan(0) / dim.getWidth();
                requestedRes[1] = envelope.getSpan(1) / dim.getHeight();
            }
            return requestedRes;
        } catch (TransformException e) {
            throw new DataSourceException("Unable to get resolution", e);
        } catch (FactoryException e) {
            throw new DataSourceException("Unable to get resolution", e);
        }
    }
View Full Code Here

      final int dotIndex = coverageName.lastIndexOf('.');
      if (dotIndex != -1 && dotIndex != coverageName.length())
        coverageName = coverageName.substring(0, dotIndex);

    } catch (IOException e) {
      throw new DataSourceException(e);
    }finally{
      // /////////////////////////////////////////////////////////////////////
      //
      // Freeing streams
      //
View Full Code Here

                }
                crs = AbstractGridFormat.getDefaultCRS();
            }

            if (this.raster2Model == null) {
                throw new DataSourceException("Raster to Model Transformation is not available");
            }

            // create envelope using corner transformation
            final AffineTransform tempTransform = new AffineTransform(
                    (AffineTransform) raster2Model);
            tempTransform.concatenate(CoverageUtilities.CENTER_TO_CORNER);
            originalEnvelope = CRS.transform(ProjectiveTransform.create(tempTransform),
                    new GeneralEnvelope(actualDim));
            originalEnvelope.setCoordinateReferenceSystem(crs);

            // ///
            //
            // setting the higher resolution available for this coverage
            //
            // ///
            highestRes = new double[2];
            highestRes[0] = XAffineTransform.getScaleX0(tempTransform);
            highestRes[1] = XAffineTransform.getScaleY0(tempTransform);

            if (ovrInStreamSPI != null) {
                ovrReader = READER_SPI.createReaderInstance();
                ovrStream = ovrInStreamSPI.createInputStreamInstance(ovrSource,
                        ImageIO.getUseCache(), ImageIO.getCacheDirectory());
                ovrReader.setInput(ovrStream);
                // this includes the real image as this is a image index, we need to add one.
                extOvrImgChoice = numOverviews + 1;
                numOverviews = numOverviews + ovrReader.getNumImages(true);
                if (numOverviews < extOvrImgChoice)
                    extOvrImgChoice = -1;
            }
           
           
            // //
            //
            // get information for the successive images
            //
            // //
            if (numOverviews >= 1) {
                overViewResolutions = new double[numOverviews][2];
                // Internal overviews start at 1, so lastInternalOverview matches numOverviews if no
                // external.
                int firstExternalOverview = extOvrImgChoice == -1 ? numOverviews : extOvrImgChoice - 1;
                double spanRes0 = highestRes[0] * this.originalGridRange.getSpan(0);
                double spanRes1 = highestRes[1] * this.originalGridRange.getSpan(1);
                for (int i = 0; i < firstExternalOverview; i++) {
                    overViewResolutions[i][0] = spanRes0 / reader.getWidth(i + 1);
                    overViewResolutions[i][1] = spanRes1 / reader.getHeight(i + 1);
                }
                for (int i = firstExternalOverview; i < numOverviews; i++) {
                    overViewResolutions[i][0] = spanRes0 / ovrReader.getWidth(i - firstExternalOverview);
                    overViewResolutions[i][1] = spanRes1 / ovrReader.getHeight(i - firstExternalOverview);
                }
              
            } else
                overViewResolutions = null;
        } catch (Throwable e) {
            throw new DataSourceException(e);
        } finally {
            if (reader != null)
                try {
                    reader.dispose();
                } catch (Throwable t) {
View Full Code Here

    Integer imageChoice = new Integer(0);
    final ImageReadParam readP = new ImageReadParam();
    try {
      imageChoice = setReadParams(overviewPolicy, readP,requestedEnvelope, dim);
    } catch (TransformException e) {
      new DataSourceException(e);
    }

    //
    // IMAGE READ OPERATION
    //
        Hints newHints = null;
    if(suggestedTileSize!=null){
        newHints= (Hints) hints.clone();
            final ImageLayout layout = new ImageLayout();
            layout.setTileGridXOffset(0);
            layout.setTileGridYOffset(0);
            layout.setTileHeight(suggestedTileSize[1]);
            layout.setTileWidth(suggestedTileSize[0]);
            newHints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout));
    }
    final ParameterBlock pbjRead = new ParameterBlock();
        if (extOvrImgChoice >= 0 && imageChoice >= extOvrImgChoice) {
            pbjRead.add(ovrInStreamSPI.createInputStreamInstance(ovrSource, ImageIO.getUseCache(),ImageIO.getCacheDirectory()));
            pbjRead.add(imageChoice - extOvrImgChoice);
        } else {
            pbjRead.add(inStreamSPI != null ? inStreamSPI.createInputStreamInstance(source, ImageIO.getUseCache(), ImageIO.getCacheDirectory()) : ImageIO.createImageInputStream(source));
            pbjRead.add(imageChoice);
        }
      pbjRead.add(Boolean.FALSE);
    pbjRead.add(Boolean.FALSE);
    pbjRead.add(Boolean.FALSE);
    pbjRead.add(null);
    pbjRead.add(null);
    pbjRead.add(readP);
    pbjRead.add(READER_SPI.createReaderInstance());
    RenderedOp coverageRaster=JAI.create("ImageRead", pbjRead,newHints!=null?(RenderingHints) newHints:null);
   
        //
        // MASKING INPUT COLOR as indicated
        //
    if(inputTransparentColor!=null){
        coverageRaster= new ImageWorker(coverageRaster).setRenderingHints(newHints).makeColorTransparent(inputTransparentColor).getRenderedOperation();
    }
   
    //
    // BUILDING COVERAGE
    //
        // I need to calculate a new transformation (raster2Model)
        // between the cropped image and the required
        // adjustedRequestEnvelope
        final int ssWidth = coverageRaster.getWidth();
        final int ssHeight = coverageRaster.getHeight();
        if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.log(Level.FINE, "Coverage read: width = " + ssWidth+ " height = " + ssHeight);
        }

        // //
        //
        // setting new coefficients to define a new affineTransformation
        // to be applied to the grid to world transformation
        // -----------------------------------------------------------------------------------
        //
        // With respect to the original envelope, the obtained planarImage
        // needs to be rescaled. The scaling factors are computed as the
        // ratio between the cropped source region sizes and the read
        // image sizes.
        //
        // //
        final double scaleX = originalGridRange.getSpan(0) / (1.0 * ssWidth);
        final double scaleY = originalGridRange.getSpan(1) / (1.0 * ssHeight);
        final AffineTransform tempRaster2Model = new AffineTransform((AffineTransform) raster2Model);
        tempRaster2Model.concatenate(new AffineTransform(scaleX, 0, 0, scaleY, 0, 0));
        try{
          return createCoverage(coverageRaster, ProjectiveTransform.create((AffineTransform) tempRaster2Model));
        }catch(Exception e){
          // dispose and close file
          ImageUtilities.disposePlanarImageChain(coverageRaster);
         
          // rethrow
          if(e instanceof DataSourceException){
            throw (DataSourceException)e;
          }
          throw new DataSourceException(e);
        }


  }
View Full Code Here

            goTo((int) offset);

        } catch (IOException ioe) {
            count = -1;
            // What now? This seems arbitrarily appropriate !
            throw new DataSourceException("Problem reading shapefile record",
                    ioe);
        }
        return count;
    }
View Full Code Here

        // If no sufficient information have been found to set the
        // envelope, try other ways, such as looking for a WorldFile
        //
        // //
        if (this.nativeEnvelope == null) {
                throw new DataSourceException(
                        "Unavailable envelope for this coverage");
        }

        // setting the coordinate reference system for the envelope
        originalEnvelope = getCoverageEnvelope();
View Full Code Here

        // Check source
        //
        // /////////////////////////////////////////////////////////////////////
        this.sourceURL = Utils.checkSource(source);
        if (this.sourceURL == null)
            throw new DataSourceException(
                    "This plugin accepts only File,  URL and String pointing to a file");

        final File inputFile = DataUtilities.urlToFile(sourceURL);
        if (inputFile == null)
            throw new DataSourceException("Unable to find a file for the provided source");
        parentPath = inputFile.getParent();
        ImageReader reader = null;
        final ImageInputStream stream = ImageIO.createImageInputStream(inputFile);
        if (cachedSPI == null) {
            reader = Utils.getReader(stream);
            if (reader != null)
                cachedSPI = reader.getOriginatingProvider();
        }

        if (reader == null)
            throw new DataSourceException("No reader found for that source " + sourceURL);
        reader.setInput(stream);
       

        // //
        //
        // ImageLayout
        //
        // //
        setLayout(reader);

        coverageName = inputFile.getName();

        final int dotIndex = coverageName.lastIndexOf(".");
        coverageName = (dotIndex == -1) ? coverageName : coverageName.substring(0, dotIndex);

        // //
        //
        // get the crs if able to
        //
        // //
        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 "+crs.toWKT());
        } else {

            setCoverageProperties(reader);

            if (crs == null) {
                throw new DataSourceException("Unable to find a CRS for this coverage, using a default one: "
                                + crs.toWKT());
            }
        }
        setResolutionInfo(reader);
        reader.dispose();
View Full Code Here

                    values.add(p);
                }
            }
            target.setValue(values);
        } catch (DataSourceException e) {
            throw new DataSourceException("Unable to clean empty element", e);
        }
    }
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.