[Gdal-dev] Getting started with raster processing with GDAL/OGR
Lucena, Ivan
ivan.lucena at pmldnet.com
Sun Sep 9 21:02:40 EDT 2007
André,
Since you are used to the GDAL Python API your transition from Vector to
Raster shouldn't be hard at all.
> The problem is that I don't have any experience creating raster data,
> so although I'm pretty confident I could process the point data by
> creating the b-box coords mathematically, I don't know how to create
> an output raster and assign values to each pixel.
If what you have is a sell-space in a Python dictionary I believe that
you can go thought the existing cells and pass the values to a raster
buffer and then write it in a band (It could be optimized) line by line.
A very simplified sample code would be something like that:
###
import gdal
import Numeric
n_rows = 180 # your calculated
n_cols = 360 # values goes here
gdal.AllRegister()
tif_driver = gdal.GetDriverByName("gtiff")
tif_ds = tif_driver.Create("\Data\grid.tif", n_cols, n_rows, 1)
tif_rb = tif_ds.GetRasterBand(1)
buffer = Numeric.zeros((1, n_cols), Numeric.Int)
# attention: ^^^
# loop through all rows of your dictionary :
x = 11 #
x = 38 # hypothetical values in the middle of your loop
z = 4 #
buffer[0][y] = z
tif_rb.WriteArray(buffer, 0, x)
# end loop
tif_ds = None
tif_driver = None
###
You can also take a look at one of the GDAL command line utilities like
pct2rgb.py for a more complete example.
Regards,
Ivan
More information about the Gdal-dev
mailing list