Welcome to the BEAM Forum!

We encourage you to sign in our forum and participate in the BEAM community. The forum is maintained by the BEAM project team who will most likely answer your questions within 24 hours (except during common holidays) - if not done by other community members. Collaborate, share your knowledge and learn from other users!

If you don't find what you are looking for, please also consider the following external forums:

Combination View Flat View Tree View
Threads [ Previous | Next ]
create RGB image with graticule and coastline using BEAM API
toggle
Hello everyone,

I'm trying to programmatically add a graticule overlay and coastline to an RGB image. The Image is generated from a single source band. (All this is implemented inside a GPF operator.)

This is fairly easy with the VISAT GUI, but I haven't been able to figure out how to do this using the BEAM APIs.
Any help is highly appreciated.

thanks,
Kutila
Flag Flag
RE: create RGB image with graticule and coastline using BEAM API
1/20/14 1:35 PM as a reply to Kutila Gunasekera.
Hi Kutila,

you need to use the layer API. It is a bit tricky.

First you create a collection layer to store the layers you want to have in your image:
1        CollectionLayer collectionLayer = new CollectionLayer();
2        List<Layer> layerChildren = collectionLayer.getChildren();

Then create layers:
 1        ImageLayer imageLayer = new ImageLayer(band.getSourceImage()); // or a RenderedImage
 2
 3        LayerType graticuleType = LayerTypeRegistry.getLayerType(GraticuleLayerType.class);
 4        PropertySet template = graticuleType .createLayerConfig(null);
 5        template.setValue(GraticuleLayerType.PROPERTY_NAME_RASTER,band);
 6        GraticuleLayer graticuleLayer = (GraticuleLayer) layerType.createLayer(null, template);
 7
 8        MaskLayerType type = LayerTypeRegistry.getLayerType(MaskLayerType.class);
 9        PropertySet configuration = type.createLayerConfig(null);
10        Mask.BandMathsType.create("coast", "", band.getSceneRasterWidth(), band.getSceneRasterHeight(), "l1_flags.COASTLINE")
11        Mask coastlineMask
12        configuration.setValue(MaskLayerType.PROPERTY_NAME_MASK, coastlineMask);
13        Layer coastlineLayer = type.createLayer(null, configuration);


Then you add one after the other to the children of the collection layer
1        layerChildren.add(0, imageLayer);
2        layerChildren.add(0, graticuleLayer );
3        layerChildren.add(0, coastlineLayer);


I'm not sure if this will work 100%. I haven't tried it. But it should work as a general guideline.
If you have further questions just come back here and ask.

regards
Marco
Flag Flag
RE: create RGB image with graticule and coastline using BEAM API
1/20/14 1:55 PM as a reply to Kutila Gunasekera.
What I forgot to say is that the creation of the coastline is dependent on your source. The example uses the flag of a MERIS L1B product.
It is also possible to use an ESRI shapefile. But this is more complex. Just let me know if you need more help.

regards
Marco
Flag Flag
RE: create RGB image with graticule and coastline using BEAM API
1/21/14 8:42 AM as a reply to Marco Peters.
Another thing I forgot. How to turn the layers into an image.
 1        Rectangle2D modelBounds = collectionLayer.getModelBounds();
 2        Rectangle2D imageBounds = imageLayer.getModelToImageTransform().createTransformedShape(modelBounds).getBounds2D();
 3        BufferedImage bufferedImage = new BufferedImage((int) imageBounds.getWidth(),
 4                                                        (int) imageBounds.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
 5
 6        BufferedImageRendering rendering = new BufferedImageRendering(bufferedImage);
 7        Viewport viewport = rendering.getViewport();
 8        viewport.setModelYAxisDown(imageLayer.getImageToModelTransform().getDeterminant() > 0.0);
 9        viewport.zoom(modelBounds);
10        collectionLayer.render(rendering);
11        RenderedImage outputImage = rendering.getImage();

best wishes
Marco
Flag Flag
RE: create RGB image with graticule and coastline using BEAM API
8/7/15 6:38 PM as a reply to Marco Peters.
Hi Marco,

I'm working with Kutila on this operator. We can add a layer to the raster image, but having problem in exporting the graticule layer labels outside the raster image. Any suggestion?

Thanks!
Flag Flag
RE: create RGB image with graticule and coastline using BEAM API
8/11/15 8:53 AM as a reply to Aynur Abdurazik.
Hi Aynur,

the GraticuleLayer misses an implementation of getLayerModelBounds().
In general the model bounds must be extended to include the labels which are drawn outside of the image bounds.
More precisely this method must be considered what is done renderLayer() and especially in drawTextLabels().

cheers
Marco
Flag Flag
RE: create RGB image with graticule and coastline using BEAM API
9/2/15 3:53 PM as a reply to Marco Peters.
Hi Marco,

Thank you for your reply. I'll try to implement the getLayerModelBounds() method for the GraticuleLayer and will keep you posted on the progress.

Best,
Aynur
Flag Flag