[geotk] Re: applet to display raster
Ramzi Oueslati
ramzi at oueslati.org
Tue Jan 11 10:43:59 EST 2011
Here is the code:
public class RasterApplet extends JApplet {
private static final MutableStyleFactory SF =
(MutableStyleFactory) FactoryFinder
.getStyleFactory(new Hints(Hints.STYLE_FACTORY,
MutableStyleFactory.class));
public void init() {
GeoTiffImageReader.Spi.registerDefaults(null);
WorldFileImageReader.Spi.registerDefaults(null);
Registry.setDefaultCodecPreferences();
final MapContext context = MapBuilder.createContext();
final JMap2D j2dmap = new JMap2D();
j2dmap.getContainer().setContext(context);
final JNavigationBar nav = new JNavigationBar(j2dmap);
final JTextField textField = new JTextField();
textField.setEnabled(false);
JButton b = new JButton("Browse");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(RasterApplet.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
textField.setText(file.getAbsolutePath());
try {
GridCoverageReader reader = GridCoverageReaders
.createSimpleReader(file);
MutableStyle coverageStyle = SF
.style(StyleConstants.DEFAULT_RASTER_SYMBOLIZER);
CoverageMapLayer coverageLayer = MapBuilder
.createCoverageLayer(reader, coverageStyle,
"background");
context.layers().add(coverageLayer);
j2dmap.getCanvas().getController().setVisibleArea(
context.getBounds());
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
}
});
JPanel filePanel = new JPanel(new BorderLayout());
filePanel.add(BorderLayout.WEST, new JLabel("Coverage File"));
filePanel.add(BorderLayout.CENTER, textField);
filePanel.add(BorderLayout.EAST, b);
JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.add(BorderLayout.NORTH, nav);
mainPanel.add(BorderLayout.CENTER, j2dmap);
mainPanel.add(BorderLayout.SOUTH, filePanel);
getContentPane().add(mainPanel);
setSize(new Dimension(750, 400));
}
}
2011/1/11 Ramzi Oueslati <geotoolkit.org at oueslati.org>:
> Hello list,
>
> I'm trying to make an applet display a geotiff coverage. I first tried
> to make the code run as a java application. So far so good. Then I
> changed the code to make it an applet.
> The applet runs fine through appletviewer but fails through the web
> browser. There are 2 errors: one is related to jpeg and the other is
> related to tiff. Here they are:
>
> # display tiff coverage #
>
> org.geotoolkit.coverage.io.CoverageStoreException: Can't read file "world.tiff".
> No suitable image reader for this input.
> at org.geotoolkit.coverage.io.ImageCoverageReader.setInput(ImageCoverageReader.java:398)
> at org.geotoolkit.coverage.io.GridCoverageReaders.createSimpleReader(GridCoverageReaders.java:136)
> at com.spotimage.sdi.applet.OOApplet$1.actionPerformed(OOApplet.java:69)
> at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
> at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
> at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
> at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
> at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
> at java.awt.Component.processMouseEvent(Unknown Source)
> at javax.swing.JComponent.processMouseEvent(Unknown Source)
> at java.awt.Component.processEvent(Unknown Source)
> at java.awt.Container.processEvent(Unknown Source)
> at java.awt.Component.dispatchEventImpl(Unknown Source)
> at java.awt.Container.dispatchEventImpl(Unknown Source)
> at java.awt.Component.dispatchEvent(Unknown Source)
> at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
> at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
> at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
> at java.awt.Container.dispatchEventImpl(Unknown Source)
> at java.awt.Component.dispatchEvent(Unknown Source)
> at java.awt.EventQueue.dispatchEvent(Unknown Source)
> at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
> at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
> at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> at java.awt.EventDispatchThread.run(Unknown Source)
> Caused by: org.geotoolkit.image.io.UnsupportedImageFormatException: No
> suitable image reader for this input.
> at org.geotoolkit.image.io.XImageIO.getReader(XImageIO.java:355)
> at org.geotoolkit.image.io.XImageIO.getReaderBySuffix(XImageIO.java:493)
> at org.geotoolkit.image.io.XImageIO.getReaderBySuffix(XImageIO.java:468)
> at org.geotoolkit.coverage.io.ImageCoverageReader.createImageReader(ImageCoverageReader.java:455)
> at org.geotoolkit.coverage.io.ImageCoverageReader.setInput(ImageCoverageReader.java:332)
> ... 26 more
>
> # display jpeg coverage #
>
> org.opengis.referencing.operation.TransformException: Can't transform envelope.
> at org.geotoolkit.referencing.CRS.transform(CRS.java:1456)
> at org.geotoolkit.display.primitive.AbstractReferencedGraphic2D.setEnvelope(AbstractReferencedGraphic2D.java:174)
> at org.geotoolkit.display2d.container.stateless.AbstractLayerJ2D.<init>(AbstractLayerJ2D.java:70)
> at org.geotoolkit.display2d.container.statefull.StatefullCoverageLayerJ2D.<init>(StatefullCoverageLayerJ2D.java:65)
> at org.geotoolkit.display2d.container.stateless.StatelessContextJ2D.parseLayer(StatelessContextJ2D.java:127)
> at org.geotoolkit.display2d.container.stateless.StatelessContextJ2D.layerChange(StatelessContextJ2D.java:200)
> at org.geotoolkit.map.ContextListener$Weak.layerChange(ContextListener.java:100)
> at org.geotoolkit.map.DefaultMapContext.fireLayerChange(DefaultMapContext.java:231)
> at org.geotoolkit.map.DefaultMapContext$AdapterList.add(DefaultMapContext.java:390)
> at org.geotoolkit.map.DefaultMapContext$AdapterList.add(DefaultMapContext.java:360)
> at java.util.AbstractList.add(Unknown Source)
> at com.spotimage.sdi.applet.OOApplet$1.actionPerformed(OOApplet.java:73)
> at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
> at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
> at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
> at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
> at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
> at java.awt.Component.processMouseEvent(Unknown Source)
> at javax.swing.JComponent.processMouseEvent(Unknown Source)
> at java.awt.Component.processEvent(Unknown Source)
> at java.awt.Container.processEvent(Unknown Source)
> at java.awt.Component.dispatchEventImpl(Unknown Source)
> at java.awt.Container.dispatchEventImpl(Unknown Source)
> at java.awt.Component.dispatchEvent(Unknown Source)
> at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
> at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
> at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
> at java.awt.Container.dispatchEventImpl(Unknown Source)
> at java.awt.Component.dispatchEvent(Unknown Source)
> at java.awt.EventQueue.dispatchEvent(Unknown Source)
> at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
> at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
> at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> at java.awt.EventDispatchThread.run(Unknown Source)
> Caused by: org.opengis.referencing.operation.OperationNotFoundException:
> No transformation available from system "ImageCRS[Grid]" to
> "GeographicCRS[WGS84(DD)]".
> at org.geotoolkit.referencing.operation.DefaultCoordinateOperationFactory.createOperation(DefaultCoordinateOperationFactory.java:339)
> at org.geotoolkit.referencing.CRS.transform(CRS.java:1454)
> ... 35 more
> Jan 11, 2011 4:26:47 PM org.geotoolkit.map.DefaultMapContext getBounds
> WARNING: Data source and map context coordinate system differ, yet it
> was not possible to get a projected bounds estimate...
> org.opengis.referencing.operation.TransformException: Can't transform envelope.
> at org.geotoolkit.referencing.CRS.transform(CRS.java:1456)
> at org.geotoolkit.map.DefaultMapContext.getBounds(DefaultMapContext.java:136)
> at com.spotimage.sdi.applet.OOApplet$1.actionPerformed(OOApplet.java:74)
> at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
> at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
> at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
> at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
> at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
> at java.awt.Component.processMouseEvent(Unknown Source)
> at javax.swing.JComponent.processMouseEvent(Unknown Source)
> at java.awt.Component.processEvent(Unknown Source)
> at java.awt.Container.processEvent(Unknown Source)
> at java.awt.Component.dispatchEventImpl(Unknown Source)
> at java.awt.Container.dispatchEventImpl(Unknown Source)
> at java.awt.Component.dispatchEvent(Unknown Source)
> at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
> at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
> at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
> at java.awt.Container.dispatchEventImpl(Unknown Source)
> at java.awt.Component.dispatchEvent(Unknown Source)
> at java.awt.EventQueue.dispatchEvent(Unknown Source)
> at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
> at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
> at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> at java.awt.EventDispatchThread.run(Unknown Source)
> Caused by: org.opengis.referencing.operation.OperationNotFoundException:
> No transformation available from system "ImageCRS[Grid]" to
> "GeographicCRS[WGS84(DD)]".
> at org.geotoolkit.referencing.operation.DefaultCoordinateOperationFactory.createOperation(DefaultCoordinateOperationFactory.java:339)
> at org.geotoolkit.referencing.CRS.transform(CRS.java:1454)
> ... 26 more
> Jan 11, 2011 4:26:47 PM org.geotoolkit.map.DefaultMapContext getBounds
> WARNING: Data source and map context coordinate system differ, yet it
> was not possible to get a projected bounds estimate...
> org.opengis.referencing.operation.TransformException: Can't transform envelope.
> at org.geotoolkit.referencing.CRS.transform(CRS.java:1456)
> at org.geotoolkit.map.DefaultMapContext.getBounds(DefaultMapContext.java:136)
> at com.spotimage.sdi.applet.OOApplet$1.actionPerformed(OOApplet.java:74)
> at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
> at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
> at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
> at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
> at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
> at java.awt.Component.processMouseEvent(Unknown Source)
> at javax.swing.JComponent.processMouseEvent(Unknown Source)
> at java.awt.Component.processEvent(Unknown Source)
> at java.awt.Container.processEvent(Unknown Source)
> at java.awt.Component.dispatchEventImpl(Unknown Source)
> at java.awt.Container.dispatchEventImpl(Unknown Source)
> at java.awt.Component.dispatchEvent(Unknown Source)
> at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
> at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
> at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
> at java.awt.Container.dispatchEventImpl(Unknown Source)
> at java.awt.Component.dispatchEvent(Unknown Source)
> at java.awt.EventQueue.dispatchEvent(Unknown Source)
> at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
> at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
> at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> at java.awt.EventDispatchThread.run(Unknown Source)
> Caused by: org.opengis.referencing.operation.OperationNotFoundException:
> No transformation available from system "ImageCRS[Grid]" to
> "GeographicCRS[WGS84(DD)]".
> at org.geotoolkit.referencing.operation.DefaultCoordinateOperationFactory.createOperation(DefaultCoordinateOperationFactory.java:339)
> at org.geotoolkit.referencing.CRS.transform(CRS.java:1454)
> ... 26 more
> org.opengis.referencing.operation.TransformException: Can't transform envelope.
> at org.geotoolkit.referencing.CRS.transform(CRS.java:1456)
> at org.geotoolkit.display.canvas.DefaultCanvasController2D.setVisibleArea(DefaultCanvasController2D.java:272)
> at org.geotoolkit.display2d.canvas.J2DCanvasVolatile$DelayedController.setVisibleArea(J2DCanvasVolatile.java:299)
> at com.spotimage.sdi.applet.OOApplet$1.actionPerformed(OOApplet.java:74)
> at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
> at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
> at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
> at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
> at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
> at java.awt.Component.processMouseEvent(Unknown Source)
> at javax.swing.JComponent.processMouseEvent(Unknown Source)
> at java.awt.Component.processEvent(Unknown Source)
> at java.awt.Container.processEvent(Unknown Source)
> at java.awt.Component.dispatchEventImpl(Unknown Source)
> at java.awt.Container.dispatchEventImpl(Unknown Source)
> at java.awt.Component.dispatchEvent(Unknown Source)
> at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
> at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
> at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
> at java.awt.Container.dispatchEventImpl(Unknown Source)
> at java.awt.Component.dispatchEvent(Unknown Source)
> at java.awt.EventQueue.dispatchEvent(Unknown Source)
> at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
> at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
> at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> at java.awt.EventDispatchThread.run(Unknown Source)
> Caused by: org.opengis.referencing.operation.OperationNotFoundException:
> No transformation available from system "ImageCRS[Grid]" to
> "GeographicCRS[WGS84(DD)]".
> at org.geotoolkit.referencing.operation.DefaultCoordinateOperationFactory.createOperation(DefaultCoordinateOperationFactory.java:339)
> at org.geotoolkit.referencing.CRS.transform(CRS.java:1454)
> ... 27 more
>
>
> I understand that the first issue seems to be related to the
> imagereader and the second seems to be a transformation issue. But it
> works fine through the appletviewer which makes me think that it is
> probably a missing library issue. Could you please help me ?
>
> Basically the applet allows the user to select a file in the local
> file system (jpeg or tiff). Then it shows the coverage image.
> The applet's jar is signed in order to run outside the security
> sandbox to allow local file system access. I checked that every
> required jar (geotk + extra) is provided with the applet. Every
> dependent jar had to be signed as well. Please let me know if you want
> me to provide the code.
>
> Kind regards,
> Ramzi
>
More information about the Geotoolkit
mailing list