Skip to content

Commit b202b35

Browse files
authored
First version
1 parent 45ec107 commit b202b35

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

TIFF2KML.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/python
2+
## @author Tim Jacobs, VITO NV, Belgium
3+
4+
import sys
5+
6+
#gdal library to help find out the coordinates
7+
from osgeo import gdal
8+
9+
#for unicode (UTF-8) reading/writing in Python 2.x
10+
import codecs
11+
12+
if len(sys.argv)<2:
13+
print "Usage", sys.argv[0], "input_ql_image_filename output_kml_filename"
14+
sys.exit(1)
15+
16+
ql_image_filename=sys.argv[1]
17+
kml_output_filename=sys.argv[2]
18+
19+
overlay_name="My first KML overlay"
20+
21+
f=gdal.Open(ql_image_filename)
22+
gt=f.GetGeoTransform()
23+
east_longitude=gt[0]
24+
west_longitude=east_longitude+(f.RasterXSize*gt[1])
25+
north_latitude=gt[3]
26+
#assumes first line is northern-most, GeoTransform[5] is negative
27+
south_latitude=north_latitude+(f.RasterYSize*gt[5])
28+
29+
#sample content of KML file, with a few values to substitute
30+
kml = (
31+
'<?xml version="1.0" encoding="UTF-8"?>\n'
32+
'<kml xmlns="http://www.opengis.net/kml/2.2">\n'
33+
' <Folder>\n'
34+
' <name>Ground Overlays</name>\n'
35+
' <description>Examples of ground overlays</description>\n'
36+
' <GroundOverlay>\n'
37+
' <name>%s</name>\n'
38+
' <Icon>\n'
39+
' <href>%s</href>\n'
40+
' </Icon>\n'
41+
' <LatLonBox>\n'
42+
' <north>%f</north>\n'
43+
' <south>%f</south>\n'
44+
' <east>%f</east>\n'
45+
' <west>%f</west>\n'
46+
' </LatLonBox>\n'
47+
' </GroundOverlay>\n'
48+
' </Folder>\n'
49+
'</kml>\n'
50+
) %(overlay_name, ql_image_filename, north_latitude, south_latitude, east_longitude, west_longitude)
51+
52+
with codecs.open(kml_output_filename, encoding='utf-8', mode='w+') as kmlFile:
53+
kmlFile.write(kml.encode('utf-8'))
54+
55+
#For web services: use following content-type header
56+
#Content-Type: application/vnd.google-earth.kml+xml'

0 commit comments

Comments
 (0)