#!/usr/bin/python ## @author Tim Jacobs, VITO NV, Belgium import sys #gdal library to help find out the coordinates from osgeo import gdal #for unicode (UTF-8) reading/writing in Python 2.x import codecs ql_image_filename='Nadia.tif' kml_output_filename='Nadia.kml' overlay_name="My first KML overlay" f=gdal.Open(ql_image_filename) gt=f.GetGeoTransform() east_longitude=gt[0] west_longitude=east_longitude+(f.RasterXSize*gt[1]) north_latitude=gt[3] #assumes first line is northern-most, GeoTransform[5] is negative south_latitude=north_latitude+(f.RasterYSize*gt[5]) #sample content of KML file, with a few values to substitute kml = ( '\n' '\n' ' \n' ' Ground Overlays\n' ' Examples of ground overlays\n' ' \n' ' %s\n' ' \n' ' %s\n' ' \n' ' \n' ' %f\n' ' %f\n' ' %f\n' ' %f\n' ' \n' ' \n' ' \n' '\n' ) %(overlay_name, ql_image_filename, north_latitude, south_latitude, east_longitude, west_longitude) kml = str(kml) with codecs.open(kml_output_filename, encoding='utf-8', mode='w+') as kmlFile: kmlFile.write(kml)