Producing a KML-friendly (Google Earth) image

All,

It took a fair bit of trial and error to coax a KML-friendly image out
of matplotlib and to understand what was and was not necessary. Below
is a demo script demonstrating how to accomplish a KML-friendly image
with and without a basemap. I hope this will help someone out.

What do I mean by a KML-friendly image? In KML you can overlay a
complicated geo-referenced image but it is geo-referenced based on the
boundaries of the image. So, for the image to be correctly displayed
in a KML document, the edges of the image have to be relatable to a
latitude or longitude. Most of the time this will mean you are using
Basemap and you'll need an image that encompasses only the bounding
box and nothing outside...no whitespace, extra room for titling, etc.

The below examples accomplish this. Turns out, the two key elements are

(1) ax = pyplot.axes((0,0,1,1))

and if you are using Basemap:

(2) a kwarg in Basemap: fix_aspect=False

Thanks!

Bruce

···

---------------------------------------
Bruce W. Ford
Clear Science, Inc.
bruce@...2905...
http://www.ClearScienceInc.com
Phone/Fax: 904-379-9704
8241 Parkridge Circle N.
Jacksonville, FL 32211
Skype: bruce.w.ford
Google Talk: fordbw@...287...

Bruce Ford wrote:

All,

It took a fair bit of trial and error to coax a KML-friendly image out
of matplotlib and to understand what was and was not necessary. Below
is a demo script demonstrating how to accomplish a KML-friendly image
with and without a basemap. I hope this will help someone out.

What do I mean by a KML-friendly image? In KML you can overlay a
complicated geo-referenced image but it is geo-referenced based on the
boundaries of the image. So, for the image to be correctly displayed
in a KML document, the edges of the image have to be relatable to a
latitude or longitude. Most of the time this will mean you are using
Basemap and you'll need an image that encompasses only the bounding
box and nothing outside...no whitespace, extra room for titling, etc.

The below examples accomplish this. Turns out, the two key elements are

(1) ax = pyplot.axes((0,0,1,1))

and if you are using Basemap:

(2) a kwarg in Basemap: fix_aspect=False

Thanks!

Bruce
  
Bruce: That's great, I've always wondered how to do that. However your example didn't make it to the list, perhaps you forgot to attach it?

-Jeff

···

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...259...
325 Broadway Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg

You're right...here it is.

test_figure_for_kml.py (1.61 KB)

···

---------------------------------------
Bruce W. Ford
Clear Science, Inc.
bruce@...2905...
bruce.w.ford.ctr@...2906...
http://www.ClearScienceInc.com
Phone/Fax: 904-379-9704
8241 Parkridge Circle N.
Jacksonville, FL 32211
Skype: bruce.w.ford
Google Talk: fordbw@...287...

On Wed, Mar 3, 2010 at 10:27 AM, Jeff Whitaker <jswhit@...146...> wrote:

Bruce Ford wrote:

All,

It took a fair bit of trial and error to coax a KML-friendly image out
of matplotlib and to understand what was and was not necessary. Below
is a demo script demonstrating how to accomplish a KML-friendly image
with and without a basemap. I hope this will help someone out.

What do I mean by a KML-friendly image? In KML you can overlay a
complicated geo-referenced image but it is geo-referenced based on the
boundaries of the image. So, for the image to be correctly displayed
in a KML document, the edges of the image have to be relatable to a
latitude or longitude. Most of the time this will mean you are using
Basemap and you'll need an image that encompasses only the bounding
box and nothing outside...no whitespace, extra room for titling, etc.

The below examples accomplish this. Turns out, the two key elements are

(1) ax = pyplot.axes((0,0,1,1))

and if you are using Basemap:

(2) a kwarg in Basemap: fix_aspect=False

Thanks!

Bruce

Bruce: That's great, I've always wondered how to do that. However your
example didn't make it to the list, perhaps you forgot to attach it?

-Jeff

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : Jeffrey.S.Whitaker@...2583...9...
325 Broadway Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg