3 [GDAL](https://gdal.org/) Scheme bindings for [Guile](https://www.gnu.org/software/guile/) programming language.
5 This library allows you to perform the following tasks:
7 * Open a raster file for reading and writing
8 * Access metadata of raster files
9 * Compute statistics of raster files
10 * Access layers of raster dataset
11 * Helper functions, providing idiomatic Scheme interface to the GDAL APIs
16 Read/write raster files using GDAL binding functions or helper functions
20 (use-modules (gdal extension))
22 (use-modules (rnrs bytevectors))
24 ;; initialize GDAL by registering GDAL drivers
28 ;; read raster dataset using binding functions
30 (let* ((dataset (open-dataset "raster-small.txt" GA_READONLY))
31 (h-band (get-raster-band dataset 1))
32 (x-size (get-raster-band-x-size h-band))
33 (y-size (get-raster-band-y-size h-band))
34 (size (* x-size y-size))
35 (bv (make-s32vector size)))
37 (raster-io h-band GF_READ 0 0 x-size y-size bv x-size y-size GDT_INT32 0 0)
38 (for-each (lambda (i) (format #t "~a " (s32vector-ref bv i)))
43 ;; or read raster dataset using helper functions in the extension module
44 ;; providing more convenient way
46 (let* ((dataset (open-dataset "raster-small.txt" GA_READONLY))
47 (h-band (get-raster-band dataset 1))
48 (buf (make-buffer-all-from-band h-band GDT_INT32)))
49 (for-each-pixel (lambda (p) (format #t "~a " p)) buf))
51 ;; transform pixels using map-pixel function, returning a new binary buffer
52 ;; of type INT16 with 1 for pixels greater than 0, and 0 otherwise.
53 ;; use write-buffer-to-file to save the buffer into the disk in GeoTIFF format.
55 (let* ((dataset (open-dataset "raster-small.txt" GA_READONLY))
56 (h-band (get-raster-band dataset 1))
57 (buf (make-buffer-all-from-band h-band GDT_INT32)))
59 (define new-buf (map-pixel (lambda (p) (if (> p 0) 1 0))
60 buf #:buf-type GDT_INT16))
61 (write-buffer-to-file new-buf GDN_GTIFF
62 "new-raster-small.tif" #:no-data -1)))
65 See examples folder for more code samples.