Package org.geotools.coverage.grid.io

Examples of org.geotools.coverage.grid.io.GranuleStore


            final GeneralEnvelope envelope,
            final DefaultTransaction transaction,
            final List<PropertiesCollector> propertiesCollectors) throws IOException {
       
        // Retrieving the store and the destination schema
        final GranuleStore store = (GranuleStore) mosaicReader.getGranules(coverageName, false);
        if (store == null) {
            throw new IllegalArgumentException("No valid granule store has been found for: " + coverageName);
        }
        final SimpleFeatureType indexSchema = store.getSchema();
        final SimpleFeature feature = new ShapefileCompatibleFeature(DataUtilities.template(indexSchema));
        store.setTransaction(transaction);
       
        final ListFeatureCollection collection = new ListFeatureCollection(indexSchema);
        final String fileLocation = prepareLocation(configuration, fileBeingProcessed);
        final String locationAttribute = configuration.getParameter(Prop.LOCATION_ATTRIBUTE);

        // getting input granules
        if (inputReader instanceof StructuredGridCoverage2DReader) {
           
            //
            // Case A: input reader is a StructuredGridCoverage2DReader. We can get granules from a source
            //
            // Getting granule source and its input granules
            final GranuleSource source = ((StructuredGridCoverage2DReader) inputReader).getGranules(coverageName, true);
            final SimpleFeatureCollection originCollection = source.getGranules(null);
            final DefaultProgressListener listener = new DefaultProgressListener();
           
            // Getting attributes structure to be filled
            final Collection<Property> destProps = feature.getProperties();
            final Set<Name> destAttributes = new HashSet<Name>();
            for (Property prop: destProps) {
                destAttributes.add(prop.getName());
            }
           
            // Collecting granules
            originCollection.accepts( new AbstractFeatureVisitor(){
                public void visit( Feature feature ) {
                    if(feature instanceof SimpleFeature)
                    {
                            // get the feature
                            final SimpleFeature sourceFeature = (SimpleFeature) feature;
                            final SimpleFeature destFeature = DataUtilities.template(indexSchema);
                            Collection<Property> props = sourceFeature.getProperties();
                            Name propName = null;
                            Object propValue = null;
                           
                            // Assigning value to dest feature for matching attributes
                            for (Property prop: props) {
                                propName = prop.getName();
                                propValue = prop.getValue();
                               
                                // Matching attributes are set
                                if (destAttributes.contains(propName)) {
                                    destFeature.setAttribute(propName, propValue);
                                }
                            }
                           
                            // Set location
                            destFeature.setAttribute(locationAttribute, fileLocation);
                           
                            // delegate remaining attributes set to properties collector
                            updateAttributesFromCollectors(destFeature, fileBeingProcessed, inputReader, propertiesCollectors);
                            collection.add(destFeature);
                           
                            // check if something bad occurred
                            if(listener.isCanceled()||listener.hasExceptions()){
                                if(listener.hasExceptions())
                                    throw new RuntimeException(listener.getExceptions().peek());
                                else
                                    throw new IllegalStateException("Feature visitor has been canceled");
                            }
                    }
                }
            }, listener);
        } else {
            //
            // Case B: old style reader, proceed with classic way, using properties collectors
            //
            feature.setAttribute(indexSchema.getGeometryDescriptor().getLocalName(),
                    GEOM_FACTORY.toGeometry(new ReferencedEnvelope((Envelope) envelope)));
            feature.setAttribute(locationAttribute, fileLocation);
           
            updateAttributesFromCollectors(feature, fileBeingProcessed, inputReader, propertiesCollectors);
            collection.add(feature);
        }

        // drop all the granules associated to the same        
        Filter filter = Utils.FF.equal(Utils.FF.property(locationAttribute), Utils.FF.literal(fileLocation),
                !isCaseSensitiveFileSystem(fileBeingProcessed));
        store.removeGranules(filter);
       
        // Add the granules collection to the store
        store.addGranules(collection);
    }
View Full Code Here


        final GridCoverage coverage = resPool.getGridCoverage(coverageInfo, "regional_currents", bbox, null);
        assertEquals(coverage.getNumSampleDimensions(), 2);

        ((GridCoverage2D) coverage).dispose(true);
        final GridCoverageReader reader = resPool.getGridCoverageReader(coverageInfo, "regional_currents", null);
        final GranuleStore granules = (GranuleStore) ((StructuredGridCoverage2DReader) reader).getGranules("regional_currents", true);
        SimpleFeatureCollection granulesCollection = granules.getGranules(null);
        assertEquals(1, granulesCollection.size());
        final Filter filter = FF.equal(FF.property("location"), FF.literal("sample.grb2"), true);
        final int removed = granules.removeGranules(filter);
        assertEquals (1, removed);
        granulesCollection = granules.getGranules(null);
        assertEquals(0, granulesCollection.size());
        reader.dispose();
    }
View Full Code Here

        public int removeGranules(Filter filter) {
            List<CoverageBand> bands = coverageView.getCoverageBands();
            int removed = 0;
            for (CoverageBand band : bands) {
                String coverageName = band.getInputCoverageBands().get(0).getCoverageName();
                GranuleStore granuleStore;
                try {
                    granuleStore = (GranuleStore) reader.getGranules(coverageName, false);
                    // TODO: We may revisit the #removed granules computation to take into
                    // account cases where we remove different number of records across different
                    // input coverages
                    removed = granuleStore.removeGranules(filter);
                } catch (UnsupportedOperationException e) {
                    LOGGER.log(Level.FINER, e.getMessage(), e);
                } catch (IOException e) {
                    LOGGER.log(Level.FINER, e.getMessage(), e);
                }
View Full Code Here

        // setup deletion filter
        Query q = getResourceQuery();
       
        // perform the delete
        GranuleStore store = (GranuleStore) reader.getGranules(nativeCoverageName, false);
        int removed = store.removeGranules(q.getFilter());
        if(LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine("Removed " + removed + " granules from the reader granule store");
        }
    }
View Full Code Here

TOP

Related Classes of org.geotools.coverage.grid.io.GranuleStore

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.