Package org.geotools.data

Examples of org.geotools.data.DataSourceException


                //
                // Getting metadata
                //
                final Object metadata = reader.getImageMetadata(0);
                if (!(metadata instanceof AsciiGridsImageMetadata)){
                        throw new DataSourceException(
                                        "Unexpected error! Metadata are not of the expected class.");
                }
           
                // casting the metadata
                final AsciiGridsImageMetadata gridMetadata = (AsciiGridsImageMetadata) metadata;
View Full Code Here


           
            // === init targetGrid2World
            initTargetTransformation();

        } catch (Exception e) {
            throw new DataSourceException("Unable to create this mosaic", e);
        }
    }
View Full Code Here

                if (localHints != null) {
                    localHints.add(new Hints(Utils.MOSAIC_READER, this));
                }
                initReaderFromURL(source, localHints);
            } catch (Exception e) {
                throw new DataSourceException(e);
            }
        }
    }
View Full Code Here

     */
    private void initReaderFromDescriptor(final ImageMosaicDescriptor source, final Hints uHints) throws IOException {
        Utilities.ensureNonNull("source", source);
        final MosaicConfigurationBean configuration = source.getConfiguration();
        if (configuration == null) {
            throw new DataSourceException("Unable to create reader for this mosaic since we could not parse the configuration.");
        }
        extractProperties(configuration);
        GranuleCatalog catalog = source.getCatalog();
        if (catalog == null) {
            throw new DataSourceException("Unable to create reader for this mosaic since the inner catalog is null.");
        }

        final SimpleFeatureType schema = catalog.getType(configuration.getCatalogConfigurationBean().getTypeName());
        if (schema == null) {
            throw new DataSourceException("Unable to create reader for this mosaic since the inner catalog schema is null.");
        }
       
        granuleCatalog = catalog;

        // grid geometry
View Full Code Here

    private void initReaderFromURL(final Object source, final Hints hints) throws Exception {
        this.sourceURL = Utils.checkSource(source, hints);
       
        // Preliminar check on source
        if (this.sourceURL == null) {
            throw new DataSourceException(
                    "This plugin accepts File, URL or String. The string may describe a File or an URL");
        }

        // Load properties file
        MosaicConfigurationBean configuration = null;
        try {
            if (sourceURL.getProtocol().equals("file")) {
                final File sourceFile = DataUtilities.urlToFile(sourceURL);
                if (!sourceFile.exists()) {
                    throw new DataSourceException("The specified sourceURL doesn't refer to an existing file");
                }
            }
            if (sourceURL != null) {
                parentDirectory = DataUtilities.urlToFile(sourceURL);
                if (!parentDirectory.isDirectory()) {
                        parentDirectory = parentDirectory.getParentFile();
                }
            }
            configuration = Utils.loadMosaicProperties(sourceURL, this.locationAttributeName);
            if (configuration == null) {
                //
                // do we have a datastore properties file? It will preempt on the shapefile
                //
                final File parent = DataUtilities.urlToFile(sourceURL).getParentFile();

                // this can be used to look for properties files that do NOT define a datastore
                final File[] properties = parent.listFiles((FilenameFilter) FileFilterUtils.and(
                        FileFilterUtils.notFileFilter(FileFilterUtils
                                .nameFileFilter("indexer.properties")), FileFilterUtils.and(
                                FileFilterUtils.notFileFilter(FileFilterUtils
                                        .nameFileFilter("datastore.properties")), FileFilterUtils
                                        .makeFileOnly(FileFilterUtils
                                                .suffixFileFilter(".properties")))));

                // do we have a valid datastore + mosaic properties pair?
                final File datastoreProperties = new File(parent, "datastore.properties");

                // Scan for MosaicConfigurationBeans from properties files
                List<MosaicConfigurationBean> beans = new ArrayList<MosaicConfigurationBean>();
                for (File propFile : properties) {
                    if (Utils.checkFileReadable(propFile) && Utils.loadMosaicProperties(DataUtilities.fileToURL(propFile), "") != null) {
                        configuration = Utils.loadMosaicProperties(DataUtilities.fileToURL(propFile), this.locationAttributeName);
                        if (configuration != null) {
                            beans.add(configuration);
                        }
                    }
                }
               
                // In case we didn't find any configuration bean and datastore properties, we can't do anything
                if (beans.isEmpty() && !datastoreProperties.exists()) {
                    throw new DataSourceException("No mosaic properties file or datastore properties file have been found");
                }
               
                // Catalog initialization from datastore
                GranuleCatalog catalog = null;
                final Properties params = CatalogManager.createGranuleCatalogProperties(datastoreProperties);

                // Since we are dealing with a catalog from an existing store, make sure to scan for all the typeNames on initialization
                final Object typeNames=params.get(Utils.SCAN_FOR_TYPENAMES);
                if (typeNames!=null){
                    params.put(Utils.SCAN_FOR_TYPENAMES, Boolean.valueOf(typeNames.toString()));
                } else {
                    params.put(Utils.SCAN_FOR_TYPENAMES, Boolean.TRUE);
                }
                if (beans.size() > 0) {
                    catalog = GranuleCatalogFactory.createGranuleCatalog(sourceURL, beans.get(0).getCatalogConfigurationBean(), params, getHints());
                } else {
                    catalog = CatalogManager.createGranuleCatalogFromDatastore(parent, datastoreProperties, true, getHints());
                }
                MultiLevelROIProvider rois = MultiLevelROIProviderFactory.createFootprintProvider(parent);
                catalog.setMultiScaleROIProvider(rois);
                if (granuleCatalog != null) {
                    granuleCatalog.dispose();
                }
                granuleCatalog = catalog;

                if (granuleCatalog == null) {
                    throw new DataSourceException("Unable to create index for this URL " + sourceURL);
                }

                // Creating a RasterManager for each mosaic configuration found on disk
                for (MosaicConfigurationBean bean : beans) {
                    // Add a RasterManager on top of this Mosaic configuration bean and initialize it
                    addRasterManager(bean, true);
                }
            } else {
               
                // Old style code: we have a single MosaicConfigurationBean. Use that to create the catalog
                granuleCatalog = CatalogManager.createCatalog(sourceURL, configuration, this.hints);
                File parent = DataUtilities.urlToFile(sourceURL).getParentFile();
                MultiLevelROIProvider rois = MultiLevelROIProviderFactory.createFootprintProvider(parent);
                granuleCatalog.setMultiScaleROIProvider(rois);
                addRasterManager(configuration, true);
            }

        } catch (Throwable e) {
           
            // Dispose catalog
            try {
                if (granuleCatalog != null) {
                    granuleCatalog.dispose();
                }
            } catch (Throwable e1) {
                if (LOGGER.isLoggable(Level.FINEST)) {
                    LOGGER.log(Level.FINEST, e1.getLocalizedMessage(), e1);
                }
            } finally {
                granuleCatalog = null;
            }
           
            // dispose raster managers as well
            try {
                disposeManagers();
            } catch (Throwable e1) {
                if (LOGGER.isLoggable(Level.FINEST)) {
                    LOGGER.log(Level.FINEST, e1.getLocalizedMessage(), e1);
                }
            } finally {
                rasterManagers = null;
            }

            // rethrow
            throw new DataSourceException(e);
        }
    }
View Full Code Here

                    // from the lower coordinate
                    emptyRequest=true;
                  return;
              }
                if (!coverageRequestedRasterArea.intersects(coverageRasterArea))
                    throw new DataSourceException("The crop region is invalid.");
                XRectangle2D.intersect(coverageRequestedRasterArea, coverageRasterArea, coverageRequestedRasterArea);

                if (LOGGER.isLoggable(Level.FINE)) {
                    StringBuffer sb = new StringBuffer(
                            "Adjusted Requested Envelope = ").append(
                                requestedBBox.toString()).append("\n")
                            .append("Requested raster dimension = ").append(
                                    requestedRasterArea.toString()).append("\n")
                            .append("Corresponding raster source region = ")
                            .append(coverageRequestedRasterArea.toString());
                    LOGGER.log(Level.FINE, sb.toString());
                }
                return;
            }
        } catch (TransformException e) {
            throw new DataSourceException(
                    "Unable to create a coverage for this source", e);
        } catch (FactoryException e) {
            throw new DataSourceException(
                    "Unable to create a coverage for this source", e);
        }
       
