Adding transparency to a kml file using new graphics in IDL
This article describes how to add transparency to a kml file using new graphics in IDL.
KML files are formatted as XML files. They are not image files but include the path to the PNG image file that will be displayed in Google Earth when opening the KML file.
IDL does not currently support KML files which include a transparent PNG file. In order to create a KML file with a transparent PNG file the following steps can be completed:
- Create a PNG image with a constant value (30 in the example below) where transparency is required. It can be any byte value (between 0 and 255).
- Save this image as a .kml file: it will generate a _test_image0.PNG in addition to the .kml file. This PNG file does not support transparency because the Save method does not support the TRANSPARENT keyword when working with kml files.
- Rewrite the "_test_image0.PNG" file using the TRANSPARENT keyword. This “_test_image0.png” file should be saved in the same locate as the“_test_image0.png” file generated in the previous step
- Test the KML file in Google Earth
The code example below illustrates these steps.
Code example:
PRO KML_with_transparency
; Reading an image
world = FILEPATH('Day.jpg', SUBDIRECTORY=['examples','data'])
read_jpeg, world,im
; Setting an area of the image to a constant byte value : 30 for example
; This is the area where we would like transparency
im[*,0:425,0:425]= 30
; Displaying the image
arctic =
IMAGE(im, LIMIT=[51, -161, 78, -52], $
GRID_UNITS=2, IMAGE_LOCATION=[-180,-90], $
IMAGE_DIMENSIONS=[360,180], MAP_PROJECTION='Stereographic', $
/CURRENT, NAME='Arctic Research', BACKGROUND_color=[30,30,30])
; Generating the kml file
arctic.save,'c:\_user\_temp\test.kml'
; Replacing the png file automatically creating at the step before by a new one supporting transparency.
arctic.
save,'c:\_user\_temp\_test_image0.PNG', TRANSPARENT=[30,30,30],BORDER=0
END