<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">Le 20/02/2024 à 11:15, Elena Ruiz via
gdal-dev a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:AS8P192MB2191E10B20C6F4C3DCA57D76BB502@AS8P192MB2191.EURP192.PROD.OUTLOOK.COM">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css" style="display:none;">P {margin-top:0;margin-bottom:0;}</style>
<div class="elementToProof"><span
style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">Hello,
I have version 3.6.2 of GDAL and I need to crop an image using
a contour from a GML file, so far there is no problem.</span></div>
<div
style="text-align: left; text-indent: 0px; background-color: rgb(255, 255, 255); margin: 0px;">
<span
style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br>
</span></div>
<div
style="text-align: left; text-indent: 0px; background-color: rgb(255, 255, 255); margin: 0px;">
<span
style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">The
problem begins when the original image is a GEOTIFF with
transparency and it generates a cropped image, the information
of both images is a little lower.</span></div>
<div
style="text-align: left; text-indent: 0px; background-color: rgb(255, 255, 255); margin: 0px;">
<span
style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br>
</span></div>
<div
style="text-align: left; text-indent: 0px; background-color: rgb(255, 255, 255); margin: 0px;">
<span
style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">The
color table changes from having 2 values to having 256, this
causes it to lose transparency although it has the label "Mask
Flags: PER_DATASET ALPHA" which indicates that it has an alpha
channel.</span></div>
<div
style="text-align: left; text-indent: 0px; background-color: rgb(255, 255, 255); margin: 0px;">
<span
style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br>
</span></div>
<div
style="text-align: left; text-indent: 0px; background-color: rgb(255, 255, 255); margin: 0px;">
<span
style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">My
question is, why does the color table change?, and is there
any parameter that can be used with gdalwarp or gdal_translate
to avoid this and keep the image transparent?</span></div>
</blockquote>
<p>Strictly speaking your input image has no transparency, just
black & white colors. Not sure which one you interpret as
transparent?</p>
<p><br>
</p>
<p>You could force a 1-bit output image (ie with a color palette of
2 colors) by adding -co NBITS=1 . But that will likely won't play
well with -dstalpha. You'd then want to use instead -dstnodata 0
if black is the transparent color or -dstnodata 1 if white is the
transparent color</p>
<p><br>
</p>
<p>Even</p>
<span style="white-space: pre-wrap">
</span>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="http://www.spatialys.com">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</body>
</html>