Skip to main content
10 events
when toggle format what by license comment
Nov 24, 2021 at 23:31 comment added user78863 My only other suggestions would be to check that the polygon overlaps the raster coordinates you are setting in SetGeoTransform(). Also, try increasing the xsize & ysize to 5000 or 10000. This would make sense given that you have set a pixel size of 25m.
Nov 24, 2021 at 23:27 comment added LostinSpatialAnalysis That is a good suggestion, though I had actually tried that using gdal.RasterizeLayer(target_ds, [1], source_layer, burn_values=[1]), but unfortunately still a black square of all 0s is shown when brought into QGIS. I really though that would solve the issue, but I am left stumped.
Nov 24, 2021 at 23:26 history edited user78863 CC BY-SA 4.0
Noticed burn value was zero, hence output raster was zero filled.
Nov 24, 2021 at 23:20 comment added user78863 I see the problem. Your burn value is zero. Change this to 1 and it should be OK.
Nov 24, 2021 at 23:13 comment added LostinSpatialAnalysis Understood, I got rid of xres and yres and just placed 100 and 100 for the xsize and ysize to address the number of pixels. I then placed target_ds.SetProjection(prok.ExportToWkt()) after proj = layer.GetSpatialRef() and before I use .RasterizeLayer(), but still the output .tif is all blank 0 value. I pasted my latest attempt in my post to show where I used your suggestions.
Nov 24, 2021 at 22:58 comment added user78863 To reiterate, the Create() function requires the number of pixels along each dimension (xsize, ysize) NOT the resolution (xres, yres). The SetProjection() function should be applied before you rasterize.
Nov 24, 2021 at 22:55 comment added LostinSpatialAnalysis Particularly I am not sure where in the script to place the function to set the projection. The code runs, but the output .tif file is just a blank 0 value square when I open in QGIS.
Nov 24, 2021 at 22:47 comment added LostinSpatialAnalysis Ok, I see that I need actual values for xres and yres. I just replaced them with 100 and 100, and that part of the code runs now. Though I am having some trouble with the SetProject() component.
Nov 24, 2021 at 22:10 history edited user78863 CC BY-SA 4.0
Noticed another bug in the questioner's code.
Nov 24, 2021 at 21:48 history answered user78863 CC BY-SA 4.0