Adding Color Bars to KML Files [message #81975] |
Sun, 04 November 2012 15:27 |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Folks,
Over the weekend I have added and upgraded a number of programs
in the Coyote Library to add functionality to my IDL to KML
programs. In particular, I have added a cgCBar2KML program
that allows you to create a color bar in a KML file.
A color bar or legend is a <ScreenOverlay> element in a KML
file, so I have also introduced a cgKML_ScreenOverlay object.
Screen overlays stay in one place on the display as the
3D Earth zooms and rotates under it.
The new cgCBar2KML implements a horizontal color bar
and pretty much accepts the same arguments as cgColorbar.
You can see an example of how it is used at the end
of this article:
http://www.idlcoyote.com/cg_tips/image2kml.php
Just a word about cgImage2KML and cgCBar2KML. These
programs just allow me to add images and color bars to a
KML file without having to do a lot of thinking. As
such, they implement only a portion of the KML functionality.
If I wanted to do more thinking, I could work with
the cgKML*** objects themselves, which implement most
(but not all) of the available KML specification.
This is especially important when it comes to creating
color bars and legends, because there are MANY ways to
do this. You may well want to do something other than
what I allow you to do in cgCBar2KML. If so, you are
free to do it with the cgKML*** objects I provide.
In fact, I wish you would, and then send them to me
so I can make them available for other people to use. :-)
On my Things To Do list is to be able to package
KML files and their corresponding image files up
into a zip file, which is all a KMZ file is. I would
like to be able to do this in a machine independent
way, which means I may be calling on you Mac users
for help. :-)
Here is some code which will allow you to display
the AVHRR NVDI data file 'AF03sep15b.n16-VIg.tif',
which can be downloaded here:
http://www.idlcoyote.com/data/AF03sep15b.n16-VIg.tif
with a color bar, in a KML file:
;; Create the image overlay KML file.
kmlFile = Obj_New('cgKML_File', 'avhrr_ndvi_cb.kml')
cgLoadCT, 11, /Brewer, /Reverse, RGB_Table=palette
map = cgGeoMap('AF03sep15b.n16-VIg.tif', Image=image)
scaledImage = BytScl(image > 0)
cgImage2KML, scaledImage, map, $
Palette=palette, Missing_Value=0, $
Description='AVHRR NDVI Data from Africa', $
PlaceName='AVHRR Africa', $
AddToFile=kmlFile
cgCBar2KML, Palette=palette, Range=[0,9400], $
Title='NDVI Index', $
Description='AVHRR NDVI Color Bar', $
PlaceName='NDVI Color Bar', $
AddToFile=kmlFile
kmlFile -> Save
kmlFile -> Destroy
Note that if you are running this in IDL 8, you can use
the more updated object syntax. For example:
kmlFile = cgKML_File('avhrr_ndvi_cb.kml')
...
kmlFile.Save
You will need a 4PM Sunday, Colorado time, version of the
Coyote Library to run this code:
http://www.idlcoyote.com/programs/zip_files/coyoteprograms.z ip
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
|
|
|