Package org.geotools.data

Examples of org.geotools.data.DataSourceException


      //
      // /////////////////////////////////////////////////////////////////
    } catch (IOException e) {
      if (LOGGER.isLoggable(Level.SEVERE))
        LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
      throw new DataSourceException(e);
    }finally{

      mWriter.dispose();
    }
  }
View Full Code Here


    final int swapXY = XAffineTransform.getSwapXY(gridToWorldTransform);
    XAffineTransform.round(gridToWorldTransform, ROTATION_EPS);
    final double rotation = XAffineTransform
        .getRotation(gridToWorldTransform);
    if (swapXY == -1)
      throw new DataSourceException(
          "Impossible to encode this coverage as an ascii grid since its"
              + "transformation is not a simple scale and translate");
    if (rotation != 0)
      throw new DataSourceException(
          "Impossible to encode this coverage as an ascii grid since its"
              + "transformation is not a simple scale and translate");

    // /////////////////////////////////////////////////////////////////////
    //
    // RULE 2
    //
    // Checking the CRS to have flip only at first axis
    //
    // /////////////////////////////////////////////////////////////////////
    final int flip = XAffineTransform.getFlip(gridToWorldTransform);
    final CoordinateReferenceSystem crs2D = ((GridCoverage2D) coverage)
        .getCoordinateReferenceSystem2D();
    // flip==-1 means there is a flip.
    if (flip > 0)
      throw new DataSourceException(
          "Impossible to encode this coverage as an ascii grid since its"
              + "coordinate reference system has strange axes orientation");
    // let's check that its the Y axis that's flipped
    if (!AxisDirection.NORTH.equals(crs2D.getCoordinateSystem().getAxis(1)
        .getDirection()))
      throw new DataSourceException(
          "Impossible to encode this coverage as an ascii grid since its"
              + "coordinate reference system has strange axes orientation");
    if (!AxisDirection.EAST.equals(crs2D.getCoordinateSystem().getAxis(0)
        .getDirection()))
      throw new DataSourceException(
          "Impossible to encode this coverage as an ascii grid since its"
              + "coordinate reference system has strange axes orientation");

    // /////////////////////////////////////////////////////////////////////
    //
    // RULE 3
    //
    // Check that we are actually writing a GridCoverage2D
    //
    // /////////////////////////////////////////////////////////////////////
    if(coverage instanceof GridCoverage2D && !(coverage.getGridGeometry() instanceof GridGeometry2D))
      throw new DataSourceException("The provided coverage is not a GridCoverage2D");
  }
View Full Code Here

            shapeType = ShapeType.ARC;
        } else if (Polygon.class.isAssignableFrom(geomType)
                || MultiPolygon.class.isAssignableFrom(geomType)) {
            shapeType = ShapeType.POLYGON;
        } else {
            throw new DataSourceException("Cannot create a shapefile whose geometry type is "
                    + geomType);
        }

        StorageFile shpStoragefile = shpFiles.getStorageFile(SHP);
        StorageFile shxStoragefile = shpFiles.getStorageFile(SHX);
View Full Code Here

        // get the protocol
        final String protocol = source.getProtocol();

        // file
        if (!(protocol.equalsIgnoreCase("file")||protocol.equalsIgnoreCase("http") || protocol.equalsIgnoreCase("dods"))) {
            throw new DataSourceException("Wrong protocol for URL:"+source.toExternalForm().toString());
        }
        File sourceFile = null;
        if (protocol.equalsIgnoreCase("file")){
            // convert to file
            sourceFile = DataUtilities.urlToFile(source);
           
            // check that it is a file,exists and can be at least read
            if (!sourceFile.exists() || !sourceFile.isFile() || !sourceFile.canRead()){
                throw new DataSourceException("Invalid source");           
            }
        }

        // initialize
        // get the needed info from them to set the extent
        try {
            reader = (NetCDFImageReader) NetCDFDriver.SPI.createReaderInstance();
            if (hints != null && hints.containsKey(Utils.AUXILIARY_FILES_PATH)) {
                String prefix = "";
                if (hints.containsKey(Utils.PARENT_DIR)) {
                    prefix = (String) hints.get(Utils.PARENT_DIR) + File.separatorChar;
                }
                String filePath = prefix + (String) hints.get(Utils.AUXILIARY_FILES_PATH);
                reader.setAuxiliaryFilesPath(filePath);
            }
            reader.setInput(this.source);

            if (names == null) {
                names = new ArrayList<Name>();
                final Collection<Name> originalNames = reader.getCoveragesNames();
                for (Name name : originalNames) {
                    Name coverageName = new NameImpl(/*namePrefix + */name.toString());
                    names.add(coverageName);
                }
            }
        } catch (Exception e) {
            throw new DataSourceException(e);
        }
    }
