Hi All,
Use the code below to render some features from WFS service and then
export it as a PNG file using JAI. There seems to be an asynchronous
problem here. I suspect it happened during streamRenderer.paint()
because if I debug step by step the image will be generated fine, but
if I just run though it the features won't be rendered (when it passed
to JAI, it's not ready yet I guess). Does anyone encounter the same
problem?
FeatureSource featureSource =
dataStore.getFeatureSource(dataStore.getTypeNames()[typeId]);
//create map context
CoordinateReferenceSystem crs =
DefaultGeographicCRS.WGS84;
MapContext mapContext = new DefaultMapContext(crs);
mapContext.addLayer(featureSource,
GTWFSMapUtil.createPointFeatureStyle());
BufferedImage bufferedImage = new
BufferedImage(webMap.getWidth(),
webMap.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics graphics = bufferedImage.getGraphics();
//graphics.setColor(Color.BLACK);
//graphics.fillRect(0, 0, webMap.getWidth(),
webMap.getHeight());
StreamingRenderer streamRenderer = new StreamingRenderer();
streamRenderer.setContext(mapContext);
streamRenderer.paint((Graphics2D)graphics, new
Rectangle(webMap.getWidth(), webMap.getHeight()), new
ReferencedEnvelope(featureSource.getBounds(), crs));
/*ParameterBlock parameterBlock = new ParameterBlock();
parameterBlock.add(bufferedImage);
PlanarImage planarImage =
(PlanarImage)JAI.create("AWTImage",
parameterBlock);*/
PlanarImage planarImage = (PlanarImage)(new
RenderedImageAdapter(bufferedImage));
ByteArrayOutputStream byteArrayOutputStream = new
ByteArrayOutputStream();
JAI.create("encode", planarImage,
byteArrayOutputStream, "PNG");
-------------------------------------------------------------------------
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