//        get it all!
        requestedBBox=coverageBBox;
View Full Code Here

        // Getting common metadata from GDAL
        //
        // //
        final IIOMetadata metadata = reader.getImageMetadata(0);
        if (!(metadata instanceof GDALCommonIIOImageMetadata)) {
            throw new DataSourceException("Unexpected error! Metadata should be an instance of the expected class: GDALCommonIIOImageMetadata.");
        }
        parseCommonMetadata((GDALCommonIIOImageMetadata) metadata);

        // //
        //
        // Envelope and CRS checks
        //
        // //
        if (this.crs== null) {
            LOGGER.info("crs not found, proceeding with default crs");
            this.crs=AbstractGridFormat.getDefaultCRS();
        }
       
       
        if (this.originalEnvelope== null) {
            throw new DataSourceException("Unable to compute the envelope for this coverage");
        }

        // setting the coordinate reference system for the envelope, just to make sure we set it
        this.originalEnvelope.setCoordinateReferenceSystem(this.crs);      
    }
View Full Code Here

                }
                return finalImage;
            }

        } catch (IOException e) {
            throw new DataSourceException("Unable to create this mosaic", e);
        } catch (TransformException e) {
            throw new DataSourceException("Unable to create this mosaic", e);
        }
    }
View Full Code Here

        } catch (IOException e) {
            if (LOGGER.isLoggable(Level.SEVERE))
                LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);

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

            throw new DataSourceException(e);
        }
        finally {

            // //
            //
View Full Code Here

                inputFile = sourceFile;
            }

            if (!sourceFile.exists() || sourceFile.isDirectory()
                    || !sourceFile.canRead()) {
                throw new DataSourceException(
                        "Provided file does not exist or is a directory or is not readable!");
            }

            this.parentPath = sourceFile.getParent();
            coverageName = sourceFile.getName();
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.