I do not have time to quickly investigate the issue,
but a quick hack si drawn by the following snippet.
....
//create your coverage
...
//snippet
final PlanarImage image=(PlanarImage) coverage.getRenderedImage();
final Object
r=image.getProperty(ImageReadDescriptor.PROPERTY_NAME_IMAGE_READER);
if(r instanceof ImageReader)
try{
((ImageInputStream)((ImageReader)r).getInput()).close();
}catch (Exception e) {
}
coverage.dispose(true);
reader.dispose();
try{
in.close();
assertTrue(((File)o).delete());
assertFalse(((File)o).exists());
//end of snippet
Note that you would probably add more checks when you try to get the
reader out of your original coverage. The code I put there is a bit
convolute and may easily fail if no reader property is attached to the
image.
Simone.
On Fri, Mar 21, 2008 at 5:07 PM, Simone Giannecchini <[EMAIL PROTECTED]> wrote:
> Ciao Thomas,
> where are you exactly trying to delete the original files in your
> code? That would help me with tracing down the problem.
>
>
> Simone.
>
>
> On Fri, Mar 21, 2008 at 4:59 PM, Thomas Bonavia <[EMAIL PROTECTED]> wrote:
> >
> > I am currently trying to :
> > - get many geotiffs files,
> > - crop them to get only the area i need,
> > - write the new geotiffs,
> > - delete the old geotiffs from my directory.
> >
> > My problem is the next one :
> > When I try to remove the old tiff files, It is impossible...
> > This is my code :
> >
> > for(int i = 0; i < files.length; i++){
> > try{
> > /* We read the coverage and crop it. */
> > reader = new GeoTiffReader(files[i], hints);
> > GridCoverage2D temp = (GridCoverage2D)reader.read(null);
> >
> > /* We crop this coverage and put it into a second coverage.
> > */
> > paramCrop.parameter("Source").setValue(temp);
> > paramCrop.parameter("Envelope").setValue(crop);
> > GridCoverage2D temp2 =
> > (GridCoverage2D)processor.doOperation(paramCrop);
> >
> > /* We write out the new coverage into geotiff file. */
> > File outFile = new
> > File(MSS_ControlProject.getRastersPath()+File.separator+i+".TIF");
> > GeoTiffWriter gtw =
> > (GeoTiffWriter)format.getWriter(outFile);
> >
> > gtw.write(temp2,(GeneralParameterValue[])paramWrite.values().toArray(new
> > GeneralParameterValue[1]));
> >
> > /* We read the new geotiff file. */
> > GeoTiffReader readerNew = new GeoTiffReader(outFile);
> > GridCoverage2D temp3 = (GridCoverage2D)readerNew.read(null);
> >
> > rasters.add(temp3);
> > readers.add(readerNew);
> >
> > temp.dispose(true);
> > reader.dispose();
> >
> > // TODO delete original files
> > // TODO add the creation of overview
> > }catch(DataSourceException dse){
> > }catch(IOException ioe){
> > }catch(CannotCropException cce){
> > cce.printStackTrace();
> > }
> >
> > I tried to simplify the code, just to test, like that :
> >
> > for(int i = 0; i < files.length; i++){
> > try{
> > /* We read the coverage and crop it. */
> > reader = new GeoTiffReader(files[i], hints);
> > GridCoverage2D temp = (GridCoverage2D)reader.read(null);
> >
> > temp.dispose(true);
> > reader.dispose();
> >
> > // TODO delete original files
> > // TODO add the creation of overview
> > }catch(DataSourceException dse){
> > }catch(IOException ioe){
> > }catch(CannotCropException cce){
> > cce.printStackTrace();
> > }
> >
> > But it does not work... Is there somebody who get an idea ?
> > (I tried to start with reader.dispose(), to put false instead of true....)
> >
> > Thanks
> > Thomas
> >
> >
> > ________________________________
> > Discutez gratuitement avec vos amis en vidéo ! Téléchargez Messenger, c'est
> > gratuit !
> > -------------------------------------------------------------------------
> > This SF.net email is sponsored by: Microsoft
> > Defy all challenges. Microsoft(R) Visual Studio 2008.
> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> > _______________________________________________
> > Geotools-devel mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/geotools-devel
> >
> >
>
>
>
> --
> -------------------------------------------------------
> Eng. Simone Giannecchini
> President /CEO GeoSolutions S.A.S.
> Via Carignoni 51
> 55041 Camaiore (LU)
> Italy
>
> phone: +39 0584983027
> fax: +39 0584983027
> mob: +39 333 8128928
>
>
> http://www.geo-solutions.it
>
> -------------------------------------------------------
>
--
-------------------------------------------------------
Eng. Simone Giannecchini
President /CEO GeoSolutions S.A.S.
Via Carignoni 51
55041 Camaiore (LU)
Italy
phone: +39 0584983027
fax: +39 0584983027
mob: +39 333 8128928
http://www.geo-solutions.it
-------------------------------------------------------
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel