0

I have a shapefile that consists of two fields/attributes, one being integers, the other being strings.

I can extract the integers into Python array by first using the function gdal.RasterizeLayer() to burn the shapefile into a .tiff image as the first band. Then, I use my_raster.GetRasterBand(1).ReadAsArray() to read the integers as an array.

However, I would like to extract the string values from the other field/attribute. I doing the exact same thing but I have already changed the attribute name in the gdal.RasterizeLayer() specification. However, calling GetRasterBand(1).ReadAsArray() only gives me zeros.

Does anyone know whether it is possible to read strings from rasters?

Btw: I'm using the exact same code as here.

Check it out from

Pure Python version -- gdal.RasterizeLayer

Val
  • 6,585
  • 5
  • 22
  • 52
adam
  • 1
  • My raster can be found here: https://www.dropbox.com/s/iq759fclrkfmyar/Area1_geo.tiff?dl=0 – adam Jun 12 '18 at 20:48
  • My shapefile can be found here: https://www.dropbox.com/s/awt6zzc63rbxfwm/Sectors.shp?dl=0 – adam Jun 12 '18 at 20:54
  • Could you elaborate a bit about why you need the rasterization part? Why would you need an "array of strings"? Its seems easier to just read the attributes of the shapefile. And if needed rasterize a mask for which you use the attributes as a lookup table. – Rutger Kassies Jun 13 '18 at 11:39
  • Sure. I'm classifying crop land using different pixel-based machine learning algorithms. Having done so, I create a heat map of the crop probabilities, and from the heat map you can easily see the crop land. Next, I want to know which sectors/areas/districts these pixels belong to and for this, I want to use the shape file with strings, like "Area 1", "Area ", etc for all the pixels. Maybe there is a smarter way to do this? – adam Jun 14 '18 at 12:23

0 Answers0