/*! \page create_raster Creating a raster dataset
The code here does not have any warranty. It is recommended that
before using any of this code, you look into it and try to understand
what it does, what input it needs, etc. Do not blindly execute
anything!
This example will create a raster dataset with one band and with cell
value of type Float32. The raster will be stored as a !GeoTiff and it
will have undefined SRS. The coordinates of the upper left vertex are
known and the size of each pixel. Pixels are squares.
\code
use Geo::GDAL;
$name = "raster"; # name (without extension) for the new raster
$datatype = 'Float32';# datatype for the values in pixels
$width = 100; # number of pixels in x direction
$height = 100; # number of pixels in y direction
$minx = 12.3; # x of the left border of leftmost pixel
$dx = 0.1; # width of pixels
$maxy = 14.5; # y of the top border of topmost pixel
$dy = -0.1; # height of pixels, negative means miny < maxy
$nodata = -1; # nodata value
@data = (); # pixel values, stored in this example in a hash
# note: things that are hardcoded:
# We create a GTiff and set the extension to '.tiff'.
# We add only one band to the raster.
$dataset = Geo::GDAL::Driver('GTiff')->Create($name.'.tiff', $width, $height, 1, $datatype);
$dataset->GeoTransform($minx, $dx, 0, $maxy, 0, -$dy);
$band = $dataset->Band(1);
$band->NoDataValue($nodata);
for (1..100) {
push @data, [1..100];
}
$band->WriteTile(\@data);
@data = ();
for $i (0..19) {
for $j (0..29) {
$data[$i][$j] = $nodata;
}
}
$band->WriteTile(\@data,10,20);
\endcode
*/