Re: [Geotools-gt2-users] Slow rendering of GridCoverage objects

2007-02-08 Thread Simone Giannecchini
Ciao Steve,
I need a couple more info about your platform:

java version
os
JAI and ImageIO version


I ran your example as it was (well, to be honest I removed the line where 
you were showing the created coverage) and I got the following execution 
time:

PROCESSING TIME: 7.86 SECONDS

I am using geotools 2.3.x compiled from SVN.

If you provide me with more info, I can try to spot the cause of your 
problems.

Thx,
Simone.
- Original Message - 
From: Steve.Ansari
To: Andrea Aime
Cc: geotools-gt2-users@lists.sourceforge.net
Sent: Sunday, February 04, 2007 6:04 PM
Subject: Re: [Geotools-gt2-users] Slow rendering of GridCoverage objects


Hi Andrea/Simone/Martin,

I threw together a quick example that reproduces the problem.  It took 159 
seconds to produce the image.

Thanks again for the help.
Steve




import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.WritableRaster;
import java.io.File;

import javax.imageio.ImageIO;
import javax.media.jai.RasterFactory;

import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.coverage.grid.GridCoverageFactory;
import org.geotools.geometry.GeneralEnvelope;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.map.DefaultMapContext;
import org.geotools.map.MapContext;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.geotools.renderer.lite.StreamingRenderer;
import org.geotools.styling.RasterSymbolizer;
import org.geotools.styling.Style;
import org.geotools.styling.StyleBuilder;

public class RenderGridCoverageExample {




public static void main(String[] args) {


try {
// 1) Create dummy GridCoverage

int width = 800; // set to 400 to create another exception when 
scaleX*scaleY  1.0
int height = 800;


long startTime = System.currentTimeMillis();


GridCoverageFactory gcFactory = new GridCoverageFactory();

java.awt.geom.Rectangle2D.Double rect =
new java.awt.geom.Rectangle2D.Double(-80.0, 30.0, 5.0, 5.0);
GeneralEnvelope envelope = new GeneralEnvelope(rect);
envelope.setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84);

WritableRaster raster = 
RasterFactory.createBandedRaster(DataBuffer.TYPE_FLOAT, width, height, 1, 
null);
for (int i = 0; i  width; i++) {
for (int j = 0; j  height; j++) {
raster.setSample(i, j, 0, i*j);
}
 }


double[] minValues = new double[] { 0.0 };
double[] maxValues = new double[] { width*height };
Color[] colors = new Color[] { Color.BLUE, Color.GREEN };
GridCoverage2D gc = gcFactory.create(My colored coverage, 
raster,
envelope, minValues, maxValues, null, new 
Color[][]{colors}, null);

gc.show();



// 2) Create MapContext
MapContext context = new 
DefaultMapContext(DefaultGeographicCRS.WGS84);

// 3 Add GridCoverage
final StyleBuilder sb = new StyleBuilder();
final RasterSymbolizer rs = sb.createRasterSymbolizer();
Style style = sb.createStyle(rs);
context.addLayer(gc, style);


// 4) init renderer
StreamingRenderer renderer = new StreamingRenderer();

// 5) set context in renderer
renderer.setContext(context);

// 6) init image (large black rectangle)
BufferedImage bufImage = new BufferedImage(800, 600, 
BufferedImage.TYPE_INT_ARGB);

// 7) create ReferencedEnvelope
ReferencedEnvelope refEnv = new ReferencedEnvelope(envelope, 
context.getCoordinateReferenceSystem());

// 8) paint the context onto the blank image
renderer.paint(
(Graphics2D)bufImage.getGraphics(),
new Rectangle(bufImage.getWidth(), 
bufImage.getHeight()),
adjustGeographicBounds(bufImage, refEnv));


// 9) write image
ImageIO.write(bufImage, png, new 
File(RenderGridCoverageExample.png));


System.out.println(PROCESSING TIME: 
+(System.currentTimeMillis()-startTime)/1000.0+ SECONDS);



} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}


