I want to polygonize a raster file with GDAL. I only want to rasterize cells with a value of 0. Is it possible to specify that within the polygonize function or do I have to modify my raster before hand?

1 Answer 1


No, it's not possible directly in the function. You can either a) reclassify the raster first (probably fastest and easiest), or 2) convert to vector then delete all non-zero polygons, or 3) create a mask, and pass that to gdal_polygonize using -mask (see manual.)

  • 4
    Thank for suggestions. I tested the first and third methods, and the third one works for me. The reason why the first one did not work was that even if I reclassified the raster (1 for the part, which I want to polygonize, nodata for the part, which I want to delete), the GDAL polygonize function still converted the whole raster into polygons. So, just classify raster into 1 and 0 for the mask, and you should be good to go.
    – Vicky Liau
    Apr 23, 2015 at 0:17
  • Just to mention that using the -mask parameter makes the process faster for me. Just tested with both options Dec 15, 2021 at 2:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.