Hi again,
see my response bellow:

El día 5 de octubre de 2009 22:24, Simone Giannecchini
<[email protected]> escribió:
> Ciao Cesar,
[SNIP]
> This is probably the worst way to work with a PlanarImage. I dag once
> those bindings and I told Victor that he was loading everything into
> memory doing that. Actually not only that, that code cobbles the
> original raster into a single untiled raster in memory, performing a
> full copy! Rather inefficient I would say :-)
[SNIP]
> the goal is to use iterators to do the processing, or anyway to do it
> tile by tile in order to avoid copies and/or loading everything into
> memory.
>
> Simone.


Thanks a lot for the links and suggestions. I've read this
documentation, and if I've correctly understood there are two
different possible approaches:
- Using iterators
- Using tiles

I've tried both of them, but I've also found an error in the process.
As I'm a JAI and GeoTools beginner, I'm not sure if there is a problem
in the driver or I misunderstood documentation.

I paste relevant code bellow:

----------------- ITERATOR APPROACH -----
        ArcGridFormat agf = new ArcGridFormat();
        GridCoverageReader reader = agf.getReader(file);
        GridCoverage2D gc = (GridCoverage2D) reader.read(null);
        PlanarImage img = (PlanarImage) gc.geophysics(true).getRenderedImage();
        RectIter iter = RectIterFactory.create(img, null);
        iter.startBands();
    while (!iter.finishedBands()) {
        iter.startLines();
        while (!iter.finishedLines()) {
            iter.startPixels();
            while (!iter.finishedPixels()) {
                int value = iter.getSample();
                if (value!=9999 && value!=-9999) {
                        System.out.println(value);
                }
                iter.nextPixel();
            }
            iter.nextLine();
        }
        iter.nextBand();
    }

-----------------

After some time running, I get the following exception:
java.lang.IllegalArgumentException: pos < flushedPos!
        at 
it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl.seek(FileImageInputStreamExtImpl.java:285)
        at 
it.geosolutions.imageio.plugins.arcgrid.raster.AsciiGridRaster.readRaster(AsciiGridRaster.java:578)
        at 
it.geosolutions.imageio.plugins.arcgrid.AsciiGridsImageReader.readRaster(AsciiGridsImageReader.java:659)
        at 
it.geosolutions.imageio.plugins.arcgrid.AsciiGridsImageReader.read(AsciiGridsImageReader.java:520)
        at 
com.sun.media.jai.imageioimpl.ImageReadOpImage.computeTile(ImageReadOpImage.java:697)
        at 
com.sun.media.jai.util.SunTileScheduler.scheduleTile(SunTileScheduler.java:904)
        at javax.media.jai.OpImage.getTile(OpImage.java:1129)
        at javax.media.jai.RenderedOp.getTile(RenderedOp.java:2257)
        at etclusi.tests.gt.TestArcGrid2.main(TestArcGrid2.java:48)


I have also tried with tiles, but I get the same error.
I assume in this code that the tiles are automatically managed by the
PlanarImage and are not kept in memory (except the tiles that I ask
for and I keep referencing), but I'm not sure if this assumption is
correct...

---------------------- TILES APPROACH --------------------

        ArcGridFormat agf = new ArcGridFormat();
        GridCoverageReader reader = agf.getReader(file);
        GridCoverage2D gc = (GridCoverage2D) reader.read(null);
        PlanarImage img = (PlanarImage) gc.geophysics(true).getRenderedImage();
        
        for (int j=img.getMinTileY(), maxTileY = img.getMaxTileY();
j<=maxTileY ; j++) {
                for (int i=img.getMinTileX(), maxTileX = img.getMaxTileX();
i<=maxTileX; i++) {
                        Raster tile = img.getTile(i, j);
                        for (int y=tile.getMinY(), maxY = tile.getHeight()+y; 
y<maxY; y++) {
                                for (int x=tile.getMinX(), maxX = 
tile.getWidth()+x; x<maxX; x++) {             
                                        int value = tile.getSample(x, y, 0); // 
assume band 0
                                                System.out.println("x: "+x+", 
y: "+y+", value: "+ value);

                                }
                        }               
                }
        }

-------------------------------

Again, after a while:

java.lang.IllegalArgumentException: pos < flushedPos!
        at 
it.geosolutions.imageio.stream.input.FileImageInputStreamExtImpl.seek(FileImageInputStreamExtImpl.java:285)
        at 
it.geosolutions.imageio.plugins.arcgrid.raster.AsciiGridRaster.readRaster(AsciiGridRaster.java:578)
        at 
it.geosolutions.imageio.plugins.arcgrid.AsciiGridsImageReader.readRaster(AsciiGridsImageReader.java:659)
        at 
it.geosolutions.imageio.plugins.arcgrid.AsciiGridsImageReader.read(AsciiGridsImageReader.java:520)
        at 
com.sun.media.jai.imageioimpl.ImageReadOpImage.computeTile(ImageReadOpImage.java:697)
        at 
com.sun.media.jai.util.SunTileScheduler.scheduleTile(SunTileScheduler.java:904)
        at javax.media.jai.OpImage.getTile(OpImage.java:1129)
        at javax.media.jai.RenderedOp.getTile(RenderedOp.java:2257)
        at etclusi.tests.gt.TestArcGrid2.main(TestArcGrid2.java:70)



So I don't know if there is an error in my code, or it is a problem
with the driver.

By the way, I've also seen all these methods "getDataBlock"
(deprecated), "evaluate"... in the GridCoverage interface, and I
wonder which is the preferred/intended way to access the pixel values
in GeoTools.

Best regards,

César Martínez Izquierdo



-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   César Martínez Izquierdo
   GIS developer
   -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
   ETC-LUSI: http://etc-lusi.eionet.europa.eu/
   Universitat Autònoma de Barcelona (SPAIN)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to