public static ReferencedEnvelope adjustGeographicBounds(BufferedImage 
image, ReferencedEnvelope bounds) {

double imgRatio = (double)image.getWidth() / 
(double)image.getHeight();
double geoRatio = bounds.getWidth() / bounds.getHeight();

double dlon = bounds.getWidth();
double dlat = bounds.getHeight();
double geoCenterX = bounds.getMinX() + (dlon / 2.0);
double geoCenterY = bounds.getMinY() + (dlat / 2.0);

double x = imgRatio

Re: [Geotools-gt2-users] Slow rendering of GridCoverage objects

2007-02-05 Thread Andrea Aime
Simone Giannecchini ha scritto:
 Ciao Steve,
 I need a couple more info about your platform:
 
 java version
 os
 JAI and ImageIO version
 
 
 I ran your example as it was (well, to be honest I removed the line 
 where you were showing the created coverage) and I got the following 
 execution time:
 
 PROCESSING TIME: 7.86 SECONDS
 
 I am using geotools 2.3.x compiled from SVN.
 
 If you provide me with more info, I can try to spot the cause of your 
 problems.

Simone, may it be that the changes performed after the 2.3.0 release
account for this speed difference?
Cheers
Andrea

-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
___
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users


Re: [Geotools-gt2-users] Slow rendering of GridCoverage objects

2007-02-05 Thread Andrea Aime
Steve.Ansari ha scritto:
 Hi Andrea/Simone/Martin,
 
 I threw together a quick example that reproduces the problem.  It took 
 159 seconds to produce the image.

Steve, can you try again using the 2.3.x nightly builds at:
http://www.geo-solutions.it/gt2_nightly/

Cheers
Andrea

-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
___
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users


Re: [Geotools-gt2-users] Slow rendering of GridCoverage objects

2007-02-05 Thread Simone
Ciao steve,
that might explain this sloweness.

I have tried on fedora 5 and it is even faster than on windows xp.

One advice. please install the JAI ImageIO tools package since it ships with 
a nice
native encoder for png which should make things a bit faster anyway.


Let us know if you have more problems.

Regards,
Simone.


- Original Message - 
From: Steve.Ansari [EMAIL PROTECTED]
To: Simone Giannecchini [EMAIL PROTECTED]
Cc: geotools-gt2-users@lists.sourceforge.net
Sent: Monday, February 05, 2007 2:59 PM
Subject: Re: [Geotools-gt2-users] Slow rendering of GridCoverage objects


 Hi Simone/Andrea,

 I'm using:
 Java jre1.5.0_04
 JAI installed from: jai-1_1_3-lib-windows-i586-jre.exe
 ImageIO from standard Java API - no native installs

 I isolated the slowness to this line in GridCoverageRenderer:
graphics.drawRenderedImage(finalImage, cloneFinalWorldToGrid);


 After some googling, I found this resolved Sun bug report:
 http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=8d01140ef3bea515d4807d013cfa:YfiG?bug_id=5073407

 However, this should be fixed in my JRE version and the example code
 with the bug report runs fine for me.

 I'm now going to try with the nightly snapshot.

 Thanks for looking into this,
 Steve






 Simone Giannecchini wrote:
 Ciao Andrea,
 I doubt it depends on differences between 2.3.0 and the actual code,
 but I want to check.

 Since the timed code contains a write operation performed using
 ImageIO directly it might be and old version of ImageIO giving
 problems, or the absence of the native codec for PNGs, or difference
 of performance on a different platform (I only tested on windows for
 the moment).

 With a bit more info, I will try to spot the source of these problems.
 Simone.


 On 2/5/07, Andrea Aime [EMAIL PROTECTED] wrote:
 Simone Giannecchini ha scritto:
  Ciao Steve,
  I need a couple more info about your platform:
 
  java version
  os
  JAI and ImageIO version
 
 
  I ran your example as it was (well, to be honest I removed the line
  where you were showing the created coverage) and I got the following
  execution time:
 
  PROCESSING TIME: 7.86 SECONDS
 
  I am using geotools 2.3.x compiled from SVN.
 
  If you provide me with more info, I can try to spot the cause of your
  problems.

 Simone, may it be that the changes performed after the 2.3.0 release
 account for this speed difference?
 Cheers
 Andrea

 -

 Using Tomcat but need to do more? Need to support web services,
 security?
 Get stuff done quickly with pre-integrated technology to make your
 job easier.
 Download IBM WebSphere Application Server v.1.0.1 based on Apache
 Geronimo
 http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
 ___
 Geotools-gt2-users mailing list
 Geotools-gt2-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users




 -- 
 Steve Ansari
 Physical Scientist
 NOAA's National Climatic Data Center
 Veach-Baley Federal Building
 151 Patton Avenue
 Asheville, NC 28801
 Ph: 828-271-4611
 Fax: 828-271-4022


 -
 Using Tomcat but need to do more? Need to support web services, security?
 Get stuff done quickly with pre-integrated technology to make your job 
 easier.
 Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
 http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
 ___
 Geotools-gt2-users mailing list
 Geotools-gt2-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users 


-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
___
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users


Re: [Geotools-gt2-users] Slow rendering of GridCoverage objects

2007-02-05 Thread Andrea Antonello
I tried the code as well on a Kubuntu distro.

It shows up very quickly both with a jdk1.5 without native jai libs
installed as well as with a 1.6 with jai native install.

Cheers
Andrea



Simone wrote:
 Ciao steve,
 that might explain this sloweness.
 
 I have tried on fedora 5 and it is even faster than on windows xp.
 
 One advice. please install the JAI ImageIO tools package since it ships with 
 a nice
 native encoder for png which should make things a bit faster anyway.
 
 
 Let us know if you have more problems.
 
 Regards,
 Simone.
 
 
 - Original Message - 
 From: Steve.Ansari [EMAIL PROTECTED]
 To: Simone Giannecchini [EMAIL PROTECTED]
 Cc: geotools-gt2-users@lists.sourceforge.net
 Sent: Monday, February 05, 2007 2:59 PM
 Subject: Re: [Geotools-gt2-users] Slow rendering of GridCoverage objects
 
 
 Hi Simone/Andrea,

 I'm using:
 Java jre1.5.0_04
 JAI installed from: jai-1_1_3-lib-windows-i586-jre.exe
 ImageIO from standard Java API - no native installs

 I isolated the slowness to this line in GridCoverageRenderer:
graphics.drawRenderedImage(finalImage, cloneFinalWorldToGrid);


 After some googling, I found this resolved Sun bug report:
 http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=8d01140ef3bea515d4807d013cfa:YfiG?bug_id=5073407

 However, this should be fixed in my JRE version and the example code
 with the bug report runs fine for me.

 I'm now going to try with the nightly snapshot.

 Thanks for looking into this,
 Steve






 Simone Giannecchini wrote:
 Ciao Andrea,
 I doubt it depends on differences between 2.3.0 and the actual code,
 but I want to check.

 Since the timed code contains a write operation performed using
 ImageIO directly it might be and old version of ImageIO giving
 problems, or the absence of the native codec for PNGs, or difference
 of performance on a different platform (I only tested on windows for
 the moment).

 With a bit more info, I will try to spot the source of these problems.
 Simone.


 On 2/5/07, Andrea Aime [EMAIL PROTECTED] wrote:
 Simone Giannecchini ha scritto:
 Ciao Steve,
 I need a couple more info about your platform:

 java version
 os
 JAI and ImageIO version

 I ran your example as it was (well, to be honest I removed the line
 where you were showing the created coverage) and I got the following
 execution time:

 PROCESSING TIME: 7.86 SECONDS

 I am using geotools 2.3.x compiled from SVN.

 If you provide me with more info, I can try to spot the cause of your
 problems.
 Simone, may it be that the changes performed after the 2.3.0 release
 account for this speed difference?
 Cheers
 Andrea

 -

 Using Tomcat but need to do more? Need to support web services,
 security?
 Get stuff done quickly with pre-integrated technology to make your
 job easier.
 Download IBM WebSphere Application Server v.1.0.1 based on Apache
 Geronimo
 http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
 ___
 Geotools-gt2-users mailing list
 Geotools-gt2-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users


 -- 
 Steve Ansari
 Physical Scientist
 NOAA's National Climatic Data Center
 Veach-Baley Federal Building
 151 Patton Avenue
 Asheville, NC 28801
 Ph: 828-271-4611
 Fax: 828-271-4022


 -
 Using Tomcat but need to do more? Need to support web services, security?
 Get stuff done quickly with pre-integrated technology to make your job 
 easier.
 Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
 http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
 ___
 Geotools-gt2-users mailing list
 Geotools-gt2-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users 
 
 
 -
 Using Tomcat but need to do more? Need to support web services, security?
 Get stuff done quickly with pre-integrated technology to make your job easier.
 Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
 http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
 ___
 Geotools-gt2-users mailing list
 Geotools-gt2-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
 

-- 

HydroloGIS - Environmental Safety Modelling
www.hydrologis.com

Andrea Antonello
Environmental Engineer
mobile:  +393288497722

Let it be as much a great honour to take as to give learning,
if you want to be called wise.
Skuggsja' - The King's mirror - 1240 Reykjavik

Re: [Geotools-gt2-users] Slow rendering of GridCoverage objects

2007-02-05 Thread Steve.Ansari
 = (double)image.getWidth() / 
(double)image.getHeight();

   double geoRatio = bounds.getWidth() / bounds.getHeight();

   double dlon = bounds.getWidth();
   double dlat = bounds.getHeight();
   double geoCenterX = bounds.getMinX() + (dlon / 2.0);
   double geoCenterY = bounds.getMinY() + (dlat / 2.0);
  
   double x = imgRatio / geoRatio;
  
   if (x  1.0) {

   dlon = dlon * x;
   }
   else {
   dlat = dlat / x;
   }
  
   return new ReferencedEnvelope(

   geoCenterX + dlon / 2.0,
   geoCenterX - dlon / 2.0,
   geoCenterY + dlat / 2.0,
   geoCenterY - dlat / 2.0,
   bounds.getCoordinateReferenceSystem()
   );
   }  //  end adjustGeographicBounds()
}





