I have raster with NDVI values. I would like to polygonize the raster to get vector where each polygon is a pixel.
I have tried gdal.Polygonize as described in the documentation and that runs without any error, but the result is just the number 0. I'm not sure if there is way I can display /read the result, or even save it. This is how I did it:
src_ds = gdal.Open( "imgs/response.tiff" )
if src_ds is None:
print ('Unable to open')
sys.exit(1)
srcband = src_ds.GetRasterBand(1)
dst_layername = "POLYGONIZED_STUFF"
drv = ogr.GetDriverByName("ESRI Shapefile")
dst_ds = drv.CreateDataSource( dst_layername + ".shp" )
dst_layer = dst_ds.CreateLayer(dst_layername, srs = None )
gdal.Polygonize( srcband, None, dst_layer, -1, [], callback=None )
>>>
0
I believe maybe there is problem with the GetRasterBand, but couldn't display it either.
My end goal is to be able to access the polygonized results
Best Answer
Firstly, I would question the wisdom of vectorizing a raster containing NDVI values. The vector dataset is likely to be huge and unwieldy.
Having said that, a fast solution would be to convert your raster into XYZ format (point coordinates) using GDAL translate:
If you really need polygons, you can do the following: