2

I use the following python code to rasterize a vector layer using gdal.RasterizeLayer

output = 'F:\\TEMP\\rasterized.tif'
target_ds = gdal.GetDriverByName('GTiff').Create(output, x_res, y_res, 1, gdal.GDT_Int32)
target_ds.SetGeoTransform((x_min, pixel_width, 0, y_min, 0, pixel_width))

gdal.RasterizeLayer(target_ds, [1], layer, options=["ATTRIBUTE=id"])

The id used as the ATTRIBUTE is larger than Int32.

I retrive the layer from a database with:

conn = ogr.Open('DB Connection parameters')
sql = "SELECT Statement"
layer = conn.ExecuteSQL(sql)

Notes:

  • The GDAL reference does not mention an Int64 datatype, which is consistent with the GeoTIFF format description.
  • However, the format description also mentions, that BigTIFF is supported when running libtiff >= 4 (which is my case). Reading the libtiff website I could not find a specific reference if Int64 is supported or not.
  • I installed gdal 2.3.2 via miniconda

Questions: How to create a raster in GDAL that supports the Int64 datatype? Does not have to be GeoTIFF.

  • 1
    Hi, I played around with the data types a bit (in ArcMap as well) and I'm fairly sure Int64 (i.e integers above 2147483647) is not supported as a datatype (for common rasters and ESRI shapefiles at least). I am not sure why exactly you would want Int64 as appose to float32, perhaps a file size issue? Anyway, I would say your best bet is just to use float32 for values > 2147483647 and < 3.4E+38. – Jascha Muller Mar 12 at 8:22
  • Agree with Jascha. You can use float32 (also see gdal.GDT_Float64). See this answer for more explanation about the ranges of float and int: stackoverflow.com/a/8746839/5326322 – Andrea Massetti Mar 13 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.