Andrea Antonello wrote:

I tried the code as well on a Kubuntu distro.

It shows up very quickly both with a jdk1.5 without native jai libs
installed as well as with a 1.6 with jai native install.

Cheers
Andrea



Simone wrote:
  

Ciao steve,
that might explain this sloweness.

I have tried on fedora 5 and it is even faster than on windows xp.

One advice. please install the JAI ImageIO tools package since it ships with 
a nice

native encoder for png which should make things a bit faster anyway.


Let us know if you have more problems.

Regards,
Simone.


- Original Message - 
From: Steve.Ansari [EMAIL PROTECTED]

To: Simone Giannecchini [EMAIL PROTECTED]
Cc: geotools-gt2-users@lists.sourceforge.net
Sent: Monday, February 05, 2007 2:59 PM
Subject: Re: [Geotools-gt2-users] Slow rendering of GridCoverage objects




Hi Simone/Andrea,

I'm using:
Java jre1.5.0_04
JAI installed from: jai-1_1_3-lib-windows-i586-jre.exe
ImageIO from standard Java API - no native installs

I isolated the slowness to this line in GridCoverageRenderer:
   graphics.drawRenderedImage(finalImage, cloneFinalWorldToGrid);


After some googling, I found this resolved Sun bug report:
http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=8d01140ef3bea515d4807d013cfa:YfiG?bug_id=5073407

