<div dir="ltr"><div><div><div><div><div>Thanks Even,<br><br>The low-res option really helped. Now I can test the commands in seconds instead of hours.<br></div>I did these commands which seem to produce a tif file with overviews and correct transparency.<br>
</div>I've opened it in MapWindow for now to check. MapWindow is using GDAL to read raster files.<br><br></div>I will now convert the hi-res version and try that version in Geoserver.<br></div>Here are the commands I used:<br>
<br># Create a low-res version:<br>gdal_translate my.ecw test\lowres.tif -outsize 1% 1%<br><br></div><div># Fix the almost white pixels:<br></div><div>nearblack -of GTiff -white -o lowres-white.tif lowres.tif<br><br># Warp and mark white pixels as transparent<br>
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 <br>
<br></div><div># Create internal tiles, don't use mask band because Geoserver doesn't like that:<br></div><div>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 <br>
<br></div><div># nodata is now black, but not all pixels are truly black:<br></div><div>nearblack -of GTiff -o lowres-compressed-black.tif lowres-compressed.tif <br><br></div><div># Set the nodata value to black:<br></div>
<div>gdal_translate -a_nodata 0 lowres-compressed-black.tif lowres-compressed-transparent.tif<br><br># Add overviews<br>gdaladdo -r average --config COMPRESS_OVERVIEW JPEG --config PHOTOMETRIC_OVERVIEW YCBCR lowres-compressed-transparent.tif 2 4 8 16 32 64 128<br>
<br></div><br><div><div><div><div><div>Thanks all.<br></div><div><br></div></div></div></div></div><div class="gmail_extra"><div>
<br>
Paul<br></div><br><div class="gmail_quote">2013/2/9 Even Rouault <span dir="ltr"><<a href="mailto:even.rouault@mines-paris.org" target="_blank">even.rouault@mines-paris.org</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Le samedi 09 février 2013 13:48:13, Paul Meems a écrit :<br>
<div class="im">> The last days I've been trying to convert my ecw file to a GeoTiff so I can<br>
> use it in Geoserver.<br>
> The ecw is a mozaik of aerial photos.<br>
> When I do these two commands it is working in Geoserver:<br>
><br>
</div>> - gdal_translate -of GTiff -co tiled=yes -co compress=jpeg -co<br>
<div class="im">> photometric=YCBCR -a_srs EPSG:28992 -co "BLOCKXSIZE=512" -co<br>
> "BLOCKYSIZE=512" my.ecw my.tif<br>
</div>> - gdaladdo -r average --config COMPRESS_OVERVIEW JPEG --config<br>
<div class="im">> PHOTOMETRIC_OVERVIEW YCBCR my.tif 2 4 8 16 32 64 128<br>
><br>
> But I want to add a second reference layer beneath this one which is<br>
> larger. The translated ecw has white edges, so that is not looking nice.<br>
> I've asked about this before and suggested was to use a cutline. So I<br>
> create a polygon that is inside the ecw file and ran this command:<br>
><br>
</div>> - gdalwarp -multi -cutline "clip.shp" -of GTiff -co tiled=yes -co<br>
<div class="im">> compress=jpeg -co photometric=YCBCR -co "BLOCKXSIZE=512" -co<br>
> "BLOCKYSIZE=512" -s_srs EPSG:28992 -r lanczos -overwrite my.ecw<br>
> clipped.tif<br>
><br>
> When I open clipped.tif in MapWindow I can see the white edges are gone.<br>
</div>> But when I call *gdaladdo* white artifacts are back again.<br>
<br>
I'm not clear why gdaladdo would add while artifacts if clipped.tif has no<br>
more white borders (i.e. if your clipping shape is a rectangle completely<br>
inside the validity area of the ECW). Unless clipped.tif has an alpha channel,<br>
but the gdalwarp command line you showed has no -dstalpha. But that wouldn't<br>
work actually since you use JPEG YCbCr compression, which doesn't support<br>
alpha channels.<br>
<br>
A solution - provided that MapWindows supports GDAL mask bands as transparency<br>
channels - would be :<br>
<br>
# Warp and mark white pixels as transparent<br>
gdalwarp 1.tif 2.tif -dstalpha -srcnodata "255 255 255" [other_options]<br>
<br>
# Transform 2.tif as a JPEG-YCBCR-in-TIFF with an internal mask band<br>
gdal_translate 2.tif 3.tif -b 1 -b 2 -b 3 -mask 4 -co compress=jpeg -co<br>
photometric=YCBCR -co BLOCKXSIZE=512 -co BLOCKYSIZE=512 --config<br>
GDAL_TIFF_INTERNAL_MASK YES<br>
<br>
# Add overviews<br>
gdaladdo 3.tif -r average --config COMPRESS_OVERVIEW JPEG --config<br>
PHOTOMETRIC_OVERVIEW YCBCR 2 4<br>
<br>
> I'm now in the process of calling *nearblack* on both my.tiff and<br>
<div class="im">> clipped.tif but I'm not sure I'm doing it right. I think I'm using the<br>
> correct commands but perhaps in the wrong order.<br>
> The ecw file isn't very large (2.6GB) but all steps take a long time,<br>
</div>> especially *nearblack *which is running for 4 hours now and is just at 10%.<br>
><br>
<br>
For the experiments, I'd encourage working with a low res extract of the ECW :<br>
gdal_translate src.ecw lowres.tif -outsize 1% 1%<br>
<div class="im"><br>
> Does anybody have some suggestions how to process the steps to convert an<br>
> ecw file which has white outside areas to a transparent tif file with<br>
> overviews?<br>
><br>
> I'm running the latest GDAL v1.10 version from Tamas on Windows Vista on a<br>
> 8GB 4core machine. Speed is not a big issue when I know the result will be<br>
> OK.<br>
<br>
</div>Another point: It is well known that warping with compression doesn't produce<br>
files with optimal size. See<br>
<a href="http://trac.osgeo.org/gdal/wiki/UserDocs/GdalWarp#GeoTIFFoutput-" target="_blank">http://trac.osgeo.org/gdal/wiki/UserDocs/GdalWarp#GeoTIFFoutput-</a><br>
coCOMPRESSisbroken<br>
<br>
><br>
> Thanks,<br>
><br>
> Paul<br>
</blockquote></div><br></div></div>