[gdal-dev] Converting ecw to tif for Geoserver

Even Rouault even.rouault at mines-paris.org
Sat Feb 9 05:17:37 PST 2013

Le samedi 09 février 2013 13:48:13, Paul Meems a écrit :
> The last days I've been trying to convert my ecw file to a GeoTiff so I can
> use it in Geoserver.
> The ecw is a mozaik of aerial photos.
> When I do these two commands it is working in Geoserver:
>    - gdal_translate -of GTiff -co tiled=yes -co compress=jpeg -co
>    photometric=YCBCR -a_srs EPSG:28992 -co "BLOCKXSIZE=512" -co
>    "BLOCKYSIZE=512" my.ecw my.tif
>    - gdaladdo -r average --config COMPRESS_OVERVIEW JPEG --config
>    PHOTOMETRIC_OVERVIEW YCBCR  my.tif 2 4 8 16 32 64 128
> But I want to add a second reference layer beneath this one which is
> larger. The translated ecw has white edges, so that is not looking nice.
> I've asked about this before and suggested was to use a cutline. So I
> create a polygon that is inside the ecw file and ran this command:
>    - gdalwarp -multi -cutline "clip.shp" -of GTiff -co tiled=yes -co
>    compress=jpeg -co photometric=YCBCR -co "BLOCKXSIZE=512" -co
>    "BLOCKYSIZE=512" -s_srs EPSG:28992 -r lanczos -overwrite my.ecw
> clipped.tif
> When I open clipped.tif in MapWindow I can see the white edges are gone.
> But when I call *gdaladdo* white artifacts are back again.

I'm not clear why gdaladdo would add while artifacts if clipped.tif has no 
more white borders (i.e. if your clipping shape is a rectangle completely 
inside the validity area of the ECW). Unless clipped.tif has an alpha channel, 
but the gdalwarp command line you showed has no -dstalpha. But that wouldn't 
work actually since you use JPEG YCbCr compression, which doesn't support 
alpha channels.

A solution - provided that MapWindows supports GDAL mask bands as transparency 
channels - would be :

# Warp and mark white pixels as transparent
gdalwarp 1.tif 2.tif -dstalpha -srcnodata "255 255 255" [other_options]

# Transform 2.tif as a JPEG-YCBCR-in-TIFF with an internal mask band
gdal_translate 2.tif 3.tif -b 1 -b 2 -b 3 -mask 4 -co compress=jpeg -co 
photometric=YCBCR -co BLOCKXSIZE=512 -co BLOCKYSIZE=512 --config 

# Add overviews
gdaladdo 3.tif  -r average --config COMPRESS_OVERVIEW JPEG --config

> I'm now in the process of calling *nearblack* on both my.tiff and
> clipped.tif but I'm not sure I'm doing it right. I think I'm using the
> correct commands but perhaps in the wrong order.
> The ecw file isn't very large (2.6GB) but all steps take a long time,
> especially *nearblack *which is running for 4 hours now and is just at 10%.

For the experiments, I'd encourage working with a low res extract of the ECW : 
gdal_translate src.ecw lowres.tif -outsize 1% 1%

> Does anybody have some suggestions how to process the steps to convert an
> ecw file which has white outside areas to a transparent tif file with
> overviews?
> I'm running the latest GDAL v1.10 version from Tamas on Windows Vista on a
> 8GB 4core machine. Speed is not a big issue when I know the result will be
> OK.

Another point: It is well known that warping with compression doesn't produce 
files with optimal size. See 

> Thanks,
> Paul

More information about the gdal-dev mailing list