---------- Forwarded message --------- De : Naima Dambrine <naima.etie...@gmail.com> Date: mar. 7 nov. 2023 à 09:16 Subject: Re: [gdal-dev] oblique cuts on a raster using python GDAL To: Javier Jimenez Shaw <j...@jimenezshaw.com>
Hi, 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. I finally obtain a perfect cut in python, here is the code : gdal.Warp( output-raster, raster-ds, format= ‘GTiff’, cutlineDSName= ‘geometry-extraction.shp’, cropToCutline = True, xRes = None, yRes=None, resampleAlg=’nearest’, multithread= True, srcNoData=None, dstNodata=255, options=[‘COMPRESS=DEFLATE’, ‘PREDICTOR=2’, ‘ZLEVEL=9'] ) Have a nice day, Naïma Le lun. 6 nov. 2023 à 17:23, Javier Jimenez Shaw <j...@jimenezshaw.com> a écrit : > > > On Mon, 6 Nov 2023 at 14:43, Naima Dambrine <naima.etie...@gmail.com> > wrote: > >> Thank you, can you please paste a zoom image of your result ? >> >> because if i translate your gdalwarp in python : >> >> gdalwarp 3635_rasters_agreges.jp2 salida.tif -cutline >> geometry_extraction.shp -crop_to_cutline -dstnodata 0 -cl >> geometry_extraction -overwrite -of GTiff >> >> gdal.Warp('salida.tif', '3635_rasters_agreges.jp2', format='GTiff', >> cutlineDSName='geometry_extraction.shp', cropToCutline=True, dstNoData=0) >> >> it's the same code ... and I do not obtain a clean image at all >> >> >> >> Le lun. 6 nov. 2023 à 14:05, Javier Jimenez Shaw <j...@jimenezshaw.com> a >> écrit : >> >>> This is working for me (and also in gdal 3.8.0): >>> >>> gdalwarp 3635_rasters_agreges.jp2 salida.tif -cutline >>> geometry_extraction.shp -crop_to_cutline -dstnodata 0 -cl >>> geometry_extraction -overwrite -of GTiff >>> >>> 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). >>> >>> On Mon, 6 Nov 2023 at 12:35, Naima Dambrine <naima.etie...@gmail.com> >>> wrote: >>> >>>> Hi Javier, >>>> >>>> Thank you, good news ... >>>> >>>> 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 : >>>> >>>> cut_ds = gdal.Warp(outfile, jp2_ds, format='GTiff', >>>> cutlineDCName=shape_file_path, >>>> cropToCutline=True, >>>> copyMetadat=True, >>>> dstNodata=0) >>>> >>>> What I see is that there are still black pixels around the image, as >>>> well as white pixels inside the image. >>>> 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? >>>> >>>> my output : >>>> >>>> >>>> >>>> >>>> Le lun. 6 nov. 2023 à 11:33, Javier Jimenez Shaw <j...@jimenezshaw.com> >>>> a écrit : >>>> >>>>> Hi Naima >>>>> >>>>> 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. >>>>> >>>>> On Sun, 5 Nov 2023 at 19:43, Rahkonen Jukka via gdal-dev < >>>>> gdal-dev@lists.osgeo.org> wrote: >>>>> >>>>>> Hi, >>>>>> >>>>>> >>>>>> >>>>>> Please add gdalinfo of the source image. Even better if you can share >>>>>> the image. >>>>>> >>>>>> >>>>>> >>>>>> -Jukka Rahkonen- >>>>>> >>>>>> >>>>>> >>>>>> *Lähettäjä:* gdal-dev <gdal-dev-boun...@lists.osgeo.org> *Puolesta *Naima >>>>>> Dambrine via gdal-dev >>>>>> *Lähetetty:* sunnuntai 5. marraskuuta 2023 17.35 >>>>>> *Vastaanottaja:* gdal-dev@lists.osgeo.org >>>>>> *Aihe:* [gdal-dev] oblique cuts on a raster using python GDAL >>>>>> >>>>>> >>>>>> >>>>>> Hi , >>>>>> >>>>>> >>>>>> >>>>>> I have problems with oblique cuts on a raster using python GDAL >>>>>> (3.6.2) >>>>>> >>>>>> >>>>>> >>>>>> - with this line i obtain black borders around : >>>>>> >>>>>> gdal.warp('raster-dst' , raster-src', >>>>>> cutLineDSName='geometry-extraction.shp', cropToCutline=True) >>>>>> >>>>>> >>>>>> >>>>>> - with this one, the crop is not clean on closer inspection: >>>>>> residual black pixels around image and white pixels appear in the image. >>>>>> >>>>>> gdal. warp( 'raster-dst' , raster-src', >>>>>> cutLineDSName='geometry-extraction.shp', cropToCutline=True, >>>>>> copyMetaData=True, dstNodata=0) >>>>>> >>>>>> >>>>>> I tried, without success, to refine with outputBounds=[minX, maxX, >>>>>> minY, maxY], under QGIS directly …. >>>>>> I've run out of ideas :/ >>>>>> A (naive) question comes to mind: Is it possible to make oblique cuts >>>>>> with gdal.warp() & co? >>>>>> >>>>>> Naïma >>>>>> _______________________________________________ >>>>>> gdal-dev mailing list >>>>>> gdal-dev@lists.osgeo.org >>>>>> https://lists.osgeo.org/mailman/listinfo/gdal-dev >>>>>> >>>>>
_______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/gdal-dev