Geography Reference
In-Depth Information
Raster Transparency
The last raster example we'll look at is setting a transparency value.
This is useful when you want the layers underneath the raster to be vis-
ible. To set the transparency, we'll use the GDAL Virtual Format (VRT).
A VRT file is a description of the raster, stored in XML, that can be
modified using a text editor. The first step is to use gdal_translate to cre-
ate the VRT file. In this case, we'll use the survey plat that we digitized
from Section 8.1 , Digitizing, on page 120 . Running the gdal_translate
command on the plat ( l1-1.tif ) creates the VRT for us:
$ gdal_translate -of VRT l1-1.tif l1-1.vrt
Input file size is 9568, 12754
Before we can set the transparency, we have to determine the index
of the white color values in the raster. For this, we use gdalinfo with
the -nomd option since we don't need the metadata, just the color table
information:
$ gdalinfo -nomd l1-1.tif
Driver: GTiff/GeoTIFF
Size is 9568, 12754
Coordinate System is `'
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0,12754.0)
Upper Right ( 9568.0, 0.0)
Lower Right ( 9568.0,12754.0)
Center ( 4784.0, 6377.0)
Band 1 Block=9568x12754 Type=Byte, ColorInterp=Palette
Color Table (RGB with 2 entries)
0: 255,255,255,255
1: 0,0,0,255
From the output, we can see that RGB 255,255,255 (white) is at index
0 in the raster. We now have everything we need to set the transparency
using the VRT file. To set the transparency, we add a <NoDataValue>
tag inside the <VRTRasterBand> tag, using 0 as the index value. Our
modified VRT file contains the following:
Download l1-1.vrt
<VRTDataset rasterXSize="9568" rasterYSize="12754">
Line 1
<Metadata>
-
<MDI key="TIFFTAG_SOFTWARE"> AccXES Version 4.2
Build 106 </MDI>
-
<MDI key="TIFFTAG_DATETIME"> 2004:02:26 16:11:38 </MDI>
-
<MDI key="TIFFTAG_XRESOLUTION"> 400 </MDI>
5
<MDI key="TIFFTAG_YRESOLUTION"> 400 </MDI>
-
<MDI key="TIFFTAG_RESOLUTIONUNIT"> 2 (pixels/inch) </MDI>
-
</Metadata>
-
 
 
Search WWH ::




Custom Search