Initialize project
[guile-gdal] / examples / raster / read-raster.scm
1 #!/usr/bin/env -S guile -s
2 !#
3
4 (add-to-load-path "../..")
5 (use-modules (gdal))
6 (use-modules (rnrs bytevectors))
7
8 (all-register)
9
10 ;; read dataset using the binding functions
11
12 (let* ((dataset (open-dataset "raster-small.txt" GA_READONLY))
13        (h-band (get-raster-band dataset 1))
14        (x-size (get-raster-band-x-size h-band))
15        (y-size (get-raster-band-y-size h-band))
16        (size (* x-size y-size))
17        (bv (make-s32vector size)))
18     (begin 
19         (raster-io h-band GF_READ 0 0 x-size y-size bv x-size y-size GDT_INT32 0 0)
20         (for-each (lambda (i) (format #t "~a " (s32vector-ref bv i)))
21           (iota size))))
22
23 (newline)
24
25 ;; and using the helper functions in the extesion module
26
27 (use-modules (gdal extension))
28
29 (let* ((dataset (open-dataset "raster-small.txt" GA_READONLY))
30        (h-band (get-raster-band dataset 1))
31        (buf (make-buffer-all-from-band h-band GDT_INT32)))
32     (for-each-pixel (lambda (p) (format #t "~a " p)) buf))
33
34 (newline)
35