Hi all,
I am currently porting an Application from an older Geotools version
(using StyledMapPane) to 2.3.0 (Release from Dec 1.). Everything works
fine except displaying a GridCoverage2D in a JMapPane. I am using JAI
1.1.3 and tried jdk 1.5.0_06 and 1.5.0_08. To isolate the problem, I
modified the MapViewer example to display a GridCoverage2D.
Here is the modified part of the MapViewer code:
...
public void load(URL shape, URL sld)throws Exception{
MapContext context = new
DefaultMapContext(DefaultGeographicCRS.WGS84);
// testing raster symbolizer
StyleBuilder sb = new StyleBuilder();
RasterSymbolizer rs = sb.createRasterSymbolizer();
context.addLayer(getGc(), sb.createStyle(rs));
com.vividsolutions.jts.geom.Envelope env =
context.getLayer(0).getFeatureSource().getBounds();
mp.setMapArea(env);
GTRenderer renderer;
// setting the hints doesn't help
if( false ){
renderer = new StreamingRenderer();
HashMap hints = new HashMap();
hints.put("memoryPreloadingEnabled", Boolean.TRUE);
renderer.setRendererHints( hints );
} else {
renderer = new StreamingRenderer();
}
mp.setRenderer(renderer);
mp.setContext(context);
mp.setReset(true);
mp.repaint();
frame.repaint();
frame.doLayout();
}
/**
* from the current FloatRasterDemo
* @return a GridCoverage2D
*/
public GridCoverage2D getGc() {
final int width = 500;
final int height = 500;
WritableRaster raster =
RasterFactory.createBandedRaster(DataBuffer.TYPE_FLOAT,
width, height, 1, null);
for (int y=0; y<height; y++) {
for (int x=0; x<width; x++) {
raster.setSample(x, y, 0, x+y);
}
}
CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84;
Envelope envelope = new Envelope2D(crs, 0, 0, 30, 30);
GridCoverageFactory factory =
FactoryFinder.getGridCoverageFactory(null);
return factory.create("My grayscale coverage", raster,
envelope);
}
...
When mp.repaint() is called, the CPU usage goes to 100%, without
displaying the raster. A stack trace from a CPU profiler shows
...
org.geotools.renderer.lite.gridcoverage2d.GridCoverageRenderer.paint()
sun.java2d.SunGraphics2D.drawRenderedImage()
...
I looked at old postings from the list, but didn't find a solution. I
think, I am missing something really stupid in my code. Could somebody
help me?
Thanks in advance!
Dieter Mach
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users