[gdal-dev] Converting ecw to tif for Geoserver

Paul Meems bontepaarden at gmail.com
Sat Feb 9 06:11:54 PST 2013


Thanks Even,

The low-res option really helped. Now I can test the commands in seconds
instead of hours.
I did these commands which seem to produce a tif file with overviews and
correct transparency.
I've opened it in MapWindow for now to check. MapWindow is using GDAL to
read raster files.

I will now convert the hi-res version and try that version in Geoserver.
Here are the commands I used:

# Create a low-res version:
gdal_translate my.ecw test\lowres.tif -outsize 1% 1%

# Fix the almost white pixels:
nearblack -of GTiff -white -o lowres-white.tif lowres.tif

# Warp and mark white pixels as transparent
gdalwarp -multi -of GTiff -dstalpha -srcnodata "255 255 255" -co tiled=yes
-co "BLOCKXSIZE=512" -co "BLOCKYSIZE=512" -s_srs EPSG:28992 -r lanczos
-overwrite lowres-white.tif lowres-transparent.tif

# Create internal tiles, don't use mask band because Geoserver doesn't like
that:
gdal_translate -of GTiff -a_srs EPSG:28992 -b 1 -b 2 -b 3 -co tiled=yes -co
compress=jpeg -co photometric=YCBCR -co BLOCKXSIZE=512 -co BLOCKYSIZE=512
--config GDAL_TIFF_INTERNAL_MASK YES lowres-transparent.tif
lowres-compressed.tif

# nodata is now black, but not all pixels are truly black:
nearblack -of GTiff -o lowres-compressed-black.tif lowres-compressed.tif

# Set the nodata value to black:
gdal_translate -a_nodata 0 lowres-compressed-black.tif
lowres-compressed-transparent.tif

# Add overviews
gdaladdo -r average --config COMPRESS_OVERVIEW JPEG --config
PHOTOMETRIC_OVERVIEW YCBCR lowres-compressed-transparent.tif 2 4 8 16 32 64
128


Thanks all.


Paul

2013/2/9 Even Rouault <even.rouault at mines-paris.org>

> 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
> GDAL_TIFF_INTERNAL_MASK YES
>
> # Add overviews
> gdaladdo 3.tif  -r average --config COMPRESS_OVERVIEW JPEG --config
>    PHOTOMETRIC_OVERVIEW YCBCR  2 4
>
> > 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
> http://trac.osgeo.org/gdal/wiki/UserDocs/GdalWarp#GeoTIFFoutput-
> coCOMPRESSisbroken
>
> >
> > Thanks,
> >
> > Paul
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20130209/b2b565a2/attachment.html>


More information about the gdal-dev mailing list