However, this should be fixed in my JRE version and the example code
with the bug report runs fine for me.

I'm now going to try with the nightly snapshot.

Thanks for looking into this,
Steve






Simone Giannecchini wrote:
  

Ciao Andrea,
I doubt it depends on differences between 2.3.0 and the actual code,
but I want to check.

Since the timed code contains a write operation performed using
ImageIO directly it might be and old version of ImageIO giving
problems, or the absence of the native codec for PNGs, or difference
of performance on a different platform (I only tested on windows for
the moment).

With a bit more info, I will try to spot the source of these problems.
Simone.


On 2/5/07, Andrea Aime [EMAIL PROTECTED] wrote:


Simone Giannecchini ha scritto:
  

Ciao Steve,
I need a couple more info about your platform:



java version
os
JAI and ImageIO version
  

I ran your example as it was (well, to be honest I removed the line
where you were showing the created coverage) and I got the following
execution time:

PROCESSING TIME: 7.86 SECONDS

I am using geotools 2.3.x compiled from SVN.

If you provide me with more info, I can try to spot the cause of your
problems.


Simone, may it be that the changes performed after the 2.3.0 release
account for this speed difference?
Cheers
Andrea

-

Using Tomcat but need to do more? Need to support web services,
security?
Get stuff done quickly with pre-integrated technology to make your
job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache
Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
___
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

  

