This code does work for me, but now I'm having a new problem. I modified
the code slightly to work with a gzipped file, which I then tested with a
small test file and it worked. I then proceeded to try and operate the
code using a gzipped file around 9Mb and it did not work. This 9Mb file
is, unfortunately, 2.6Gb when uncompressed and thus impractical to store in
an uncompressed format.
I modified the first few lines of code in the following way
InputStream input = new FileInputStream(rasterDatasetPath);
InputStream gzipInput = new GZIPInputStream(input);
ArcGridRaster reader = new ArcGridRaster(new
InputStreamReader(gzipInput), true);
So I basically just created a GZIPInputStream and passed in a value of true
to the ArcGridRaster constructor. This works fine for a small test raster
dataset I created, but when I try it with the aforementioned 9Mb dataset
Eclipse stops with an out of memory error in the DataBufferFloat
class. The stack trace is reproduced below. Can anyone help me with this
new problem? Is there a way for me to retrieve only a portion of the
raster that I need?
Thank you so much for your help so far,
Hari
java.lang.RuntimeException: Cannot construct DataBuffer.
at
com.sun.media.jai.util.DataBufferUtils.constructDataBuffer(DataBufferUtils.java:140)
at
com.sun.media.jai.util.DataBufferUtils.createDataBufferFloat(DataBufferUtils.java:222)
at javax.media.jai.RasterFactory.createBandedRaster(RasterFactory.java:349)
at javax.media.jai.RasterFactory.createBandedRaster(RasterFactory.java:248)
at org.geotools.gce.arcgrid.ArcGridRaster.readRaster(ArcGridRaster.java:366)
at RasterReader.readRaster(RasterReader.java:44)
at Simulator.main(Simulator.java:237)
>Sorry... there was a little bug in my posted code:
>
> In the ASCII import routine the ArcGridRaster-constructor must be called
with a second
>parameter (boolean):
>
> ArcGridRaster reader = new ArcGridRaster(
> new InputStreamReader(input), false );
> -----Urspr ngliche Nachricht-----
> Von: Martin Schmitz <[EMAIL PROTECTED]>
> Gesendet: 17.11.06 16:32:47
> An: [EMAIL PROTECTED]
> Betreff: Re: [Geotools-gt2-users] working with rasters
> Hello,
>
> I did not work with ESRI or ERDAS grids yet, but the following code
segments should work
for ASCII and GeoTiff (using GT2.2.0):
>
> Importing ASCII-Grids
> ===============
> import java.io.InputStream;
> import java.io.InputStreamReader;
> import java.awt.geom.Rectangle2D;
> import java.awt.image.WritableRaster;
> import org.geotools.gce.arcgrid.ArcGridRaster;
> import org.geotools.geometry.Envelope2D;
> import org.geotools.coverage.grid.GridCoverage2D;
> import org.geotools.coverage.grid.GridCoverageFactory;
> ...
> InputStream input = ...;
> ArcGridRaster reader = new ArcGridRaster(
> new InputStreamReader(input) );
> WritableRaster raster = reader.readRaster();
> float x = (float)reader.getXlCorner(); // South West
> float y = (float)reader.getYlCorner(); // South West
> float w = (float)(reader.getNCols() * reader.getCellSize());
> float h = (float)(reader.getNRows() * reader.getCellSize());
> Envelope2D envelope = new Envelope2D(null,
> new Rectangle2D.Float(x,y,w,h));
> GridCoverage2D grid = new GridCoverageFactory().create(
> "My Grid", raster, envelope);
>
>
> Importing GeoTiff-Grids
> ================
> import java.io.File;
> import org.geotools.gce.geotiff.GeoTiffFormat;
> import org.geotools.coverage.grid.GridCoverage2D;
> ...
> File input = ...;
> GeoTiffFormat format = new GeoTiffFormat();
> GridCoverage2D grid =
> (GridCoverage2D)format.getReader(input).read(null);
>
>
> With kind regards...
>
> Martin Schmitz
>
>
> > -----Urspr ngliche Nachricht-----
> > Von: "Hari S. Khalsa" <[EMAIL PROTECTED]>
> > Gesendet: 17.11.06 15:33:33
> > An: [EMAIL PROTECTED]
> > Betreff: [Geotools-gt2-users] working with rasters
>
>
> > Hi All,
> >
> > This is my first post to these forums. I'm currently having an issue
> > relating to working with rasters in Geotools. However, before I
describe
> > it, I was wondering if anyone here could give me some general
help. I've
> > been working with Geotools for a couple of months now but I've just
used it
> > for it's shapefile reading/writing ability and the JTS geometry
> > functionality. All this time, I've been somewhat confused by the
> > organization of the web site and all Geotools resources in
general. I even
> > find this user forum hard to read as it seems that the spacings and
> > carriage returns get messed up in replies to people's
questions. Where is
> > the best place to find help using Geotools? Is it this forum? Is
there a
> > Developer's Guide somewhere because the link on the website to a
developers
> > guide brings up a 404 error
(<http://geotools.codehaus.org/display/GEOT/Home>http://geotools.codehaus.org/display/GEOT/Home)?
> >
> > Currently I'm trying to read in an ERDAS imagine file. I don't think
there
> > is any support for this in Geotools, but I haven't been able to make a
> > definitive determination on this. I converted the ERDAS file into
the ESRI
> > raster format and then into ASCII text hoping to follow the example
given
> > on the following webpage
> >
<http://geotools.codehaus.org/Using+Grid+Coverage+Exchange>http://geotools.codehaus.org/Using+Grid+Coverage+Exchange
> >
> > Unfortunately this example does not work. Can anyone provide me with a
> > method for reading in a raster in any of the three aforementioned
formats
> > (ESRI, ERDAS, or ASCII)? I don't even have a GUI on my code, my
ultimate
> > goal is to simply determine the underlying raster values below a vector
> > polygon. I'm sure I'll have issues with projections later, but for
now I
> > just want to be able to read in the raster data.
> >
> > Thanks,
> > Hari
> >
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users