File: cr.dox

package info (click to toggle)
gdal 1.10.1%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 84,320 kB
  • ctags: 74,726
  • sloc: cpp: 677,199; ansic: 162,820; python: 13,816; cs: 11,163; sh: 10,446; java: 5,279; perl: 4,429; php: 2,971; xml: 1,500; yacc: 934; makefile: 494; sql: 112
file content (49 lines) | stat: -rw-r--r-- 1,658 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*! \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

*/