[GRASS-user] Raster Google Earth script using gdal2tiles.py

John A Stevenson john.stevenson at manchester.ac.uk
Wed May 13 05:31:23 EDT 2009


Hi,

I've seen various ways of getting GRASS rasters into Google Earth tiles 
but always seemed to have trouble with the colours or the 
reprojections.  This is what I finally found worked for me, so am 
posting it in case it is useful to anyone else.  It requires a recent 
version of gdal (I have 1.5.2) to provied the gdal2tiles.py script, and 
the ImageMagick program mogrify to make null regions of the map (which 
were white in my map) transparent.

I hope that it is useful.

Later

John

r.out.ge

#!/bin/bash
# Export map to Google Earth tiles.

map=$1

# Export map as png and make null data transparent
g.region rast=$map
export `g.region zoom=$map -lg` # Get map bounds in Lat Long
r.out.png $map
mogrify -transparent white $map.png

# Georeference and reproject output
gdal_translate -a_srs EPSG:4326 -a_ullr $nw_long $nw_lat $se_long 
$se_lat $map.png $map.tif
gdalwarp -t_srs EPSG:4326 -rc $map.tif $map\4326.tif

# Tile for Google Earth
gdal2tiles.py -title $map -forcekml $map\4326.tif $map

-- 


Dr John Stevenson
Postdoctoral Research Associate
School of Earth, Atmospheric and Environmental Sciences
Williamson Building (Room 2.42)
University of Manchester
Manchester M13 9PL, UK
tel. +44(0)161 306 6585; fax. +44(0)161 306 9361;
john.stevenson at manchester.ac.uk 



More information about the grass-user mailing list