[gdal-dev] problem with datatype in python
Luca Delucchi
lucadeluge at gmail.com
Thu Sep 3 08:34:27 PDT 2015
Hi devs,
I'm trying to rasterize a vector layer and convert it to numpy array.
I'm using the gdal.RasterizeLayer function but I have problem to set
the right datatype. I would like to have UInt32 but I got every time
Byte, this is my code
target_ds = gdal.GetDriverByName('MEM').Create('', xcount, ycount,
gdal.GDT_UInt32)
target_ds.SetGeoTransform((fi.ulx, fi.geotransform[1], 0, fi.uly, 0,
fi.geotransform[5]))
shape_datasource = ogr.Open(invect)
shape_layer = shape_datasource.GetLayer()
# create for target raster the same projection as for the value raster
raster_srs = osr.SpatialReference()
raster_srs.ImportFromWkt(fi.s_fh.GetProjectionRef())
target_ds.SetProjection(raster_srs.ExportToWkt())
# rasterize zone polygon to raster
gdal.RasterizeLayer(target_ds, [1], shape_layer, None, None, [1],
['ATTRIBUTE=id', 'ALL_TOUCHED=TRUE'])
trees_indices = gdal_array.DatasetReadAsArray(target_ds)
This is the debug
(Pdb) trees_indices.max()
255
(Pdb) ba=target_ds.GetRasterBand(1)
(Pdb) ba.DataType
1
Have you any idea to solve this problem?
--
ciao
Luca
http://gis.cri.fmach.it/delucchi/
www.lucadelu.org
More information about the gdal-dev
mailing list