Hello there

I've been playing around reprojecting imagery and found that everything
works fine with tiny MrSID files. However, when attempting to read a
larger file (e.g.,
ftp://data.massgis.state.ma.us/pub/wave/coqhsid/east/161866.sid), I get
an "OutOfMemoryError: Direct buffer memory" exception.

The reason is probably because I am trying to read everything into
memory (using GridCoverageReader.read(null), which by the way is
deprecated). So, what would be the current suggested way of doing this, 
so that I simply specify the reprojection operation without having to 
read everything? I am aware that the Coverage API is going to change, 
but it would still be good to know how to do things right with the 
current library available.

My current code goes as follows (using GeoTools version 2.5-RC1):


File file = new File("D:\\data\\source.sid");
File destFile = new File("D:\\data\\dest.tif");

AbstractGridFormat gridFormat =
(AbstractGridFormat)GridFormatFinder.findFormat(file);
if (gridFormat instanceof UnknownFormat)
     throw new FactoryException("Cannot find a reader for file " + file);

GridCoverageReader reader = gridFormat.getReader(file, hints);
GridCoverage2D coverage = (GridCoverage2D) reader.read(null);

CoordinateReferenceSystem sourceCRS =
coverage.getCoordinateReferenceSystem();
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");

GridCoverage2D coverageTransf = (GridCoverage2D)
Operations.DEFAULT.resample(coverage, targetCRS);

GeoTiffWriter writer = new GeoTiffWriter(destFile);
writer.write(coverageTransf, null);



Thanks!
Milton

-- 

Milton Jonathan
Grupo GIS e Meio Ambiente
Tecgraf/PUC-Rio
Tel: +55-21-3527-2502


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to