<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><div data-html-editor-font-wrapper="true" style="font-family: arial, sans-serif; font-size: 13px;">Maybe this could help a little.<br><br>I had a problem a while ago when I wanted to filter just the mask and then assemble it again. It took some reading to get it right.<br>So I took the image apart with gdal_translate -b mask. Then ran gdal_sieve.py where I got a 8 bit mask.<br>The tricky part was then the assembly. This is how I did the reassemble with two gdalbuildvrt:<br><br>### Convert the mask to a real 1 bit mask with the right mask flags<br>### and deflate compression<br><br>echo "gdal_translate - real mask"<br><br>gdal_translate \<br> -of GTiff \<br> -ot Byte \<br> -co NBITS=1 \<br> -co COMPRESS=DEFLATE \<br> -mo INTERNAL_MASK_FLAGS_1=2 \<br> ${TIF_TMP_DIR}/${TIF_FILE_NAME}_mask_separate_clean.tif \<br> ${TIF_TMP_DIR}/${TIF_FILE_NAME}_mask.msk<br><br>### Combine the image with the mask<br><br>gdalbuildvrt -b 1 ${TIF_TMP_DIR}/${TIF_FILE_NAME}_warp_1.vrt ${TIF_TMP_DIR}/${TIF_FILE_NAME}_warp.tif<br>gdalbuildvrt -b 2 ${TIF_TMP_DIR}/${TIF_FILE_NAME}_warp_2.vrt ${TIF_TMP_DIR}/${TIF_FILE_NAME}_warp.tif<br>gdalbuildvrt -b 3 ${TIF_TMP_DIR}/${TIF_FILE_NAME}_warp_3.vrt ${TIF_TMP_DIR}/${TIF_FILE_NAME}_warp.tif<br><br>echo "gdalbuildvrt"<br><br>gdalbuildvrt \<br> -separate ${TIF_TMP_DIR}/${TIF_FILE_NAME}_combined.vrt \<br> ${TIF_TMP_DIR}/${TIF_FILE_NAME}_warp_1.vrt \<br> ${TIF_TMP_DIR}/${TIF_FILE_NAME}_warp_2.vrt \<br> ${TIF_TMP_DIR}/${TIF_FILE_NAME}_warp_3.vrt \<br> ${TIF_TMP_DIR}/${TIF_FILE_NAME}_mask.msk<br><br>echo "final gdal_translate"<br><br>gdal_translate \<br> -b 1 -b 2 -b 3 -mask 4 \<br> -co COMPRESS=NONE \<br> -co TILED=YES \<br> -co BLOCKXSIZE=512 \<br> -co BLOCKYSIZE=512 \<br> -co INTERLEAVE=BAND \<br> --config GDAL_TIFF_INTERNAL_MASK YES \<br> --config GDAL_CACHEMAX 512 \<br> ${TIF_TMP_DIR}/${TIF_FILE_NAME}_combined.vrt \<br> ${DATA_OUTPUT_DIR}/${TIF_FILE_NAME}.tif<br><br>Hope this helps you to take the image apart and then put back together again.<br><br>/Lars S.<br><br><br>11 februari 2021 kl. 18:37, "Patrick Young" <<a target="_blank" tabindex="-1" href="mailto:patrick.mckendree.young@gmail.com?to=%22Patrick%20Young%22%20<patrick.mckendree.young@gmail.com>">patrick.mckendree.young@gmail.com</a>> skrev:<br> <blockquote><div><div> <div dir="ltr">Not sure what the expected behavior is with gdalwarp and the underlying mask preservation. It is kind of a tricky problem to solve in general; should the mask be resampled with the same kernel as used in the warp? Or should it always be NN? If the functionality is missing, this is a good opportunity to get your employer funding gdal development.<div></div> <div>A quick hack would be like you mention; you can extract the datamask (gdal_translate -b mask ... i think) and then warp that separately, and recombine.</div> <div></div> <div>P<div></div> <div></div> </div> </div> <div> <div dir="ltr">On Thu, Feb 11, 2021 at 7:57 AM Daniele Romagnoli <<a rel="external nofollow noopener noreferrer" target="_blank" tabindex="-1" href="mailto:daniele.romagnoli@geo-solutions.it">daniele.romagnoli@geo-solutions.it</a>> wrote:</div> <blockquote style="margin: 0px 0px 0px 0.8ex;border-left: 1px solid rgb(204,204,204);padding-left: 1ex"> <div dir="ltr">Hi Jukka,<div>sorry but I can't share the data. Is owned by a customer :(</div> <div></div> <div>Long story short:</div> <div>I have several raster tiles (with size around 5000x5000) and a shapefile containing edges defining valid area of each tile.</div> <div></div> <div>I have used gdalrasterize to extract the needed crop for each tile to setup a binary mask.</div> <div>Then, I have combined the binary mask with the original tile and rewritten as a new TIFF file with internal masks.</div> <div>Then, I'm composing all the TIFF files to a VRT.</div> <div>When rewriting that VRT to a mosaic TIFF, everything looks good. I see the binary mask is used to properly compose/overlap/mask the pieces of the mosaic and the output contains the mask too. This is an example of gdalinfo on one of the mosaicked tiff:</div> <div></div> <div>Driver: GTiff/GeoTIFF<br>Files: out.tif<br>Size is 45842, 42506<br>Coordinate System is:<br>[... OMITTED... ]<br><br>Metadata:<br>AREA_OR_POINT=Area<br>Image Structure Metadata:<br>COMPRESSION=YCbCr JPEG<br>INTERLEAVE=PIXEL<br>JPEGTABLESMODE=1<br>JPEG_QUALITY=75<br>SOURCE_COLOR_SPACE=YCbCr<br>Corner Coordinates:<br>[... OMITTED... ]<br>Band 1 Block=256x256 Type=Byte, ColorInterp=Red<br>Mask Flags: PER_DATASET<br>Band 2 Block=256x256 Type=Byte, ColorInterp=Green<br>Mask Flags: PER_DATASET<br>Band 3 Block=256x256 Type=Byte, ColorInterp=Blue<br>Mask Flags: PER_DATASET</div> <div></div> <div>So, as you can see the masks are added to the mosaicked dataset.</div> <div></div> <div>However, when running</div> <div>gdalwarp -t_srs EPSG:NEWCODE out.tif warped.tif</div> <div></div> <div>the binary mask is lost from the output file.</div> <div>I have also tried using -dstalpha but it complains that "Destination dataset has 3 bands, but at least 4 are needed" which makes sense.</div> <div></div> <div>So I was just wondering if there is anything I should be aware of when warping a masked TIFF.</div> <div>I would probably try to transform the binary mask to an alpha band, do the warp and then convert back the alpha to a binary mask....</div> <div></div> <div>Thanks for any feedback in advance.</div> <div>Regards,</div> <div>Daniele</div> <div></div> <div></div> <div></div> <div></div> </div> <div> <div dir="ltr">On Thu, Feb 11, 2021 at 3:27 PM jratike80 <<a target="_blank" rel="external nofollow noopener noreferrer" tabindex="-1" href="mailto:jukka.rahkonen@maanmittauslaitos.fi">jukka.rahkonen@maanmittauslaitos.fi</a>> wrote:</div> <blockquote style="margin: 0px 0px 0px 0.8ex;border-left: 1px solid rgb(204,204,204);padding-left: 1ex">Hi Daniele,<br><br>Test data, please.<br><br>-Jukka Rahkonen-<br><br><br><br>Daniele Romagnoli-3 wrote<br>> Thanks for the feedback, Patrick.<br>> I have downloaded the latest build from GisInternals and it worked as<br>> expected.<br>> I have another question.<br>> It looks like warping an input file containing a binary mask isn't<br>> preserving the binary mask on the output.<br>> Should I specify any flag for that?<br>><br>> Thanks for the help.<br>> Regards,<br>> Daniele<br>> _______________________________________________<br>> gdal-dev mailing list<br><br>> gdal-dev@.osgeo<br><br>> <a rel="external nofollow noopener noreferrer" target="_blank" tabindex="-1" href="https://lists.osgeo.org/mailman/listinfo/gdal-dev">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br><br><br><br><br><br>--<br>Sent from: <a rel="external nofollow noopener noreferrer" target="_blank" tabindex="-1" href="http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html">http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html</a><br>_______________________________________________<br>gdal-dev mailing list<br><a target="_blank" rel="external nofollow noopener noreferrer" tabindex="-1" href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br><a rel="external nofollow noopener noreferrer" target="_blank" tabindex="-1" href="https://lists.osgeo.org/mailman/listinfo/gdal-dev">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a> </blockquote> </div> <div></div>--<div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"> <div dir="ltr">Regards,</div> <div dir="ltr">Daniele Romagnoli</div> <div dir="ltr">==</div> <div dir="ltr">GeoServer Professional Services from the experts! Visit <a target="_blank" rel="external nofollow noopener noreferrer" tabindex="-1" href="http://goo.gl/it488V">http://goo.gl/it488V</a> for more information.</div> <div dir="ltr">==</div> <div dir="ltr"></div> <div dir="ltr">Ing. Daniele Romagnoli</div> <div dir="ltr">Senior Software Engineer</div> <div dir="ltr"></div> <div dir="ltr">GeoSolutions S.A.S.</div> <div dir="ltr">Via di Montramito 3/A</div> <div dir="ltr">55054 Massarosa (LU)</div> <div dir="ltr">Italy</div> <div dir="ltr">phone: +39 0584 962313</div> <div dir="ltr">fax: +39 0584 1660272</div> <div dir="ltr"></div> <div dir="ltr"><a target="_blank" rel="external nofollow noopener noreferrer" tabindex="-1" href="http://www.geo-solutions.it">http://www.geo-solutions.it</a></div> <div dir="ltr"><a target="_blank" rel="external nofollow noopener noreferrer" tabindex="-1" href="http://twitter.com/geosolutions_it">http://twitter.com/geosolutions_it</a></div> <div dir="ltr"></div> <div dir="ltr"> <div dir="ltr"><span style="font-size: 12.8px">-------------------------------------------------------</span></div> <div dir="ltr"></div> <div dir="ltr"><span style="font-size: 12.8px">Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia.</span></div> <div dir="ltr"></div> <div dir="ltr"><span style="font-size: 12.8px">This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 “GDPR” - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail.</span></div> </div> </div></div></div></div></div></div></div></div></div></div></div></div></div> _______________________________________________<br>gdal-dev mailing list<br><a target="_blank" rel="external nofollow noopener noreferrer" tabindex="-1" href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br><a rel="external nofollow noopener noreferrer" target="_blank" tabindex="-1" href="https://lists.osgeo.org/mailman/listinfo/gdal-dev">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a> </blockquote> </div> </div></div></blockquote> <br><br><signature></signature> </div></body></html>