GDAL – Using gdal_rasterize with Color from Feature Property

gdalgdal-rasterizegeotiff-tiff

Each feature in my geojson file contains a property with hex color codes. Is it possible to convert these vector feature-collection to a geotiff using this color code on every feature ? I populate the properties myself, so I could add any property I want.

Best Answer

All that gdal_rasterize can do is documented in https://gdal.org/programs/gdal_rasterize.html. Without changing the code the best you can to is to burn a coded value for the colors with -a "

-a <attribute_name> Identifies an attribute field on the features to be used for a burn-in value. The value will be burned into all output bands.

I suggest to create a single band 8-bit image with values 1,2,3,4.... Once you have the image it should be possible to color it by creating a vrt file and adding a color palette into it as in this question How to add a color table to a one band tiff using GDAL?. It did not work in the question for 64-bit data but with 8-bit data it should be OK.

Related Question