Hello again Mike, It turned out this problem has a very simple fix involving a single line in the StreamingRenderer class. Unfortunately the GeoTools subversion repository is having problems so I can't commit the change at the moment. However, if you have the GeoTools sources you could apply the fix yourself and re-build the gt-render module. A patch file is attached to the Jira issue:
http://jira.codehaus.org/browse/GEOT-3555 When the repository is back on-line the code changes will be committed and, shortly after that, be available via the 2.7-SNAPSHOT and 8-SNAPSHOT builds. Michael On 29 April 2011 22:39, Michael Bedward <[email protected]> wrote: > Hello Mike, > > I just tried your code. I'm afraid it looks like a bug in GeoTools: > either in the render module involving the new content-specific Layer > classes that have replaced the DefaultMapLayer, or in the swing module > which might be mishandling the Layer class used for a GridCoverage2D > object. > > I've created an issue for it > (http://jira.codehaus.org/browse/GEOT-3555) and will do my best to > look into it in the next couple of days. > > Thanks for reporting the problem. > > Michael > > > On 29 April 2011 13:30, Mike O'Toole <[email protected]> wrote: >> Hi All, >> >> Can someone please point me to my error. I've been trying to display a >> GridCoverage2D object in a JMapFrame. I keep getting the following casting >> error. I know I can just use the reader object (and it works) to display the >> image, however, I need to be able to display a passed GridCoverage2D object. >> >> Thanks for your help, >> Mike >> >> Error: >> 2011-04-28 16:09:54 SEVERE: org.geotools.feature.simple.SimpleFeatureImpl >> cannot be cast to org.geotools.coverage.grid.GridCoverage2D >> (StreamingRenderer.fireErrorEvent()) >> java.lang.ClassCastException: org.geotools.feature.simple.SimpleFeatureImpl >> cannot be cast to org.geotools.coverage.grid.GridCoverage2D >> >> org.geotools.renderer.lite.StreamingRenderer.processSymbolizers(StreamingRenderer.java:2219) >> >> org.geotools.renderer.lite.StreamingRenderer.process(StreamingRenderer.java:2158) >> >> org.geotools.renderer.lite.StreamingRenderer.drawPlain(StreamingRenderer.java:2014) >> >> org.geotools.renderer.lite.StreamingRenderer.processStylers(StreamingRenderer.java:1934) >> >> org.geotools.renderer.lite.StreamingRenderer.paint(StreamingRenderer.java:766) >> >> org.geotools.swing.RenderingExecutor$Task.call(RenderingExecutor.java:149) >> >> org.geotools.swing.RenderingExecutor$Task.call(RenderingExecutor.java:105) >> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) >> java.util.concurrent.FutureTask.run(FutureTask.java:166) >> >> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) >> >> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) >> java.lang.Thread.run(Thread.java:636) >> >> >> Code: >> >> AbstractGridFormat format = GridFormatFinder.findFormat( rasterFile ); >> AbstractGridCoverage2DReader reader = format.getReader(rasterFile); >> GridCoverage2D grid = reader.read(null); >> >> CoordinateReferenceSystem crs = CRS.decode("EPSG:26911"); >> >> MapContext mapcontext = new MapContext(crs); >> mapcontext.addLayer( grid, createGreyscaleStyle(1)); >> >> JMapFrame frame = new JMapFrame(mapcontext); >> frame.setSize(965, 600); >> frame.enableStatusBar(true); >> frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE); >> frame.setVisible(true); >> >> private static Style createGreyscaleStyle(int band) { >> ContrastEnhancement ce = sf.contrastEnhancement(ff.literal(1.0), >> ContrastMethod.NORMALIZE); >> SelectedChannelType sct = >> sf.createSelectedChannelType(String.valueOf(band), ce); >> >> RasterSymbolizer sym = sf.getDefaultRasterSymbolizer(); >> ChannelSelection sel = sf.channelSelection(sct); >> sym.setChannelSelection(sel); >> >> return SLD.wrapSymbolizers(sym); >> } >> ------------------------------------------------------------------------------ >> WhatsUp Gold - Download Free Network Management Software >> The most intuitive, comprehensive, and cost-effective network >> management toolset available today. Delivers lowest initial >> acquisition cost and overall TCO of any competing solution. >> http://p.sf.net/sfu/whatsupgold-sd >> _______________________________________________ >> Geotools-gt2-users mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >> > ------------------------------------------------------------------------------ WhatsUp Gold - Download Free Network Management Software The most intuitive, comprehensive, and cost-effective network management toolset available today. Delivers lowest initial acquisition cost and overall TCO of any competing solution. http://p.sf.net/sfu/whatsupgold-sd _______________________________________________ Geotools-gt2-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
