From: Simone G. <sim...@gm...> - 2007-08-24 11:34:02
|
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): =09public void test() throws FactoryException, IOException { =09=09// // =09=09// =09=09// Here below you have how to correctly create an envelope for a =09=09// coverage. =09=09// =09=09// // =09=09// final GeneralEnvelope sourceEnvelope =3D new GeneralEnvelope( =09=09// new double[] { -180, -90 }, new double[] { 180, 90 }); =09=09// sourceEnvelope.setCoordinateReferenceSystem(CRS.decode("EPSG:4326"= , =09=09// true)); =09=09// get a reader for the image =09=09final WorldImageReader wiReader =3D new WorldImageReader(new File( =09=09=09=09"D:\\data\\ikonos_rgb\\ikonos_rgb.tif")); =09=09// get the coverage =09=09GridCoverage2D coverage =3D (GridCoverage2D) wiReader.read(null); =09=09// now that we have the input image let's try to mess it up writing o= nto =09=09// a new bufferedimage with a strange color model =09=09final BufferedImage bi =3D new BufferedImage(coverage.getGridGeometry= () =09=09=09=09.getGridRange().getLength(0), coverage.getGridGeometry() =09=09=09=09.getGridRange().getLength(1), BufferedImage.TYPE_INT_BGR); =09=09((Graphics2D) bi.getGraphics()) =09=09=09=09.drawRenderedImage(coverage.getRenderedImage(), AffineTransform =09=09=09=09=09=09.getTranslateInstance(0, 0)); =09=09coverage =3D FactoryFinder.getGridCoverageFactory(null).create( =09=09=09=09"I_need_a_long_vacation", bi, coverage.getEnvelope()); =09=09// resample the created coverage =09=09coverage =3D (GridCoverage2D) Operations.DEFAULT.resample(coverage, =09=09=09=09CRS.decode("EPSG:32633")); =09=09final RenderedImage resampled =3Dcoverage.getRenderedImage(); =09=09// Painting some other BufferedImages PNG or JPEGS on the Canvas of =09=09// by using =09=09// the bi.getGraphics().drawImage(Image,..) Method =09=09((Graphics2D) bi.getGraphics()).drawRenderedImage(resampled, =09=09=09=09AffineTransform.getTranslateInstance(0, 0)); =09=09// write it down =09=09ImageIO.write(bi, "tiff", new File("d:\\data\\b.tif")); =09} 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 <jga...@re...> wrote: > Thanks Martin/Tim I have updated the wiki with this description of resamp= le: > - 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 =E9crit : > > > >>> 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)-librar= y > >>> which can do that. > >>> > > > > CoordinateReference sourceCRS =3D CRS.decode("EPSG:4326"); > > CoordinateReference targetCRS =3D CRS.decode("EPSG:32632"); > > RenderedImage image =3D ... > > Envelope imageEnvelope =3D ... > > imageEnvelope.setCoordinateReferenceSystem(sourceCRS); > > GridCoverage2D coverage =3D coverageFactory.create("My coverage", image= , envelope); > > coverage =3D 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 > > Geo...@li... > > 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 > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > --=20 ------------------------------------------------------- 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 ------------------------------------------------------- |