I have a shapefile containing a number of polygons and all attributes being text. I'm trying to import the polygons into NumPy as an array where each polygon is represented as unique values.
I approach this by using gdal_rasterize to generate a GeoTIFF, which I then can convert to an array:
gdal_rasterize -a provcode -l longhurst PG:'host=localhost dbname=biomes' -tr 0.25 0.25 out.tif
and
tif = gdal.Open('out.tif')
tifArray = tif.ReadAsArray()
My problem is that all polygons get the same values since provcode is of type string. How can I make gdal_rasterize burn different values to represent different polygons?
Alternatively, is there a better way to do this conversion?