Exporting RGB image with vector layers


Hello. I am working on python code, which will create RGB image from OLCI products. I am having problems with last step, which is adding a vector layer on top of image before exporting it.

I have managed to add vector data to BEAM-DIMAP, meaning that when I open .dim file, the vector data is placed on top of bands. However, after generating RGB image of selected bands, I cant see any borders on top of my image.

Generated RGB image:


My code for adding vector data:

def vectoradd():
    for file in glob.glob(source_directory):
        HashMap = snappy.jpy.get_type('java.util.HashMap')
        product = ProductIO.readProduct(file)
        shapeFile = '/home/lubomir/Desktop/Sentinel3_OLCI/hranice/CNTR_BN_01M_2016_3035_INLAND.shp'
        params = HashMap()
        params.put('vectorFile', shapeFile)
        params.put('separateShapes', False)  
        target = GPF.createProduct('Import-Vector', params, product)
        ProductIO.writeProduct(target, "/home/lubomir/Desktop/Sentinel3_OLCI/borders/TEST_POLYGON", 'BEAM-DIMAP')

My code for creation of RGB image (simplified):

def write_rgb_image(bands, filename, format):
    image_info = ProductUtils.createImageInfo(bands, True, ProgressMonitor.NULL)
    im = ImageManager.getInstance().createColoredBandImage(bands, image_info, 0)
    JAI.create("filestore", im, filename, format)

def rgb_OLCI():
    for file in glob.glob(source_directory):
        product = ProductIO.readProduct(file)
        starttime = product.getStartTime()
        description = product.getDescription()
        band_names = product.getBandNames()
        starttime_parsed = datetime.strptime(str(starttime),'%d-%b-%Y %H:%M:%S.%f')
        gamma_export = export_directory + '/TrueColor_' + starttime_parsed.strftime("%Y%m%d%H%M")

        ImageIO = jpy.get_type('javax.imageio.ImageIO')

        red = product.getBand('gamma3')
        green = product.getBand('gamma2')
        blue = product.getBand('gamma')
        mask = product.getVectorDataGroup().get('CNTR_BN_01M_2016_3035_INLAND')
        write_rgb_image([red, gree, blue], gamma_export, 'PNG')


Please have a look at this thread

And especially to my second reply in this thread. There I link to this example source code.

The Problem is that this code is Java not Python. Maybe you can translate it or someone can help?