|
From: Steve.Ansari <Ste...@no...> - 2007-02-05 14:26:47
|
Ha!!!
I tried with GT-2.3.1-SNAPSHOT-rev24168 and it works GREAT!
I added some time markers to the example code below and here are the
comparisons. Thanks you all for the help.
Steve
GT-2.3.0:
PROCESSING TIME 1: 1.438 SECONDS
PROCESSING TIME 2: 2.563 SECONDS
PROCESSING TIME 3: 171.203 SECONDS
TOTAL PROCESSING TIME: 171.985 SECONDS
GT-2.3.1-SNAPSHOT-rev24168
PROCESSING TIME 1: 1.484 SECONDS
Feb 5, 2007 9:22:35 AM FactoryRegistry scanForPlugins
WARNING: Can't load a service for category "DataSource". Cause is
"NoClassDefFoundError: org/postgresql/jdbc3/Jdbc3SimpleDataSource".
PROCESSING TIME 2: 3.328 SECONDS
PROCESSING TIME 3: 4.141 SECONDS
TOTAL PROCESSING TIME: 4.75 SECONDS
package steve.test;
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();
System.out.println("PROCESSING TIME 1:
"+(System.currentTimeMillis()-startTime)/1000.0+" SECONDS");
// 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());
System.out.println("PROCESSING TIME 2:
"+(System.currentTimeMillis()-startTime)/1000.0+" SECONDS");
// 8) paint the context onto the blank image
renderer.paint(
(Graphics2D)bufImage.getGraphics(),
new Rectangle(bufImage.getWidth(),
bufImage.getHeight()),
adjustGeographicBounds(bufImage, refEnv));
System.out.println("PROCESSING TIME 3:
"+(System.currentTimeMillis()-startTime)/1000.0+" SECONDS");
// 9) write image
ImageIO.write(bufImage, "png", new
File("RenderGridCoverageExample.png"));
System.out.println("TOTAL 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 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" <Ste...@no...>
>> To: "Simone Giannecchini" <sim...@ge...>
>> Cc: <geo...@li...>
>> 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 <aa...@op...> 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=lnk&kid=120709&bid=263057&dat=121642
>>>>> _______________________________________________
>>>>> Geotools-gt2-users mailing list
>>>>> Geo...@li...
>>>>> 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
>>> Geo...@li...
>>> 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
>> Geo...@li...
>> 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
|