Ciao Tim,
I think we could try to avoid the write-to-disk-and-read-back step.
Did you try to follow my advice about not drawing on the same input
image?

Ciao,
Simone.

On 8/27/07, Tim Englich <[EMAIL PROTECTED]> wrote:
> Hello Simone,
>
> I try out your example.
> No everything works after I have stored the image to disk and read it as an
> RenderedImage.
> Thank you for your help.
>
> Tim
>
> -----Ursprüngliche Nachricht-----
> Von: Simone Giannecchini [mailto:[EMAIL PROTECTED]
> Gesendet: Freitag, 24. August 2007 23:58
> An: Jody Garnett
> Cc: Tim Englich; Martin Desruisseaux;
> [email protected]
> Betreff: Re: [Geotools-gt2-users] Image Transformation form one CRS to
> an other
>
>
> Ciao Jody,
> be aware that the code I sent back to Tim is not really an example per
> se but it is done in that way to reproduce (at least to try to
> reproduce) Tim's problem.
> If you have in mind a couple of snippets you would like to see for
> coverages you can send an email and next week I will put together some
> code for which you could put together some doc. How does that sound?
> :-)
>
> This is for Tim, try the code I sent you and afterwards try to follow
> the advice I gave you about NOT drawing on the source image. If you
> still have problems I'll try to help you again next week (I will be
> back on tue).
>
>
> Ciao guys,
> Simone.
>
> On 8/24/07, Jody Garnett <[EMAIL PROTECTED]> wrote:
> > Yeah Simone,
> >
> > This will serve not only as a resample example but as the first example
> > for WorldImageReader (you guys really never use the FormatFinder do you?).
> >
> > I have updated the wiki page with this new example:
> > - http://docs.codehaus.org/display/GEOTDOC/05+Resample+Operation
> >
> > Tim perhaps you like me find Simone's example confusing ? When I get a
> > break I am going to place it into demos/examples and step through it
> > with a debugger and see if I can figure out how it works. If you get any
> > insights please let me know.
> >
> > Jody
> > > Ok,
> > > I played with the code you sent me:
> > >
> > > 1>You are doing a strange thing here. You are creating a BufferedImage
> > > to feed it to a Coverage, then you are reprojecting it, which by the
> > > way creates a new RenderedImage having as a source the original
> > > BufferedImage. Then you try to draw this reproject image onto the
> > > first one. I see that you might want to do some god memory reusing by
> > > reusing the first one but it might be a bit risky to overwrite the
> > > source image. You are basically creating  reprojected image B from
> > > original image A (which btw is BufferedImage, hence it is all in
> > > memory untiled) where B is a tiled PlanarImage using a deferred model
> > > which causes computation only on demand. Then you are drawing image B
> > > back onto A. You like to risk huh? :-)
> > >
> > > In some cases this should cause a lot of pains, especially with
> > > operations that needs more than one source tile to compute an output
> > > tile (high order interpolation is involved or convolutions). Anyway
> > > let's try the code...
> > >
> > > 2>I adapted a bit the code as shown below (copy and paste in an editor
> > > if you see it jaggled):
> > >
> > >
> > >       public void test() throws FactoryException, IOException {
> > >
> > >               // //
> > >               //
> > >               // Here below you have how to correctly create an envelope
> for a
> > >               // coverage.
> > >               //
> > >               // //
> > >               // final GeneralEnvelope sourceEnvelope = new
> GeneralEnvelope(
> > >               // new double[] { -180, -90 }, new double[] { 180, 90 });
> > >               //
> sourceEnvelope.setCoordinateReferenceSystem(CRS.decode("EPSG:4326",
> > >               // true));
> > >
> > >               // get a reader for the image
> > >               final WorldImageReader wiReader = new WorldImageReader(new
> File(
> > >                               "D:\\data\\ikonos_rgb\\ikonos_rgb.tif"));
> > >               // get the coverage
> > >               GridCoverage2D coverage = (GridCoverage2D)
> wiReader.read(null);
> > >
> > >               // now that we have the input image let's try to mess it up
> writing onto
> > >               // a new bufferedimage with a strange color model
> > >               final BufferedImage bi = new
> BufferedImage(coverage.getGridGeometry()
> > >                               .getGridRange().getLength(0),
> coverage.getGridGeometry()
> > >                               .getGridRange().getLength(1),
> BufferedImage.TYPE_INT_BGR);
> > >               ((Graphics2D) bi.getGraphics())
> > >
> .drawRenderedImage(coverage.getRenderedImage(), AffineTransform
> > >                                               .getTranslateInstance(0,
> 0));
> > >               coverage =
> FactoryFinder.getGridCoverageFactory(null).create(
> > >                               "I_need_a_long_vacation", bi,
> coverage.getEnvelope());
> > >
> > >               // resample the created coverage
> > >               coverage = (GridCoverage2D)
> Operations.DEFAULT.resample(coverage,
> > >                               CRS.decode("EPSG:32633"));
> > >               final RenderedImage resampled =coverage.getRenderedImage();
> > >
> > >               // Painting some other BufferedImages PNG or JPEGS on the
> Canvas of
> > >               // by using
> > >               // the bi.getGraphics().drawImage(Image,..) Method
> > >               ((Graphics2D)
> bi.getGraphics()).drawRenderedImage(resampled,
> > >                               AffineTransform.getTranslateInstance(0,
> 0));
> > >
> > >               // write it down
> > >               ImageIO.write(bi, "tiff", new File("d:\\data\\b.tif"));
> > >
> > >       }
> > >
> > > Surprise, surpise it works perfectly for me! This is funny (at least
> > > for me :-) for you I bet is annoying!).
> > > Let's try to ddig a bit more. I need to know: platform, geotools
> > > version, JAI version (do you have native libs installed?).
> > > Could you try to avoid drawing on the source image? I rather create a
> > > sibling one.
> > >
> > > Talk to you soon.
> > > Simone.
> > >
> > > PS:
> > > Not to soon, the elba island is waiting for me, I won't be back until
> > > tuesday 28th of august!
> > >
> > >
> > >
> > > On 8/23/07, Jody Garnett <[EMAIL PROTECTED]> wrote:
> > >
> > >> Thanks Martin/Tim I have updated the wiki with this description of
> resample:
> > >> - http://docs.codehaus.org/display/GEOTDOC/05+Resample+Operation
> > >>
> > >> I also added this question to the referencing FAQ:
> > >> - http://docs.codehaus.org/display/GEOTDOC/11+Referencing+FAQ
> > >>
> > >> Cheers,
> > >> Jody
> > >>
> > >> Martin Desruisseaux wrote:
> > >>
> > >>> Tim Englich a écrit :
> > >>>
> > >>>
> > >>>>> I am looking for a possibility to transform an georefrenced image to
> an
> > >>>>> other coordinatereferencesystem.
> > >>>>> E.g. from EPSG:4326 to EPSG:32632
> > >>>>> Provide GeoTools such a functionality? Do anyone know a
> (Java)-library
> > >>>>> which can do that.
> > >>>>>
> > >>>>>
> > >>> CoordinateReference sourceCRS = CRS.decode("EPSG:4326");
> > >>> CoordinateReference targetCRS = CRS.decode("EPSG:32632");
> > >>> RenderedImage image = ...
> > >>> Envelope imageEnvelope = ...
> > >>> imageEnvelope.setCoordinateReferenceSystem(sourceCRS);
> > >>> GridCoverage2D coverage = coverageFactory.create("My coverage", image,
> envelope);
> > >>> coverage = Operations.DEFAULT.resample(coverage, targetCRS);
> > >>>
> > >>>
> > >>>       Martin
> > >>>
> > >>>
> -------------------------------------------------------------------------
> > >>> This SF.net email is sponsored by: Splunk Inc.
> > >>> Still grepping through log files to find problems?  Stop.
> > >>> Now Search log events and configuration files using AJAX and a browser.
> > >>> Download your FREE copy of Splunk now >>  http://get.splunk.com/
> > >>> _______________________________________________
> > >>> Geotools-gt2-users mailing list
> > >>> [email protected]
> > >>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
> > >>>
> > >>>
> > >>
> -------------------------------------------------------------------------
> > >> This SF.net email is sponsored by: Splunk Inc.
> > >> Still grepping through log files to find problems?  Stop.
> > >> Now Search log events and configuration files using AJAX and a browser.
> > >> Download your FREE copy of Splunk now >>  http://get.splunk.com/
> > >> _______________________________________________
> > >> Geotools-gt2-users mailing list
> > >> [email protected]
> > >> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
> > >>
> > >>
> > >
> > >
> > >
> >
> >
>
>
> --
> -------------------------------------------------------
> 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

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

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to