--
Steve Ansari
Physical Scientist
NOAA's National Climatic Data Center
Veach-Baley Federal Building
151 Patton Avenue
Asheville, NC 28801
Ph: 828-271-4611
Fax: 828-271-4022


-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job 
easier.

Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
___
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users 
  

-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make

Re: [Geotools-gt2-users] Slow rendering of GridCoverage objects

2007-02-04 Thread Andrea Aime
Steve.Ansari ha scritto:
 Hello all,
 
 I'm using StreamingRenderer to draw a MapContext with the 2.3.0 release, 
 however it is VERY slow when drawing a GridCoverage layer.  I've 
 isolated the problem to:
 
 graphics.drawRenderedImage(finalImage, cloneFinalWorldToGrid);
 
 in GridCoverageRenderer ( 
 http://svn.geotools.org/geotools/trunk/gt/modules/library/render/src/main/java/org/geotools/renderer/lite/gridcoverage2d/GridCoverageRenderer.java
  
 )
 
 My GridCoverage is 800x800 and the drawing time is around 1 minute.

Are you creating the map layer with Reader or a Coverage? If you're 
reading from disk, always add a reader.
Let me know if this helped
Cheers
Andrea

-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
___
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users


Re: [Geotools-gt2-users] Slow rendering of GridCoverage objects

2007-02-04 Thread Steve.Ansari

Hi Andrea,

I'm manually creating the GridCoverage from a WritableRaster using:

 GridCoverage2D gc = gcFactory.create(My colored coverage, raster,
   envelope, minValues, maxValues, null, new Color[][]{colors}, 
null);


Thanks for the help!
Steve




Andrea Aime wrote:

Steve.Ansari ha scritto:
  

Hello all,

I'm using StreamingRenderer to draw a MapContext with the 2.3.0 release, 
however it is VERY slow when drawing a GridCoverage layer.  I've 
isolated the problem to:


graphics.drawRenderedImage(finalImage, cloneFinalWorldToGrid);

in GridCoverageRenderer ( 
http://svn.geotools.org/geotools/trunk/gt/modules/library/render/src/main/java/org/geotools/renderer/lite/gridcoverage2d/GridCoverageRenderer.java 
)


My GridCoverage is 800x800 and the drawing time is around 1 minute.



Are you creating the map layer with Reader or a Coverage? If you're 
reading from disk, always add a reader.

Let me know if this helped
Cheers
Andrea

-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
___
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
  


--
Steve Ansari
Physical Scientist
NOAA's National Climatic Data Center
Veach-Baley Federal Building
151 Patton Avenue
Asheville, NC 28801
Ph: 828-271-4611
Fax: 828-271-4022

-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642___
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users


Re: [Geotools-gt2-users] Slow rendering of GridCoverage objects

2007-02-04 Thread Steve.Ansari

Hi Andrea/Simone/Martin,

I threw together a quick example that reproduces the problem.  It took 
159 seconds to produce the image.


Thanks again for the help.
Steve




import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.WritableRaster;
import java.io.File;

import javax.imageio.ImageIO;
import javax.media.jai.RasterFactory;

import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.coverage.grid.GridCoverageFactory;
import org.geotools.geometry.GeneralEnvelope;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.map.DefaultMapContext;
import org.geotools.map.MapContext;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.geotools.renderer.lite.StreamingRenderer;
import org.geotools.styling.RasterSymbolizer;
import org.geotools.styling.Style;
import org.geotools.styling.StyleBuilder;

