[gdal-dev] Requesting a transparent image from a WMS server...

Carl Godkin cgodkin at gmail.com
Fri Feb 19 05:41:54 PST 2021


Hi,

I'm generating WMS service description files as described here:
https://gdal.org/drivers/raster/wms.html#generation-of-wms-service-description-xml-file

This works well, but I wonder if there's a way to request the image from
the WMS server to be transparent.

If I use gdal_translate to create the WMS service description file like
this:

gdal_translate "WMS:
https://maps-public.geo.nyu.edu:443/geoserver/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=sdr%3Anyu_2451_43745&SRS=EPSG:4326&BBOX=-119.265762329102,35.2621765136719,-118.825294494629,35.4424705505371"
service.xml -of WMS

then I get this:

<GDAL_WMS>
  <Service name="WMS">
    <Version>1.1.1</Version>
    <ServerUrl>https://maps-public.geo.nyu.edu:443/geoserver/wms?SERVICE=WMS
</ServerUrl>
    <Layers>sdr%3Anyu_2451_43745</Layers>
    <SRS>EPSG:4326</SRS>
    <ImageFormat>image/jpeg</ImageFormat>
    <Transparent>FALSE</Transparent>
    <BBoxOrder>xyXY</BBoxOrder>
  </Service>
  <DataWindow>
    <UpperLeftX>-119.265762329102</UpperLeftX>
    <UpperLeftY>35.4424705505371</UpperLeftY>
    <LowerRightX>-118.825294494629</LowerRightX>
    <LowerRightY>35.2621765136719</LowerRightY>
    <SizeX>1073741824</SizeX>
    <SizeY>439508252</SizeY>
  </DataWindow>
  <BandsCount>3</BandsCount>
  <BlockSizeX>1024</BlockSizeX>
  <BlockSizeY>1024</BlockSizeY>
  <OverviewCount>20</OverviewCount>
</GDAL_WMS>

I have discovered that if I slightly edit three lines the service
description like this:

    <ImageFormat>image/geotiff</ImageFormat>
    <Transparent>TRUE</Transparent>
 <BandsCount>4</BandsCount>

then my output image is transparent if I compare these two output files:

gdal_translate -outsize 512 512 -projwin -119.1 35.4 -119 35.3 service.xml
bakersfield.tif
gdal_translate -outsize 512 512 -projwin -119.1 35.4 -119 35.3
service_trans.xml bakersfield_trans.tif

Are there some options I can use in the first gdal_translate command above
to generate the WMS description file so that
it retrieves transparent images if the server supports transparency?

(I am actually creating the service description file in C++ code using
CreateCopy, but I believe it's easy to prototype with the CLI.)

Thanks very much,

carl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20210219/cd969e36/attachment.html>


More information about the gdal-dev mailing list