View Full Code Here

        //
        if (!CRS.equalsIgnoreMetadata(requestCRS, coverageProperties.crs2D))
            try {
                destinationToSourceTransform = CRS.findMathTransform(requestCRS, coverageProperties.crs2D, true);
            } catch (FactoryException e) {
                throw new DataSourceException("Unable to inspect request CRS", e);
            }
        // now transform the requested envelope to source crs
        if (destinationToSourceTransform != null ){
            if (destinationToSourceTransform.isIdentity()) {

                destinationToSourceTransform = null;// the CRS is basically the same
            } else {
                // we do need to reproject
                needsReprojection = true;

                //
                // k, the transformation between the various CRS is not null or the
                // Identity, let's see if it is an affine transform, which case we
                // can incorporate it into the requested grid to world
                if (destinationToSourceTransform instanceof AffineTransform) {

                    //
                    // we should not have any problems with regards to BBOX reprojection
                    // update the requested grid to world transformation by pre concatenating the
                    // destination to source transform
                    AffineTransform mutableTransform = (AffineTransform) requestedGridToWorld
                            .clone();
                    mutableTransform.preConcatenate((AffineTransform) destinationToSourceTransform);

                    // update the requested envelope
                    try {
                        final MathTransform tempTransform = PixelTranslation.translate(
                                ProjectiveTransform.create(mutableTransform),
                                PixelInCell.CELL_CENTER, PixelInCell.CELL_CORNER);
                        requestedBBox = new ReferencedEnvelope(CRS.transform(tempTransform,
                                new GeneralEnvelope(requestedRasterArea)));

                    } catch (Exception e) {
                        throw new DataSourceException("Unable to inspect request CRS", e);
                    }

                    // now clean up all the traces of the transformations
                    destinationToSourceTransform = null;
                    needsReprojection = false;
View Full Code Here

                // the requested raster area
                XRectangle2D.intersect(computedRasterArea, requestedRasterArea, computedRasterArea);

            }
        } catch (Exception e) {
            throw new DataSourceException(e);
        }
       
        // is it empty??
        if (computedRasterArea.isEmpty()) {
View Full Code Here

    protected ShapefileReader openShapeReader(GeometryFactory gf, boolean onlyRandomAccess)
            throws IOException {
        try {
            return new ShapefileReader(shpFiles, true, store.isMemoryMapped(), gf, onlyRandomAccess);
        } catch (ShapefileException se) {
            throw new DataSourceException("Error creating ShapefileReader", se);
        }
    }
View Full Code Here

      finalStreamPreparation();
    } catch (Exception e) {
      if (LOGGER.isLoggable(Level.SEVERE)){
          LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
      }
      throw new DataSourceException(e);
    }

  }
View Full Code Here

    // //
    if (input instanceof File) {
      final File sourceFile = (File) input;
      if (!sourceFile.exists() || sourceFile.isDirectory()
          || !sourceFile.canRead())
        throw new DataSourceException("Provided file does not exist or is a directory or is not readable!");
      this.coverageName = sourceFile.getName();
      final int dotIndex = coverageName.indexOf(".");
      gzipped = coverageName.toLowerCase().endsWith("gz");
      coverageName = (dotIndex == -1) ? coverageName : coverageName
          .substring(0, dotIndex);
      if(gzipped)
                            inStream = ImageIO.createImageInputStream(new GZIPInputStream(
                                new FileInputStream(sourceFile)))
      else{
          inStreamSPI= ImageIOExt.getImageInputStreamSPI(sourceFile);
          if (inStreamSPI == null)
                          throw new DataSourceException(
                                          "No input stream for the provided source");
          inStream = inStreamSPI.createInputStreamInstance(sourceFile, ImageIO.getUseCache(), ImageIO.getCacheDirectory());
      }
    } else
    // //
    //
    // URL
    //
    // //
    if (input instanceof URL) {
      final URL tempURL = ((URL) input);
      input = tempURL.openConnection().getInputStream();
      GZIPInputStream gzInStream = null;
      try {
        gzInStream = new GZIPInputStream((InputStream) input);
        gzipped = false;
      } catch (Exception e) {
        gzipped = false;
      }
      input = tempURL.openConnection().getInputStream();
      inStream = gzipped ? ImageIO.createImageInputStream(gzInStream)
          : ImageIO.createImageInputStream(tempURL.openConnection()
              .getInputStream());
    } else
    // //
    //
    // InputStream
    //
    // //
    if (input instanceof InputStream) {
      closeMe = false;
      if (ImageIO.getUseCache())
        inStream = new FileCacheImageInputStream((InputStream) input,
            null);
      else
        inStream = new MemoryCacheImageInputStream((InputStream) input);
      // let's mark it
      inStream.mark();
    } else
    // //
    //
    // ImageInputStream
    //
    // //
    if (input instanceof ImageInputStream) {
      closeMe = false;
      inStream = (ImageInputStream) input;
      inStream.mark();
    } else
      throw new IllegalArgumentException("Unsupported input type");

    if (inStream == null)
      throw new DataSourceException(
          "No input stream for the provided source");
  }
View Full Code Here

              properties);

    } catch (NoSuchElementException e) {
      if (LOGGER.isLoggable(Level.SEVERE))
        LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
      throw new DataSourceException(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.