[gdal-dev] Colour interpretation missing in the TMS mini-driver

Homme Zwaagstra hrz at geodata.soton.ac.uk
Fri Feb 12 04:48:24 EST 2010


Hello all,

I've been using the TMS mini driver for the first time (gdal 1.7.0)
and came across a problem that I think is due to the driver not
setting ColorInterp values on the raster bands it returns.

The problem arose using the gdal plugin to mapnik whereby all the
images mapnik renders using the TMS data are grayscale. It transpires
that mapnik treats gdal derived images as grayscale if no colour
interpretation is present (using the first band it comes across). You
could say this is a mapnik problem, but it seems to me that it is
Gdal's responsibility to properly define the data it returns. In this
case the TMS is returning RGB PNG images but the problem would also
apply to RGBA data sources.

My current workaround is to wrap the GDAL TMS description file in a
VRT file that explicitly assigns ColorInterp values, and use that VRT
as the mapnik datasource. It would be nice if the TMS driver did this
automatically.

Hopefully I'm not missing anything here; if there are no objections
I'll add this as a bug.

The TMS description I'm using is along these lines:

<GDAL_WMS>
  <Service name="TMS">
    <ServerUrl>http://my.local.tms</ServerUrl>
    <Layer>bathymetry</Layer>
    <Format>png</Format>
  </Service>
  <DataWindow>
    <UpperLeftX>-180.0</UpperLeftX>
    <UpperLeftY>90.0</UpperLeftY>
    <LowerRightX>180.0</LowerRightX>
    <LowerRightY>-90.0</LowerRightY>
    <TileLevel>19</TileLevel>
    <TileCountX>2</TileCountX>
    <TileCountY>1</TileCountY>
  </DataWindow>
  <Projection>EPSG:4326</Projection>
  <BlockSizeX>256</BlockSizeX>
  <BlockSizeY>256</BlockSizeY>
  <BandsCount>3</BandsCount>
  <MaxConnections>10</MaxConnections>
  <Timeout>5</Timeout>
</GDAL_WMS>

In case it helps others with the same issue, the VRT that corrects the
problem in mapnik is:

<VRTDataset rasterXSize="268435456" rasterYSize="134217728">
  <SRS>GEOGCS[&quot;WGS 84&quot;,DATUM[&quot;WGS_1984&quot;,SPHEROID[&quot;WGS 84&quot;,6378137,298.257223563,AUTHORITY[&quot;EPSG&quot;,&quot;7030&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;6326&quot;]],PRIMEM[&quot;Greenwich&quot;,0,AUTHORITY[&quot;EPSG&quot;,&quot;8901&quot;]],UNIT[&quot;degree&quot;,0.01745329251994328,AUTHORITY[&quot;EPSG&quot;,&quot;9122&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;4326&quot;]]</SRS>
  <GeoTransform> -1.8000000000000000e+02,  1.3411045074462891e-06,  0.0000000000000000e+00,  9.0000000000000000e+01,  0.0000000000000000e+00, -1.3411045074462891e-06</GeoTransform>
  <Metadata/>
  <VRTRasterBand dataType="Byte" band="1">
    <ColorInterp>Red</ColorInterp>
    <Metadata/>
    <SimpleSource>
      <SourceFilename relativeToVRT="1">tms.xml</SourceFilename>
      <SourceBand>1</SourceBand>
      <SourceProperties RasterXSize="268435456" RasterYSize="134217728" DataType="Byte" BlockXSize="256" BlockYSize="256"/>
      <SrcRect xOff="0" yOff="0" xSize="268435456" ySize="134217728"/>
      <DstRect xOff="0" yOff="0" xSize="268435456" ySize="134217728"/>
    </SimpleSource>
  </VRTRasterBand>
  <VRTRasterBand dataType="Byte" band="2">
    <ColorInterp>Green</ColorInterp>
    <Metadata/>
    <SimpleSource>
      <SourceFilename relativeToVRT="1">tms.xml</SourceFilename>
      <SourceBand>2</SourceBand>
      <SourceProperties RasterXSize="268435456" RasterYSize="134217728" DataType="Byte" BlockXSize="256" BlockYSize="256"/>
      <SrcRect xOff="0" yOff="0" xSize="268435456" ySize="134217728"/>
      <DstRect xOff="0" yOff="0" xSize="268435456" ySize="134217728"/>
    </SimpleSource>
  </VRTRasterBand>
  <VRTRasterBand dataType="Byte" band="3">
    <ColorInterp>Blue</ColorInterp>
    <Metadata/>
    <SimpleSource>
      <SourceFilename relativeToVRT="1">tms.xml</SourceFilename>
      <SourceBand>3</SourceBand>
      <SourceProperties RasterXSize="268435456" RasterYSize="134217728" DataType="Byte" BlockXSize="256" BlockYSize="256"/>
      <SrcRect xOff="0" yOff="0" xSize="268435456" ySize="134217728"/>
      <DstRect xOff="0" yOff="0" xSize="268435456" ySize="134217728"/>
    </SimpleSource>
  </VRTRasterBand>
</VRTDataset>

Kind regards,

Homme

-- 
Homme Zwaagstra
GeoData Institute
University of Southampton



More information about the gdal-dev mailing list