Package org.geotools.util

Examples of org.geotools.util.DefaultProgressListener


            // 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");
                            }
                    }
                }
View Full Code Here


     * The logger to use for this class.
     */
    private final static Logger LOGGER = Logging.getLogger(GridCoverageProgressAdapterTest.class);
    @Test
    public void testInReadingCanceled() throws Exception{
        final DefaultProgressListener adaptee= new DefaultProgressListener();
        final ProgressListener myListener= new ProgressListener() {
          

            @Override
            public void warningOccurred(String source, String location, String warning) {
                adaptee.warningOccurred(source, location, warning);
               
            }
           
            @Override
            public void started() {
                adaptee.started();
                LOGGER.info("started");
            }
           
            @Override
            public void setTask(InternationalString task) {
                adaptee.setTask(task);
               
            }
           
            @Override
            public void setDescription(String description) {
                adaptee.setDescription(description);
               
            }
           
            @Override
            public void setCanceled(boolean cancel) {
                adaptee.setCanceled(cancel);
                LOGGER.info("canceled");
            }
           
            @Override
            public void progress(float percent) {
                synchronized (this) {
                    try {
                        this.wait(3000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                assertTrue(percent>=0);
                assertTrue(percent<=100);
                adaptee.progress(percent);
                LOGGER.info("progress:"+percent);
               
            }
           
            @Override
            public boolean isCanceled() {
                return adaptee.isCanceled();
            }
           
            @Override
            public InternationalString getTask() {
                return adaptee.getTask();
            }
           
            @Override
            public float getProgress() {
                return adaptee.getProgress();
            }
           
            @Override
            public String getDescription() {
                return adaptee.getDescription();
            }
           
            @Override
            public void exceptionOccurred(Throwable exception) {
                adaptee.exceptionOccurred(exception);
               
            }
           
            @Override
            public void dispose() {
                adaptee.dispose();
               
            }
           
            @Override
            public void complete() {
                adaptee.complete();
                LOGGER.info("completed");
            }
        };
       
       
        // listener
        final GridCoverageReaderProgressAdapter readerAdapter= new GridCoverageReaderProgressAdapter(myListener);
        final InputStream input = TestData.openStream(GridCoverage2D.class, "CHL01195.png");
       
        ImageReader reader = ImageIO.getImageReadersByFormatName("png").next();
        reader.setInput(ImageIOExt.createImageInputStream(input));
        reader.addIIOReadProgressListener(readerAdapter);
        reader.addIIOReadUpdateListener(readerAdapter);
        TimerTask task = new TimerTask() {
           
            @Override
            public void run() {
               readerAdapter.monitor.setCanceled(true);
               
            }
        };
        new Timer().schedule(task, 1500);
        BufferedImage image = reader.read(0);
        reader.dispose();
        image.flush();
        image=null;
       
        if(!PackageUtil.isCodecLibAvailable()) {
            assertFalse(adaptee.isCompleted());
        }
        assertTrue(adaptee.isStarted());
        assertTrue(adaptee.isCanceled());
    }
View Full Code Here

        assertTrue(adaptee.isCanceled());
    }
   
    @Test
    public void testInReading() throws Exception{
        final DefaultProgressListener adaptee= new DefaultProgressListener();
        final ProgressListener myListener= new ProgressListener() {
          

            @Override
            public void warningOccurred(String source, String location, String warning) {
                adaptee.warningOccurred(source, location, warning);
               
            }
           
            @Override
            public void started() {
                adaptee.started();
                LOGGER.info("started");
            }
           
            @Override
            public void setTask(InternationalString task) {
                adaptee.setTask(task);
               
            }
           
            @Override
            public void setDescription(String description) {
                adaptee.setDescription(description);
               
            }
           
            @Override
            public void setCanceled(boolean cancel) {
                adaptee.setCanceled(cancel);
                LOGGER.info("canceled");
            }
           
            @Override
            public void progress(float percent) {
                assertTrue(percent>=0);
                assertTrue(percent<=100);
                adaptee.progress(percent);
                LOGGER.info("progress:"+percent);
               
            }
           
            @Override
            public boolean isCanceled() {
                return adaptee.isCanceled();
            }
           
            @Override
            public InternationalString getTask() {
                return adaptee.getTask();
            }
           
            @Override
            public float getProgress() {
                return adaptee.getProgress();
            }
           
            @Override
            public String getDescription() {
                return adaptee.getDescription();
            }
           
            @Override
            public void exceptionOccurred(Throwable exception) {
                adaptee.exceptionOccurred(exception);
               
            }
           
            @Override
            public void dispose() {
                adaptee.dispose();
               
            }
           
            @Override
            public void complete() {
                adaptee.complete();
                LOGGER.info("completed");
            }
        };
       
       
        // listener
        final GridCoverageReaderProgressAdapter readerAdapter= new GridCoverageReaderProgressAdapter(myListener);
        final InputStream input = TestData.openStream(GridCoverage2D.class, "CHL01195.png");
       
        ImageReader reader = ImageIO.getImageReadersByFormatName("png").next();
        reader.setInput(ImageIOExt.createImageInputStream(input));
        reader.addIIOReadProgressListener(readerAdapter);
        reader.addIIOReadUpdateListener(readerAdapter);
        BufferedImage image = reader.read(0);
        reader.dispose();
        image.flush();
        image=null;
       
        assertTrue(adaptee.isCompleted());
        assertTrue(adaptee.isStarted());
        assertFalse(adaptee.isCanceled());
    }
View Full Code Here

    }
   

    @Test
    public void testInWriting() throws Exception {
        final DefaultProgressListener adaptee= new DefaultProgressListener();
        final ProgressListener myListener= new ProgressListener() {
   
            @Override
            public void warningOccurred(String source, String location, String warning) {
                adaptee.warningOccurred(source, location, warning);
               
            }
           
            @Override
            public void started() {
                adaptee.started();              
            }
           
            @Override
            public void setTask(InternationalString task) {
                adaptee.setTask(task);
               
            }
           
            @Override
            public void setDescription(String description) {
                adaptee.setDescription(description);
               
            }
           
            @Override
            public void setCanceled(boolean cancel) {
                adaptee.setCanceled(cancel);
               
            }
           
            @Override
            public void progress(float percent) {
                assertTrue(percent>=0);
                assertTrue(percent<=100);
                adaptee.progress(percent);
               
            }
           
            @Override
            public boolean isCanceled() {
                return adaptee.isCanceled();
            }
           
            @Override
            public InternationalString getTask() {
                return adaptee.getTask();
            }
           
            @Override
            public float getProgress() {
                return adaptee.getProgress();
            }
           
            @Override
            public String getDescription() {
                return adaptee.getDescription();
            }
           
            @Override
            public void exceptionOccurred(Throwable exception) {
                adaptee.exceptionOccurred(exception);
               
            }
           
            @Override
            public void dispose() {
                adaptee.dispose();
               
            }
           
            @Override
            public void complete() {
                adaptee.complete();
               
            }
        };
       
       
        // listener
        final GridCoverageWriterProgressAdapter writerAdapter= new GridCoverageWriterProgressAdapter(myListener);
        final InputStream input = TestData.openStream(GridCoverage2D.class, "CHL01195.png");
        final BufferedImage image = ImageIO.read(input);
       
        ImageWriter writer = ImageIO.getImageWritersByFormatName("tiff").next();
        writer.setOutput(ImageIOExt.createImageOutputStream(image, TestData.temp(ImageWorkerTest.class, "CHL01195.tif")));
        writer.addIIOWriteProgressListener(writerAdapter);
        writer.addIIOWriteWarningListener(writerAdapter);
        writer.write(image);
        writer.dispose();
       
        assertTrue(adaptee.isCompleted());
        assertTrue(adaptee.isStarted());
        assertFalse(adaptee.isCanceled());
    }
View Full Code Here

        assertFalse(adaptee.isCanceled());
    }
   
    @Test
    public void testInWritingCanceled() throws Exception {
        final DefaultProgressListener adaptee= new DefaultProgressListener();
        final ProgressListener myListener= new ProgressListener() {
   
            @Override
            public void warningOccurred(String source, String location, String warning) {
                adaptee.warningOccurred(source, location, warning);
               
            }
           
            @Override
            public void started() {
                adaptee.started()
                LOGGER.info("started");
            }
           
            @Override
            public void setTask(InternationalString task) {
                adaptee.setTask(task);
               
            }
           
            @Override
            public void setDescription(String description) {
                adaptee.setDescription(description);
               
            }
           
            @Override
            public void setCanceled(boolean cancel) {
                adaptee.setCanceled(cancel);
                LOGGER.info("requesting cancel");
               
            }
           
            @Override
            public void progress(float percent) {
                synchronized (this) {
                    try {
                        this.wait(3000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }               
                assertTrue(percent>=0);
                assertTrue(percent<=100);
                adaptee.progress(percent);
                LOGGER.info("progress:"+percent);               
               
            }
           
            @Override
            public boolean isCanceled() {
                return adaptee.isCanceled();
            }
           
            @Override
            public InternationalString getTask() {
                return adaptee.getTask();
            }
           
            @Override
            public float getProgress() {
                return adaptee.getProgress();
            }
           
            @Override
            public String getDescription() {
                return adaptee.getDescription();
            }
           
            @Override
            public void exceptionOccurred(Throwable exception) {
                adaptee.exceptionOccurred(exception);
               
            }
           
            @Override
            public void dispose() {
                adaptee.dispose();
               
            }
           
            @Override
            public void complete() {
                adaptee.complete();
                LOGGER.info("completed");
            }
        };
       
       
        // listener
        final GridCoverageWriterProgressAdapter writerAdapter= new GridCoverageWriterProgressAdapter(myListener);
        final InputStream input = TestData.openStream(GridCoverage2D.class, "CHL01195.png");
        final BufferedImage image = ImageIO.read(input);
       
        ImageWriter writer = ImageIO.getImageWritersByFormatName("tiff").next();
        writer.setOutput(ImageIOExt.createImageOutputStream(image, TestData.temp(ImageWorkerTest.class, "CHL01195.tif")));
        writer.addIIOWriteProgressListener(writerAdapter);
        writer.addIIOWriteWarningListener(writerAdapter);
        TimerTask task = new TimerTask() {
           
            @Override
            public void run() {
               writerAdapter.monitor.setCanceled(true);
               
            }
        };  
        new Timer().schedule(task, 1000);
        writer.write(image);
        writer.dispose();
       
        assertFalse(adaptee.isCompleted());
        assertTrue(adaptee.isStarted());
        assertTrue(adaptee.isCanceled());
    }
View Full Code Here

        q.getFilter().accept(bboxExtractor, null);
        ReferencedEnvelope requestedBBox=bboxExtractor.getBBox();
        final Geometry intersectionGeometry=requestedBBox!=null?JTS.toGeometry(requestedBBox):null;

        // visiting the features from the underlying store
        final DefaultProgressListener listener = new DefaultProgressListener();
        features.accepts(new AbstractFeatureVisitor() {
            public void visit(Feature feature) {
                if (feature instanceof SimpleFeature) {
                    // get the feature
                    final SimpleFeature sf = (SimpleFeature) feature;
                    GranuleDescriptor granule = null;

                    // caching by granule's location
//                    synchronized (descriptorsCache) {
                        String featureId = sf.getID();
                        if(descriptorsCache.containsKey(featureId)){
                            granule = descriptorsCache.get(featureId);
                        } else{
                            // create the granule descriptor
                            MultiLevelROI footprint = getGranuleFootprint(sf);
                            if(footprint == null || !footprint.isEmpty()) {
                                // caching only if the footprint is eithery absent or present and NON-empty
                                granule = new GranuleDescriptor(
                                                sf,
                                                adaptee.suggestedRasterSPI,
                                                adaptee.pathType,
                                                adaptee.locationAttribute,
                                                adaptee.parentLocation,
                                                footprint,
                                                adaptee.heterogeneous,
                                                adaptee.hints); // retain hints since this may contain a reader or anything
                                descriptorsCache.put(featureId, granule);
                            }
                        }
                       
                        if(granule != null) {
                            // check ROI inclusion
                            final Geometry footprint = granule.getFootprint();
                            if(intersectionGeometry==null||footprint==null||polygonOverlap(footprint, intersectionGeometry)){
                                visitor.visit(granule, null);
                            }else{
                                if(LOGGER.isLoggable(Level.FINE)){
                                    LOGGER.fine("Skipping granule "+granule+"\n since its ROI does not intersect the requested area");
                                }
                            }
                        }
   
                        // 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 for query " + q
                                        + " has been canceled");
                            }
                        }
View Full Code Here

            if (LOGGER.isLoggable(Level.FINE))
                LOGGER.fine("Index Loaded");

            // visiting the features from the underlying store
            final DefaultProgressListener listener = new DefaultProgressListener();
            features.accepts(new AbstractFeatureVisitor() {
                public void visit(Feature feature) {
                    if (feature instanceof SimpleFeature) {
                        // get the feature
                        final SimpleFeature sf = (SimpleFeature) feature;
                        MultiLevelROI footprint = getGranuleFootprint(sf);
                        if(footprint == null || !footprint.isEmpty()) {
                            final GranuleDescriptor granule = new GranuleDescriptor(sf,
                                    suggestedRasterSPI, pathType, locationAttribute, parentLocation,
                                    footprint,
                                    heterogeneous, q.getHints());
   
                            visitor.visit(granule, null);
                        }

                        // 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 for query " + q
                                        + " has been canceled");
                            }
                        }
View Full Code Here

        FeatureTypeInfo ti = getCatalog().getFeatureTypeByName(getLayerId(MockData.POLYGONS));
        SimpleFeatureCollection rawSource = (SimpleFeatureCollection) ti.getFeatureSource(null,
                null).getFeatures();

        final DefaultProgressListener progressListener = new DefaultProgressListener();
        try {
            // Download the features. It should throw an exception.
            downloadProcess.execute(getLayerId(MockData.POLYGONS), // layerName
                    null, // filter
                    "IAmWrong!!!", // outputFormat
View Full Code Here

        private SimpleFeatureCollection join(SimpleFeatureCollection inputCollection,
                CoverageBand band, final String coverageName) throws IOException {
            // TODO Improve this by doing batch join and storing the result into memory

            final DefaultProgressListener listener = new DefaultProgressListener();
            final ListFeatureCollection collection = new ListFeatureCollection(schema);
            // Getting attributes structure to be filled

            inputCollection.accepts(new AbstractFeatureVisitor() {
                public void visit(Feature feature) {
                    if (feature instanceof SimpleFeature) {
                        // get the feature
                        final SimpleFeature sourceFeature = (SimpleFeature) feature;
                        Collection<Property> props = sourceFeature.getProperties();
                        Name propName = null;
                        Object propValue = null;

                        // Assigning value to dest feature for matching attributes
                        Filter filter = null;
                        for (Property prop : props) {
                            propName = prop.getName();
                            if (
                            !propName.getLocalPart().equalsIgnoreCase("imageIndex")
                                    && !propName.getLocalPart().equalsIgnoreCase("the_geom")
                                    && !propName.getLocalPart().equalsIgnoreCase("location")) {
                                propValue = prop.getValue();
                                Filter updatedFilter = Utils.FF.equal(Utils.FF.property(propName),
                                        Utils.FF.literal(propValue), true);
                                if (filter == null) {
                                    filter = updatedFilter;
                                } else {
                                    filter = FF.and(filter, updatedFilter);
                                }
                            }
                        }
                        Query query = new Query();
                        query.setFilter(filter);
                        SimpleFeatureCollection coverageCollection;
                        try {
                            coverageCollection = reader.getGranules(coverageName, readOnly)
                                    .getGranules(query);
                            coverageCollection.accepts(new AbstractFeatureVisitor() {
                                public void visit(Feature feature) {
                                    if (feature instanceof SimpleFeature) {
                                        // get the feature
                                        final SimpleFeature destFeature = DataUtilities
                                                .template(schema);
                                        Collection<Property> props = destFeature.getProperties();
                                        Name propName = null;
                                        Object propValue = null;

                                        // Assigning value to dest feature for matching attributes
                                        for (Property prop : props) {
                                            propName = prop.getName();
                                            propValue = ((SimpleFeature) feature)
                                                    .getAttribute(propName);
                                            // Matching attributes are set

                                            destFeature.setAttribute(propName, propValue);
                                        }
                                        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);
                        } catch (IOException e) {
                            LOGGER.log(Level.FINER, e.getMessage(), e);
                        } catch (UnsupportedOperationException e) {
                            LOGGER.log(Level.FINER, e.getMessage(), e);
                        }

                        // 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");
                        }
                    }
                }
View Full Code Here

     */
    public static GridCoverage2DReader getCoverageReader(CoverageInfo ci)
            throws IOException, Exception {
        // get a reader for this coverage
        final CoverageStoreInfo store = (CoverageStoreInfo) ci.getStore();
        final GridCoverageReader reader_ = ci.getGridCoverageReader(new DefaultProgressListener(), GeoTools.getDefaultHints());
        if (reader_ == null) {
            throw new Exception("Unable to acquire a reader for this coverage with format: "
                    + store.getFormat().getName());
        }
        final GridCoverage2DReader reader = (GridCoverage2DReader) reader_;
View Full Code Here

TOP

Related Classes of org.geotools.util.DefaultProgressListener

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.