public class RenderGridCoverageExample {

  
  
  
   public static void main(String[] args) {
  
  
   try {

   // 1) Create dummy GridCoverage
  
   int width = 800; // set to 400 to create another exception 
when scaleX*scaleY  1.0

   int height = 800;
  


   long startTime = System.currentTimeMillis();

  
   GridCoverageFactory gcFactory = new GridCoverageFactory();
  
   java.awt.geom.Rectangle2D.Double rect =

   new java.awt.geom.Rectangle2D.Double(-80.0, 30.0, 5.0, 5.0);
   GeneralEnvelope envelope = new GeneralEnvelope(rect);
   
envelope.setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84);
  
   WritableRaster raster = 
RasterFactory.createBandedRaster(DataBuffer.TYPE_FLOAT, width, height, 
1, null);

   for (int i = 0; i  width; i++) {
   for (int j = 0; j  height; j++) {
   raster.setSample(i, j, 0, i*j);
   }
}
  
  
   double[] minValues = new double[] { 0.0 };

   double[] maxValues = new double[] { width*height };
   Color[] colors = new Color[] { Color.BLUE, Color.GREEN };
   GridCoverage2D gc = gcFactory.create(My colored coverage, 
raster,
   envelope, minValues, maxValues, null, new 
Color[][]{colors}, null);
  
   gc.show();
 
  
  
   // 2) Create MapContext
   MapContext context = new 
DefaultMapContext(DefaultGeographicCRS.WGS84);
  
   // 3 Add GridCoverage

   final StyleBuilder sb = new StyleBuilder();
   final RasterSymbolizer rs = sb.createRasterSymbolizer();
   Style style = sb.createStyle(rs);
   context.addLayer(gc, style);

  
   // 4) init renderer

   StreamingRenderer renderer = new StreamingRenderer();
  
   // 5) set context in renderer

   renderer.setContext(context);
  
   // 6) init image (large black rectangle)
   BufferedImage bufImage = new BufferedImage(800, 600, 
BufferedImage.TYPE_INT_ARGB); 


   // 7) create ReferencedEnvelope
   ReferencedEnvelope refEnv = new ReferencedEnvelope(envelope, 
context.getCoordinateReferenceSystem());
  
   // 8) paint the context onto the blank image

   renderer.paint(
   (Graphics2D)bufImage.getGraphics(),
   new Rectangle(bufImage.getWidth(), 
bufImage.getHeight()),

   adjustGeographicBounds(bufImage, refEnv));


   // 9) write image
   ImageIO.write(bufImage, png, new 
File(RenderGridCoverageExample.png));
  
  
   System.out.println(PROCESSING TIME: 
+(System.currentTimeMillis()-startTime)/1000.0+ SECONDS);
  
  
  
   } catch (Exception e) {

   // TODO Auto-generated catch block
   e.printStackTrace();
   }
  
   }
  
 
   public static ReferencedEnvelope 
adjustGeographicBounds(BufferedImage image, ReferencedEnvelope bounds) {
  
   double imgRatio = (double)image.getWidth() / 
(double)image.getHeight();

   double geoRatio = bounds.getWidth() / bounds.getHeight();

   double dlon = bounds.getWidth();
   double dlat = bounds.getHeight();
   double geoCenterX = bounds.getMinX() + (dlon / 2.0);
   double geoCenterY = bounds.getMinY() + (dlat / 2.0);
  
   double x = imgRatio / geoRatio;
  
   if (x  1.0) {

   dlon = dlon * x;
   }
   else {
   dlat = dlat / x;
   }
  
   return new ReferencedEnvelope(

   geoCenterX + dlon / 2.0,
   geoCenterX - dlon / 2.0,
   geoCenterY + dlat / 2.0,
   geoCenterY - dlat / 2.0,
   bounds.getCoordinateReferenceSystem()
   );
   }  //  end adjustGeographicBounds()
}

























Re: [Geotools-gt2-users] Slow rendering of GridCoverage objects

2007-02-04 Thread Dieter Mach
Hello,

I had the same problem some month ago (see my posting from Dec 16, 2006) 
and still didn't find a solution. While rendering, the memory usage 
increases continuously. If it would be helpful, I could send a detailed 
stack trace showing where the renderer spends that much time.

A workaround would be great!

Dieter




-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
___
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users