<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">---------- Forwarded message ---------<br>De : <strong class="gmail_sendername" dir="auto">Naima Dambrine</strong> <span dir="auto"><<a href="mailto:naima.etienne@gmail.com">naima.etienne@gmail.com</a>></span><br>Date: mar. 7 nov. 2023 à 09:16<br>Subject: Re: [gdal-dev] oblique cuts on a raster using python GDAL<br>To: Javier Jimenez Shaw <<a href="mailto:j1@jimenezshaw.com">j1@jimenezshaw.com</a>><br></div><br><br><div dir="ltr">Hi,<div><br></div><div>Thank you very much for your help, it let me try and try again, and you are right when you say that it is possible.</div><div>I finally obtain a perfect cut in python, here is the code :</div><div><div style="font-size:16px;color:rgb(255,255,255);font-family:Avenir-Book"><br></div></div><div><p style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Avenir;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(149,149,149)"><span style="font-kerning:none">gdal.Warp(</span></p>
<p style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Avenir;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(149,149,149)"><span style="font-kerning:none">output-raster,</span></p>
<p style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Avenir;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(149,149,149)"><span style="font-kerning:none">raster-ds,</span></p>
<p style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Avenir;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(149,149,149)"><span style="font-kerning:none">format=<span> </span>‘GTiff’,</span></p>
<p style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Avenir;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(149,149,149)"><span style="font-kerning:none">cutlineDSName= ‘geometry-extraction.shp’,</span></p>
<p style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Avenir;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(149,149,149)"><span style="font-kerning:none">cropToCutline = True,</span></p>
<p style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Avenir;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(149,149,149)"><span style="font-kerning:none">xRes = None, yRes=None,</span></p>
<p style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Avenir;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(149,149,149)"><span style="font-kerning:none">resampleAlg=’nearest’,</span></p>
<p style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Avenir;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(149,149,149)"><span style="font-kerning:none">multithread= True,</span></p>
<p style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Avenir;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(149,149,149)"><span style="font-kerning:none">srcNoData=None, dstNodata=255,</span></p>
<p style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Avenir;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(149,149,149)"><span style="font-kerning:none">options=[‘COMPRESS=DEFLATE’, ‘PREDICTOR=2’, ‘ZLEVEL=9']</span></p>
<p style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Avenir;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(149,149,149)"><span style="font-kerning:none">)</span></p><p style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Avenir;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(149,149,149)"><span style="font-kerning:none"><br></span></p><p style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Avenir;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(149,149,149)"><span style="font-kerning:none">Have a nice day,</span></p><p style="margin:0px;font-stretch:normal;font-size:16px;line-height:normal;font-family:Avenir;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(149,149,149)"><span style="font-kerning:none">Naïma</span></p></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le lun. 6 nov. 2023 à 17:23, Javier Jimenez Shaw <<a href="mailto:j1@jimenezshaw.com" target="_blank">j1@jimenezshaw.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 6 Nov 2023 at 14:43, Naima Dambrine <<a href="mailto:naima.etienne@gmail.com" target="_blank">naima.etienne@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Thank you, can you please paste a zoom image of your result ?<div><br><div>because if i translate your gdalwarp in python :<div><br><div><span style="color:rgb(0,0,0)">gdalwarp 3635_rasters_agreges.jp2 salida.tif -cutline geometry_extraction.shp -crop_to_cutline -dstnodata 0 -cl geometry_extraction -overwrite -of GTiff</span><br></div><div><span style="color:rgb(0,0,0)"><br></span></div><div><span style="color:rgb(0,0,0)">gdal.Warp(</span><span style="color:rgb(0,0,0)">'</span><span style="color:rgb(0,0,0)">salida.tif', '</span><span style="color:rgb(0,0,0)">3635_rasters_agreges.jp2', format='GTiff', cutlineDSName='</span><span style="color:rgb(0,0,0)">geometry_extraction.shp</span><span style="color:rgb(0,0,0)">', cropToCutline=True, dstNoData=0)</span></div><div><span style="color:rgb(0,0,0)"><br></span></div><div><font color="#000000"><span>it's the same code ... and I do not obtain a clean image at all</span></font></div><div><span style="color:rgb(0,0,0)"><br></span></div><div><span style="color:rgb(0,0,0)"><br></span></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le lun. 6 nov. 2023 à 14:05, Javier Jimenez Shaw <<a href="mailto:j1@jimenezshaw.com" target="_blank">j1@jimenezshaw.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>This is working for me (and also in gdal 3.8.0):</div><div><br></div><div>gdalwarp 3635_rasters_agreges.jp2 salida.tif -cutline geometry_extraction.shp -crop_to_cutline -dstnodata 0 -cl geometry_extraction -overwrite -of GTiff</div><div><br></div><div>About the "white" pixels inside the image, it could be that a single band has a value of 0 (not that strange). Then it is transparent, and you see the background color. (to avoid those "color misunderstandings" I have a pink background color, that is not white).<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 6 Nov 2023 at 12:35, Naima Dambrine <<a href="mailto:naima.etienne@gmail.com" target="_blank">naima.etienne@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi Javier,<div><br></div><div>Thank you, good news ...</div><div><br></div><div>I'm on Ubuntu 20.04 with gdal 3.6.2. Yes, the original raster format is JP2, but my output format is GTiff. Here is exactly what I do :</div><div><br></div><div>cut_ds = gdal.Warp(outfile, jp2_ds, format='GTiff', cutlineDCName=shape_file_path,</div><div>cropToCutline=True,</div><div>copyMetadat=True,</div><div>dstNodata=0)</div><div><br></div><div>What I see is that there are still black pixels around the image, as well as white pixels inside the image. </div><div>Another point to consider is that, despite the use of compression, the output file is 75.3 MB, compared with around 14 MB with a JP2 format. Why is this?<br></div><div><br></div><div>my output :</div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le lun. 6 nov. 2023 à 11:33, Javier Jimenez Shaw <<a href="mailto:j1@jimenezshaw.com" target="_blank">j1@jimenezshaw.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi Naima</div><div><br></div><div>I have been testing with your dataset. To me, using the GDAL in Ubuntu 22.04 (3.4.1) seems to be a problem with the JP2 output format. If you output as geotiff it works fine.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, 5 Nov 2023 at 19:43, Rahkonen Jukka via gdal-dev <<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div>
<div lang="FI">
<div>
<p class="MsoNormal"><span>Hi,<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">Please add gdalinfo of the source image. Even better if you can share the image.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">-Jukka Rahkonen-<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<div style="border-width:1pt medium medium;border-style:solid none none;border-color:rgb(225,225,225) currentcolor currentcolor;padding:3pt 0cm 0cm">
<p class="MsoNormal"><b>Lähettäjä:</b> gdal-dev <<a href="mailto:gdal-dev-bounces@lists.osgeo.org" target="_blank">gdal-dev-bounces@lists.osgeo.org</a>>
<b>Puolesta </b>Naima Dambrine via gdal-dev<br>
<b>Lähetetty:</b> sunnuntai 5. marraskuuta 2023 17.35<br>
<b>Vastaanottaja:</b> <a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<b>Aihe:</b> [gdal-dev] oblique cuts on a raster using python GDAL<u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Avenir-Book,serif;color:black">Hi ,<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Avenir-Book,serif;color:black"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:13.5pt;font-family:Avenir-Book,serif;color:black">I have problems with oblique cuts on a raster using python GDAL (3.6.2)</span><span style="font-size:12pt;font-family:Avenir-Book,serif;color:black"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Avenir-Book,serif;color:black"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:13.5pt;font-family:Avenir-Book,serif;color:black">- with this line i obtain black borders around :</span><span style="font-size:12pt;font-family:Avenir-Book,serif;color:black"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:13.5pt;font-family:Avenir-Book,serif;color:black">gdal.warp('raster-dst' , raster-src', cutLineDSName='geometry-extraction.shp', cropToCutline=True)</span><span style="font-size:12pt;font-family:Avenir-Book,serif;color:black"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-family:Avenir-Book,serif;color:black"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Avenir-Book,serif;color:black">- with this one, </span><span style="font-size:13.5pt;font-family:Avenir-Book,serif;color:black">the crop is not clean on closer inspection: residual black pixels
around image and white pixels appear in the image.</span><span style="font-family:Avenir-Book,serif;color:black"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:13.5pt;font-family:Avenir-Book,serif;color:black">gdal. warp( 'raster-dst' , raster-src', cutLineDSName='geometry-extraction.shp', cropToCutline=True, copyMetaData=True, dstNodata=0)</span><span style="font-family:Avenir-Book,serif;color:black"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12pt"><span style="font-family:Avenir-Book,serif;color:black"><br>
</span><span style="font-size:13.5pt;font-family:Avenir-Book,serif;color:black">I tried, without success, to refine with outputBounds=[minX, maxX, minY, maxY], under QGIS directly …. </span><span style="font-family:Avenir-Book,serif;color:black"><br>
</span><span style="font-size:13.5pt;font-family:Avenir-Book,serif;color:black">I've run out of ideas :/ </span><span style="font-family:Avenir-Book,serif;color:black"><br>
</span><span style="font-size:13.5pt;font-family:Avenir-Book,serif;color:black">A (naive) question comes to mind: Is it possible to make oblique cuts with gdal.warp() & co?</span><span style="font-family:Avenir-Book,serif;color:black"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Avenir-Book,serif;color:black">Naïma<u></u><u></u></span></p>
</div>
</div>
</div>
</div>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</div></blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</div></div>