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 / 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 Aime wrote:
Steve.Ansari ha scritto:

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);


Ouch... it shouldn't be that slow. Hopefully Simone or Martin will know
more about this.
Can you give us a self-contained program that exhibits this poor behavior?

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=lnk&kid=120709&bid=263057&dat=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=lnk&kid=120709&bid=263057&dat=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=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to