2 #:use-module (system foreign)
3 #:use-module (rnrs bytevectors)
5 #:use-module (srfi srfi-9)
6 #:use-module (srfi srfi-1)
7 #:use-module (srfi srfi-11)
8 #:use-module (srfi srfi-4 gnu)
9 #:use-module (gdal config)
10 #:use-module (gdal internal)
11 #:re-export (GDT_UNKNOWN
25 ;;------------------------------------------------------------------------------
29 ;;------------------------------------------------------------------------------
31 ;;; GDALAsyncStatusType enums
32 (define-public GARIO_PENDING 0)
33 (define-public GARIO_UPDATE 1)
34 (define-public GARIO_ERROR 2)
35 (define-public GARIO_COMPLETE 3)
36 (define-public GARIO_TYPECOUNT 4)
38 ;;; GDALColorInterp enums
39 (define-public GCI_UNDEFINED 0)
40 (define-public GCI_GRAY_INDEX 1)
41 (define-public GCI_PALETTE_INDEX 2)
42 (define-public GCI_RED_BAND 3)
43 (define-public GCI_GREEN_BAND 4)
44 (define-public GCI_BLUE_BAND 5)
45 (define-public GCI_ALPHA_BAND 6)
46 (define-public GCI_HUE_BAND 7)
47 (define-public GCI_SATURATION_BAND 8)
48 (define-public GCI_LIGHTNESS_BAND 9)
49 (define-public GCI_CYAN_BAND 10)
50 (define-public GCI_MAGENTA_BAND 11)
51 (define-public GCI_YELLOW_BAND 12)
52 (define-public GCI_BLACK_BAND 13)
53 (define-public GCI_YCBCR_Y_BAND 14)
54 (define-public GCI_YCBCR_CB_Band 15)
55 (define-public GCI_YCBCR_CR_Band 16)
56 (define-public GCI_MAX 16)
58 ;;; GDALPaletteInterp enums
59 (define-public GPI_GRAY 0)
60 (define-public GPI_RGB 1)
61 (define-public GPI_CMYK 2)
62 (define-public GPI_HLS 3)
65 (define-public GA_READONLY 0)
66 (define-public GA_UPDATE 1)
69 (define-public CE_NONE 0)
70 (define-public CE_DEBUG 1)
71 (define-public CE_WARNING 2)
72 (define-public CE_FAILURE 3)
73 (define-public CE_FATAL 4)
76 (define-public GF_READ 0)
77 (define-public GF_WRITE 1)
79 ;;; GDALRIOResampleAlg enums
80 (define-public GRIORA_NEAREST_NEIGHBOUR 0)
81 (define-public GRIORA_BILINEAR 1)
82 (define-public GRIORA_CUBIC 2)
83 (define-public GRIORA_CUBIC_SPLINE 3)
84 (define-public GRIORA_LANCZOS 4)
85 (define-public GRIORA_AVERAGE 5)
86 (define-public GRIORA_MODE 6)
87 (define-public GRIORA_GAUSS 7)
89 ;;; GDALRIOResampleAlg v2 enums
90 (define-public GRIORAv2_NEAREST_NEIGHBOUR 0)
91 (define-public GRIORAv2_BILINEAR 1)
92 (define-public GRIORAv2_CUBIC 2)
93 (define-public GRIORAv2_CUBIC_SPLINE 3)
94 (define-public GRIORAv2_LANCZOS 4)
95 (define-public GRIORAv2_AVERAGE 5)
96 (define-public GRIORAv2_MODE 6)
97 (define-public GRIORAv2_GAUSS 7)
98 (define-public GRIORAv2_AVERAGE_MAGPHASE 8)
99 (define-public GRIORAv2_NONE 9)
101 (define *grioeav2-to-string*
102 `((,GRIORAv2_NEAREST_NEIGHBOUR . ,"NEAREST")
103 (,GRIORAv2_BILINEAR . ,"BILINEAR")
104 (,GRIORAv2_CUBIC . ,"CUBIC")
105 (,GRIORAv2_CUBIC_SPLINE . ,"CUBICSPLINE")
106 (,GRIORAv2_LANCZOS . ,"LANCZOS")
107 (,GRIORAv2_AVERAGE . ,"AVERAGE")
108 (,GRIORAv2_MODE . ,"MODE")
109 (,GRIORAv2_GAUSS . ,"GAUSS")
110 (,GRIORAv2_AVERAGE_MAGPHASE . ,"AVERAGE_MAGPHASE")
111 (,GRIORAv2_NONE . ,"NONE")))
113 ;;; Enums of known driver short names
114 (define-public GDN_AAIGRID "AAIGrid")
115 (define-public GDN_ACE2 "ACE2")
116 (define-public GDN_ADRG "ADRG")
117 (define-public GDN_AERONAVFAA "AeronavFAA")
118 (define-public GDN_AIG "AIG")
119 (define-public GDN_AIRSAR "AirSAR")
120 (define-public GDN_AMIGOCLOUD "AmigoCloud")
121 (define-public GDN_ARCGEN "ARCGEN")
122 (define-public GDN_ARG "ARG")
123 (define-public GDN_AVCBIN "AVCBin")
124 (define-public GDN_AVCE00 "AVCE00")
125 (define-public GDN_BAG "BAG")
126 (define-public GDN_BIGGIF "BIGGIF")
127 (define-public GDN_BLX "BLX")
128 (define-public GDN_BMP "BMP")
129 (define-public GDN_BNA "BNA")
130 (define-public GDN_BSB "BSB")
131 (define-public GDN_BT "BT")
132 (define-public GDN_CAD "CAD")
133 (define-public GDN_CALS "CALS")
134 (define-public GDN_CARTO "Carto")
135 (define-public GDN_CEOS "CEOS")
136 (define-public GDN_CLOUDANT "Cloudant")
137 (define-public GDN_COASP "COASP")
138 (define-public GDN_COSAR "COSAR")
139 (define-public GDN_COUCHDB "CouchDB")
140 (define-public GDN_CPG "CPG")
141 (define-public GDN_CSV "CSV")
142 (define-public GDN_CSW "CSW")
143 (define-public GDN_CTABLE2 "CTable2")
144 (define-public GDN_CTG "CTG")
145 (define-public GDN_DERIVED "DERIVED")
146 (define-public GDN_DGN "DGN")
147 (define-public GDN_DIMAP "DIMAP")
148 (define-public GDN_DIPEX "DIPEx")
149 (define-public GDN_DODS "DODS")
150 (define-public GDN_DOQ1 "DOQ1")
151 (define-public GDN_DOQ2 "DOQ2")
152 (define-public GDN_DTED "DTED")
153 (define-public GDN_DXF "DXF")
154 (define-public GDN_E00GRID "E00GRID")
155 (define-public GDN_ECRGTOC "ECRGTOC")
156 (define-public GDN_EDIGEO "EDIGEO")
157 (define-public GDN_EHDR "EHdr")
158 (define-public GDN_EIR "EIR")
159 (define-public GDN_ELAS "ELAS")
160 (define-public GDN_ELASTICSEARCH "ElasticSearch")
161 (define-public GDN_ENVI "ENVI")
162 (define-public GDN_EPSILON "EPSILON")
163 (define-public GDN_ERS "ERS")
164 (define-public GDN_ESAT "ESAT")
165 (define-public GDN_ESRI_SHAPEFILE "ESRI Shapefile")
166 (define-public GDN_ESRIJSON "ESRIJSON")
167 (define-public GDN_FAST "FAST")
168 (define-public GDN_FIT "FIT")
169 (define-public GDN_FUJIBAS "FujiBAS")
170 (define-public GDN_GENBIN "GenBin")
171 (define-public GDN_GEOCONCEPT "Geoconcept")
172 (define-public GDN_GEOJSON "GeoJSON")
173 (define-public GDN_GEOMEDIA "Geomedia")
174 (define-public GDN_GEORSS "GeoRSS")
175 (define-public GDN_GFF "GFF")
176 (define-public GDN_GFT "GFT")
177 (define-public GDN_GIF "GIF")
178 (define-public GDN_GML "GML")
179 (define-public GDN_GMLAS "GMLAS")
180 (define-public GDN_GMT "GMT")
181 (define-public GDN_GNMDATABASE "GNMDatabase")
182 (define-public GDN_GNMFILE "GNMFile")
183 (define-public GDN_GPKG "GPKG")
184 (define-public GDN_GPSBABEL "GPSBabel")
185 (define-public GDN_GPSTRACKMAKER "GPSTrackMaker")
186 (define-public GDN_GPX "GPX")
187 (define-public GDN_GRASSASCIIGRID "GRASSASCIIGrid")
188 (define-public GDN_GRIB "GRIB")
189 (define-public GDN_GS7BG "GS7BG")
190 (define-public GDN_GSAG "GSAG")
191 (define-public GDN_GSBG "GSBG")
192 (define-public GDN_GSC "GSC")
193 (define-public GDN_GTIFF "GTiff")
194 (define-public GDN_GTX "GTX")
195 (define-public GDN_GXF "GXF")
196 (define-public GDN_HDF4 "HDF4")
197 (define-public GDN_HDF4IMAGE "HDF4Image")
198 (define-public GDN_HDF5 "HDF5")
199 (define-public GDN_HDF5IMAGE "HDF5Image")
200 (define-public GDN_HF2 "HF2")
201 (define-public GDN_HFA "HFA")
202 (define-public GDN_HTF "HTF")
203 (define-public GDN_HTTP "HTTP")
204 (define-public GDN_IDA "IDA")
205 (define-public GDN_IDRISI "Idrisi")
206 (define-public GDN_ILWIS "ILWIS")
207 (define-public GDN_INGR "INGR")
208 (define-public GDN_INTERLIS_1 "Interlis 1")
209 (define-public GDN_INTERLIS_2 "Interlis 2")
210 (define-public GDN_IRIS "IRIS")
211 (define-public GDN_ISCE "ISCE")
212 (define-public GDN_ISIS2 "ISIS2")
213 (define-public GDN_ISIS3 "ISIS3")
214 (define-public GDN_JAXAPALSAR "JAXAPALSAR")
215 (define-public GDN_JDEM "JDEM")
216 (define-public GDN_JML "JML")
217 (define-public GDN_JP2OPENJPEG "JP2OpenJPEG")
218 (define-public GDN_JPEG "JPEG")
219 (define-public GDN_JPEGLS "JPEGLS")
220 (define-public GDN_KML "KML")
221 (define-public GDN_KMLSUPEROVERLAY "KMLSUPEROVERLAY")
222 (define-public GDN_KRO "KRO")
223 (define-public GDN_L1B "L1B")
224 (define-public GDN_LAN "LAN")
225 (define-public GDN_LCP "LCP")
226 (define-public GDN_LEVELLER "Leveller")
227 (define-public GDN_LIBKML "LIBKML")
228 (define-public GDN_LOSLAS "LOSLAS")
229 (define-public GDN_MAP "MAP")
230 (define-public GDN_MAPINFO_FILE "MapInfo File")
231 (define-public GDN_MBTILES "MBTiles")
232 (define-public GDN_MEM "MEM")
233 (define-public GDN_MEMORY "Memory")
234 (define-public GDN_MFF "MFF")
235 (define-public GDN_MFF2 "MFF2")
236 (define-public GDN_MRF "MRF")
237 (define-public GDN_MSGN "MSGN")
238 (define-public GDN_MSSQLSPATIAL "MSSQLSpatial")
239 (define-public GDN_MVT "MVT")
240 (define-public GDN_MYSQL "MySQL")
241 (define-public GDN_NAS "NAS")
242 (define-public GDN_NDF "NDF")
243 (define-public GDN_NETCDF "netCDF")
244 (define-public GDN_NGSGEOID "NGSGEOID")
245 (define-public GDN_NITF "NITF")
246 (define-public GDN_NTV2 "NTv2")
247 (define-public GDN_NWT_GRC "NWT_GRC")
248 (define-public GDN_NWT_GRD "NWT_GRD")
249 (define-public GDN_ODBC "ODBC")
250 (define-public GDN_ODS "ODS")
251 (define-public GDN_OGR_DODS "OGR_DODS")
252 (define-public GDN_OGR_GMT "OGR_GMT")
253 (define-public GDN_OGR_OGDI "OGR_OGDI")
254 (define-public GDN_OGR_PDS "OGR_PDS")
255 (define-public GDN_OGR_SDTS "OGR_SDTS")
256 (define-public GDN_OGR_VRT "OGR_VRT")
257 (define-public GDN_OPENAIR "OpenAir")
258 (define-public GDN_OPENFILEGDB "OpenFileGDB")
259 (define-public GDN_OSM "OSM")
260 (define-public GDN_OZI "OZI")
261 (define-public GDN_PAUX "PAux")
262 (define-public GDN_PCIDSK "PCIDSK")
263 (define-public GDN_PCRASTER "PCRaster")
264 (define-public GDN_PDF "PDF")
265 (define-public GDN_PDS "PDS")
266 (define-public GDN_PDS4 "PDS4")
267 (define-public GDN_PGDUMP "PGDUMP")
268 (define-public GDN_PGEO "PGeo")
269 (define-public GDN_PLMOSAIC "PLMOSAIC")
270 (define-public GDN_PLSCENES "PLSCENES")
271 (define-public GDN_PNG "PNG")
272 (define-public GDN_PNM "PNM")
273 (define-public GDN_POSTGISRASTER "PostGISRaster")
274 (define-public GDN_POSTGRESQL "PostgreSQL")
275 (define-public GDN_PRF "PRF")
276 (define-public GDN_R "R")
277 (define-public GDN_RASTERLITE "Rasterlite")
278 (define-public GDN_RDA "RDA")
279 (define-public GDN_REC "REC")
280 (define-public GDN_RIK "RIK")
281 (define-public GDN_RMF "RMF")
282 (define-public GDN_ROI_PAC "ROI_PAC")
283 (define-public GDN_RPFTOC "RPFTOC")
284 (define-public GDN_RRASTER "RRASTER")
285 (define-public GDN_RS2 "RS2")
286 (define-public GDN_RST "RST")
287 (define-public GDN_S57 "S57")
288 (define-public GDN_SAFE "SAFE")
289 (define-public GDN_SAGA "SAGA")
290 (define-public GDN_SAR_CEOS "SAR_CEOS")
291 (define-public GDN_SDTS "SDTS")
292 (define-public GDN_SEGUKOOA "SEGUKOOA")
293 (define-public GDN_SEGY "SEGY")
294 (define-public GDN_SELAFIN "Selafin")
295 (define-public GDN_SENTINEL2 "SENTINEL2")
296 (define-public GDN_SGI "SGI")
297 (define-public GDN_SNODAS "SNODAS")
298 (define-public GDN_SOSI "SOSI")
299 (define-public GDN_SQLITE "SQLite")
300 (define-public GDN_SRP "SRP")
301 (define-public GDN_SRTMHGT "SRTMHGT")
302 (define-public GDN_SUA "SUA")
303 (define-public GDN_SVG "SVG")
304 (define-public GDN_SXF "SXF")
305 (define-public GDN_TERRAGEN "Terragen")
306 (define-public GDN_TIGER "TIGER")
307 (define-public GDN_TIL "TIL")
308 (define-public GDN_TOPOJSON "TopoJSON")
309 (define-public GDN_TSX "TSX")
310 (define-public GDN_UK_NTF "UK .NTF")
311 (define-public GDN_USGSDEM "USGSDEM")
312 (define-public GDN_VDV "VDV")
313 (define-public GDN_VFK "VFK")
314 (define-public GDN_VICAR "VICAR")
315 (define-public GDN_VRT "VRT")
316 (define-public GDN_WALK "Walk")
317 (define-public GDN_WASP "WAsP")
318 (define-public GDN_WCS "WCS")
319 (define-public GDN_WEBP "WEBP")
320 (define-public GDN_WFS "WFS")
321 (define-public GDN_WFS3 "WFS3")
322 (define-public GDN_WMS "WMS")
323 (define-public GDN_WMTS "WMTS")
324 (define-public GDN_XLS "XLS")
325 (define-public GDN_XLSX "XLSX")
326 (define-public GDN_XPLANE "XPlane")
327 (define-public GDN_XPM "XPM")
328 (define-public GDN_XYZ "XYZ")
329 (define-public GDN_ZMAP "ZMap")
331 ;;; OGRwkbGeometryType enums
332 (define-public WKB_UNKNOWN 0)
333 (define-public WKB_POINT 1)
334 (define-public WKB_LINE_STRING 2)
335 (define-public WKB_POLYGON 3)
336 (define-public WKB_MULTI_POINT 4)
337 (define-public WKB_MULTI_LINE_STRING 5)
338 (define-public WKB_MULTI_POLYGON 6)
339 (define-public WKB_GEOMETRY_COLLECTION 7)
340 (define-public WKB_COMPOUND_CURVE 9)
341 (define-public WKB_CURVE_POLYGON 10)
342 (define-public WKB_MULTI_CURVE 11)
343 (define-public WKB_MULTI_SURFACE 12)
344 (define-public WKB_CURVE 13)
345 (define-public WKB_SURFACE 14)
346 (define-public WKB_POLYHEDRAL_SURFACE 15)
347 (define-public WKB_TIN 16)
348 (define-public WKB_TRIANGLE 17)
349 (define-public WKB_NONE 100)
350 (define-public WKB_LINEAR_RING 101)
351 (define-public WKB_CIRCULAR_STRING_Z 1008)
352 (define-public WKB_COMPOUND_CURVE_Z 1009)
353 (define-public WKB_CURVE_POLYGON_Z 1010)
354 (define-public WKB_MULTI_CURVE_Z 1011)
355 (define-public WKB_MULTI_SURFACE_Z 1012)
356 (define-public WKB_CURVE_Z 1013)
357 (define-public WKB_SURFACE_Z 1014)
358 (define-public WKB_POLYHEDRAL_SURFACE_Z 1015)
359 (define-public WKB_TIN_Z 1016)
360 (define-public WKB_TRIANGLE_Z 1017)
361 (define-public WKB_POINT_M 2001)
362 (define-public WKB_LINE_STRING_M 2002)
363 (define-public WKB_POLYGON_M 2003)
364 (define-public WKB_MULTI_POINT_M 2004)
365 (define-public WKB_MULTI_LINE_STRING_M 2005)
366 (define-public WKB_MULTI_POLYGON_M 2006)
367 (define-public WKB_GEOMETRY_COLLECTION_M 2007)
368 (define-public WKB_CIRCULAR_STRING_M 2008)
369 (define-public WKB_COMPOUND_CURVE_M 2009)
370 (define-public WKB_CURVE_POLYGON_M 2010)
371 (define-public WKB_MULTI_CURVE_M 2011)
372 (define-public WKB_MULTI_SURFACE_M 2012)
373 (define-public WKB_CURVE_M 2013)
374 (define-public WKB_SURFACE_M 2014)
375 (define-public WKB_POLYHEDRAL_SURFACE_M 2015)
376 (define-public WKB_TIN_M 2016)
377 (define-public WKB_TRIANGLE_M 2017)
378 (define-public WKB_POINT_ZM 3001)
379 (define-public WKB_LINE_STRING_ZM 3002)
380 (define-public WKB_POLYGON_ZM 3003)
381 (define-public WKB_MULTI_POINT_ZM 3004)
382 (define-public WKB_MULTI_LINE_STRING_ZM 3005)
383 (define-public WKB_MULTI_POLYGON_ZM 3006)
384 (define-public WKB_GEOMETRY_COLLECTION_ZM 3007)
385 (define-public WKB_CIRCULAR_STRING_ZM 3008)
386 (define-public WKB_COMPOUND_CURVE_ZM 3009)
387 (define-public WKB_CURVE_POLYGON_ZM 3010)
388 (define-public WKB_MULTI_CURVE_ZM 3011)
389 (define-public WKB_MULTI_SURFACE_ZM 3012)
390 (define-public WKB_CURVE_ZM 3013)
391 (define-public WKB_SURFACE_ZM 3014)
392 (define-public WKB_POLYHEDRAL_SURFACE_ZM 3015)
393 (define-public WKB_TIN_ZM 3016)
394 (define-public WKB_TRIANGLE_ZM 3017)
395 (define-public WKB_POINT_25D #x80000001)
396 (define-public WKB_LINE_STRING_25D #x80000002)
397 (define-public WKB_POLYGON_25D #x80000003)
398 (define-public WKB_MULTI_POINT_25D #x80000004)
399 (define-public WKB_MULTI_LINE_STRING_25D #x80000005)
400 (define-public WKB_MULTI_POLYGON_25D #x80000006)
401 (define-public WKB_GEOMETRY_COLLECTION_25D #x80000007)
404 (define-public GMF_ALL_VALID #x01)
405 (define-public GMF_PER_DATASET #x02)
406 (define-public GMF_ALPHA #x04)
407 (define-public GMF_NODATA #x08)
410 (define-public GDAL_OF_READONLY #x00)
411 (define-public GDAL_OF_UPDATE #x01)
412 (define-public GDAL_OF_ALL #x00)
413 (define-public GDAL_OF_RASTER #x02)
414 (define-public GDAL_OF_VECTOR #x04)
415 (define-public GDAL_OF_GNM #x08)
416 (define-public GDAL_OF_MULTIDIM_RASTER #x10)
417 (define-public GDAL_OF_KIND_MASK #x1e)
418 (define-public GDAL_OF_SHARED #x20)
419 (define-public GDAL_OF_VERBOSE_ERROR #x40)
420 (define-public GDAL_OF_INTERNAL #x80)
421 (define-public GDAL_OF_DEFAULT_BLOCK_ACCESS 0)
422 (define-public GDAL_OF_ARRAY_BLOCK_ACCESS #x100)
423 (define-public GDAL_OF_HASHSET_BLOCK_ACCESS #x200)
424 (define-public GDAL_OF_BLOCK_ACCESS_MASK #x300)
427 (define-public ODSC_CREATE_LAYER "CreateLayer")
428 (define-public ODSC_DELETE_LAYER "DeleteLayer")
429 (define-public ODSC_CREATE_GEOM_FIELD_AFTER_CREATE_LAYER
430 "CreateGeomFieldAfterCreateLayer")
431 (define-public ODSC_CURVE_GEOMETRIES "CurveGeometries")
432 (define-public ODSC_TRANSACTIONS "Transactions")
433 (define-public ODSC_EMULATED_TRANSACTIONS "EmulatedTransactions")
434 (define-public ODSC_RANDOM_LAYER_READ "RandomLayerRead")
435 (define-public ODSC_RANDOM_LAYER_WRITE "RandomLayerWrite")
438 (define-public OGRERR_NONE 0)
439 (define-public OGRERR_NOT_ENOUGH_DATA 1)
440 (define-public OGRERR_NOT_ENOUGH_MEMORY 2)
441 (define-public OGRERR_UNSUPPORTED_GEOMETRY_TYPE 3)
442 (define-public OGRERR_UNSUPPORTED_OPERATION 4)
443 (define-public OGRERR_CORRUPT_DATA 5)
444 (define-public OGRERR_FAILURE 6)
445 (define-public OGRERR_UNSUPPORTED_SRS 7)
446 (define-public OGRERR_INVALID_HANDLE 8)
447 (define-public OGRERR_NON_EXISTING_FEATURE 9)
450 (define-public GFU_GENERIC 0)
451 (define-public GFU_PIXEL_COUNT 1)
452 (define-public GFU_NAME 2)
453 (define-public GFU_MIN 3)
454 (define-public GFU_MAX 4)
455 (define-public GFU_MIN_MAX 5)
456 (define-public GFU_RED 6)
457 (define-public GFU_GREEN 7)
458 (define-public GFU_BLUE 8)
459 (define-public GFU_ALPHA 9)
460 (define-public GFU_RED_MIN 10)
461 (define-public GFU_GREEN_MIN 11)
462 (define-public GFU_BLUE_MIN 12)
463 (define-public GFU_ALPHA_MIN 13)
464 (define-public GFU_RED_MAX 14)
465 (define-public GFU_GREEN_MAX 15)
466 (define-public GFU_BLUE_MAX 16)
467 (define-public GFU_ALPHA_MAX 17)
470 (define-public GFT_INTEGER 0)
471 (define-public GFT_REAL 1)
472 (define-public GFT_STRING 2)
475 (define-public GRTT_THEMATIC 0)
476 (define-public GRTT_ATHEMATIC 1)
478 ;;------------------------------------------------------------------------------
482 ;;------------------------------------------------------------------------------
486 (define-record-type <gcp>
487 (%make-gcp id info pixel line x y z)
489 (id gcp-id set-gcp-id!)
490 (info gcp-info set-gcp-info!)
491 (pixel gcp-pixel set-gcp-pixel!)
492 (line gcp-line set-gcp-line!)
495 (z gcp-z set-gcp-z!))
497 (define* (make-gcp #:key
505 (%make-gcp id info pixel line x y z))
524 (define gcp-types (list '* '* double double double double double))
526 (define (gcp->pointer record)
530 (list (string->pointer (gcp-id record))
531 (string->pointer (gcp-info record))
539 (define (pointer->gcp pointer)
540 (let ((lst (parse-c-struct pointer gcp-types)))
541 (make-gcp #:id (pointer->string (list-ref lst 0))
542 #:info (pointer->string (list-ref lst 1))
543 #:pixel (list-ref lst 2)
544 #:line (list-ref lst 3)
547 #:z (list-ref lst 6))))
549 (define (gcp-list->pointer lst)
550 (struct-list->pointer lst (sizeof gcp-types) gcp->pointer))
552 (define (pointer->gcp-list pointer count)
553 (pointer->struct-list pointer count (sizeof gcp-types) pointer->gcp))
555 (export pointer->gcp-list)
556 ;;; GDALRasterIOExtraArg
558 (define-record-type <grioea>
559 (%make-grioea version resample-alg progress-callback progress-data
560 is-fp-window-valid x-off y-off x-size y-size)
562 (version grioea-version set-grioea-version!)
563 (resample-alg grioea-resample-alg set-grioea-resample-alg!)
564 (progress-callback grioea-progress-callback set-grioea-progress-callback!)
565 (progress-data grioea-progress-data set-grioea-progress-data!)
566 (is-fp-window-valid grioea-is-fp-window-valid set-grioea-is-fp-window-valid!)
567 (x-off grioea-x-off set-grioea-x-off!)
568 (y-off grioea-y-off set-grioea-y-off!)
569 (x-size grioea-x-size set-grioea-x-size!)
570 (y-size grioea-y-size set-grioea-y-size!))
572 (define (gdal-progress-func progress-callback)
573 (if (null? progress-callback)
575 (procedure->pointer int
576 (lambda (complete message progress-arg)
577 (progress-callback complete
578 (pointer->string message)
580 (list double '* '*))))
582 (define* (make-grioea #:key
584 (resample-alg GRIORA_NEAREST_NEIGHBOUR)
585 (progress-callback '())
586 (progress-data %null-pointer)
587 (is-fp-window-valid #f)
592 (%make-grioea version resample-alg
593 (gdal-progress-func progress-callback)
595 (boolean->c-bool is-fp-window-valid)
596 x-off y-off x-size y-size))
603 set-grioea-resample-alg!
604 grioea-progress-callback
605 set-grioea-progress-callback!
607 set-grioea-progress-data!
608 grioea-is-fp-window-valid
609 set-grioea-is-fp-window-valid!
619 (define (grioea->foreign-pointer record)
622 (list int int '* '* int double double double double)
623 (list (grioea-version record)
624 (grioea-resample-alg record)
625 (grioea-progress-callback record)
626 (grioea-progress-data record)
627 (grioea-is-fp-window-valid record)
628 (grioea-x-off record)
629 (grioea-y-off record)
630 (grioea-x-size record)
631 (grioea-y-size record)))
634 (define (gdal-term-progress complete message arg)
635 "Simple progress report to terminal.
637 This progress reporter prints simple progress report to the terminal window.
638 The progress report generally looks something like this:
640 17.0...33.0...50.0...67.0...83.0...100.0.
642 Use it when you create grioea record via \"make-grioea\" function:
646 (make-grioea #:progress-callback gdal-term-progress)"
647 (let ((perc (round (* complete 100))))
654 (export gdal-term-progress)
656 ;;------------------------------------------------------------------------------
658 ;;; GDAL Function Bindings
660 ;;------------------------------------------------------------------------------
662 (define-gdal-foreign %gdal-all-register
663 void "GDALAllRegister" '() 20)
665 (define (all-register)
666 "Register all known configured GDAL drivers."
667 (%gdal-all-register))
669 (export all-register)
671 ;;------------------------------------------------------------------------------
673 (define-gdal-foreign %cpl-error-reset
674 void "CPLErrorReset" '() 20)
676 (define (reset-error)
677 "Erase any traces of previous errors.
679 This is normally used to ensure that an error which has been recovered from
680 does not appear to be still in play with high level functions."
685 ;;------------------------------------------------------------------------------
687 (define-gdal-foreign %cpl-get-last-error-msg
688 '* "CPLGetLastErrorMsg" '() 20)
690 (define (get-last-error-message)
691 "Get the last error message.
693 Fetches the last error message posted with CPLError(), that hasn't been cleared
695 (let ((ptr (%cpl-get-last-error-msg)))
696 (if (null-pointer? ptr)
698 (pointer->string ptr))))
700 (export get-last-error-message)
702 ;;------------------------------------------------------------------------------
704 (define-gdal-foreign %gdal-data-type-size
705 int "GDALGetDataTypeSize" (list int) 20)
707 (define (get-data-type-size data-type)
708 "Get data type size in bits.
712 Returns the size of a GDT_* type in bits, not bytes!
713 Use get-data-type-size-bytes for bytes. Use get-data-type-size-bits for bits.
716 data-type: type, such as GDT_BYTE."
717 (let ((result (%gdal-data-type-size data-type)))
719 (error "failed to recognize data type")
722 (export get-data-type-size)
724 ;;------------------------------------------------------------------------------
726 (define-gdal-foreign %gdal-data-type-size-bits
727 int "GDALGetDataTypeSizeBits" (list int) 20)
729 (define (get-data-type-size-bits data-type)
730 "Get data type size in bits.
732 Returns the size of a GDT_* type in bits, not bytes!
733 Use get-data-type-size-bytes for bytes.
736 data-type: type, such as GDT_BYTE."
737 (let ((result (%gdal-data-type-size-bits data-type)))
739 (error "failed to recognize data type")
742 (export get-data-type-size-bits)
744 ;;------------------------------------------------------------------------------
746 (define-gdal-foreign %gdal-data-type-size-bytes
747 int "GDALGetDataTypeSizeBytes" (list int) 20)
749 (define (get-data-type-size-bytes data-type)
750 "Get data type size in bytes.
752 Returns the size of a GDT_* type in bytes. In contrast, get-data-type-size and
753 get-data-type-size-bits return the size in bits.
756 data-type: type, such as GDT_BYTE."
757 (let ((result (%gdal-data-type-size-bytes data-type)))
759 (error "failed to recognize data type")
762 (export get-data-type-size-bytes)
764 ;;------------------------------------------------------------------------------
766 (define-gdal-foreign %gdal-data-type-is-complex
767 int "GDALDataTypeIsComplex" (list int) 20)
769 (define (data-type-is-complex? data-type)
770 "Is data type complex?
772 Returns #t if the passed type is complex (one of GDT_CINT16, GDT_CINT32,
773 GDT_CFLOAT32 or GDT_CFLOAT64), that is it consists of a real and imaginary
777 data-type: type, such as GDT_BYTE."
778 (let ((result (%gdal-data-type-is-complex data-type)))
783 (export data-type-is-complex?)
785 ;;------------------------------------------------------------------------------
787 (define-gdal-foreign %gdal-data-type-is-integer
788 int "GDALDataTypeIsInteger" (list int) 23)
790 (define (data-type-is-integer? data-type)
791 "Is data type integer? (might be complex)
793 Returns #t if the passed type is integer (one of GDT_BYTE, GDT_INT16,
794 GDT_UINT16, GDT_INT32, GDT_UINT32, GDT_CINT16 or GDT_CINT32).
797 data-type: type, such as GDT_BYTE."
798 (let ((result (%gdal-data-type-is-integer data-type)))
803 (export data-type-is-integer?)
805 ;;------------------------------------------------------------------------------
807 (define-gdal-foreign %gdal-data-type-is-floating
808 int "GDALDataTypeIsFloating" (list int) 23)
810 (define (data-type-is-floating? data-type)
811 "Is data type floating? (might be complex)
813 Returns #t if the passed type is floating (one of GDT_FLOAT32, GDT_FLOAT64,
814 GDT_CFLOAT32, GDT_CFLOAT64).
817 data-type: type, such as GDT_BYTE."
818 (let ((result (%gdal-data-type-is-floating data-type)))
823 (export data-type-is-floating?)
825 ;;------------------------------------------------------------------------------
827 (define-gdal-foreign %gdal-data-type-is-signed
828 int "GDALDataTypeIsSigned" (list int) 23)
830 (define (data-type-is-signed? data-type)
831 "Is data type signed?
833 Returns #t if the passed type is signed.
836 data-type: type, such as GDT_BYTE."
837 (let ((result (%gdal-data-type-is-signed data-type)))
842 (export data-type-is-signed?)
844 ;;------------------------------------------------------------------------------
846 (define-gdal-foreign %gdal-get-data-type-name
847 '* "GDALGetDataTypeName" (list int) 20)
849 (define (get-data-type-name data-type)
850 "Get name of data type.
852 Returns a symbolic name for the data type. This is essentially the enumerated
853 item name with the GDT_ prefix removed. So GDT_BYTE returns 'Byte'.
856 data-type: type to get name of."
857 (let ((ptr (%gdal-get-data-type-name data-type)))
858 (if (null-pointer? ptr)
859 (error "failed to recognize data type")
860 (pointer->string ptr))))
862 (export get-data-type-name)
864 ;;------------------------------------------------------------------------------
866 (define-gdal-foreign %gdal-get-data-type-by-name
867 int "GDALGetDataTypeByName" (list '*) 20)
869 (define (get-data-type-by-name name)
870 "Get data type by symbolic name.
872 Returns a data type corresponding to the given symbolic name. This function is
873 opposite to the get-data-type-name.
876 name: string containing the symbolic name of the type."
877 (let ((result (%gdal-get-data-type-by-name (string->pointer name))))
879 (error "failed to recognize data type")
882 (export get-data-type-by-name)
884 ;;------------------------------------------------------------------------------
886 (define-gdal-foreign %gdal-data-type-union
887 int "GDALDataTypeUnion" (list int int) 20)
889 (define (data-type-union data-type-1 data-type-2)
890 "Return the smallest data type that can fully express both input data
894 data-type-1: first data type.
895 data-type-2: second data type."
896 (let ((result (%gdal-data-type-union data-type-1 data-type-2)))
898 (error "failed to recognize data type")
901 (export data-type-union)
903 ;;------------------------------------------------------------------------------
905 (define-gdal-foreign %gdal-data-type-union-with-value
906 int "GDALDataTypeUnionWithValue" (list int double int) 23)
908 (define (data-type-union-with-value data-type value is-complex)
909 "Union a data type with the one found for a value.
912 data-type: the first data type
913 value: the value for which to find a data type and union with 'data-type'
914 is-complex: boolean, #t if the value is complex."
915 (let ((result (%gdal-data-type-union-with-value
916 data-type value (boolean->c-bool is-complex))))
918 (error "failed to union data type")
921 (export data-type-union-with-value)
923 ;;------------------------------------------------------------------------------
925 (define-gdal-foreign %gdal-find-data-type
926 int "GDALFindDataType" (list int int int int) 23)
928 (define (find-data-type n-bits is-signed is-floating is-complex)
929 "Finds the smallest data type able to support the given requirements.
932 n-bits: number of bits necessary
933 is-signed: if negative values are necessary
934 is-floating: if non-integer values necessary
935 is-complex: if complex values are necessary."
936 (let ((result (%gdal-find-data-type n-bits (boolean->c-bool is-signed)
937 (boolean->c-bool is-floating) (boolean->c-bool is-complex))))
939 (error "failed to find data type")
942 (export find-data-type)
944 ;;------------------------------------------------------------------------------
946 (define-gdal-foreign %gdal-find-data-type-for-value
947 int "GDALFindDataTypeForValue" (list double int) 23)
949 (define (find-data-type-for-value value is-complex)
950 "Finds the smallest data type able to support the provided value.
953 value: double value to support
954 is-complex: is the value complex."
955 (let ((result (%gdal-find-data-type-for-value value
956 (boolean->c-bool is-complex))))
958 (error "failed to find data type")
961 (export find-data-type-for-value)
963 ;;------------------------------------------------------------------------------
965 (define-gdal-foreign %gdal-adjust-data-type-to-value
966 double "GDALAdjustValueToDataType" (list int double '* '*) 20)
968 (define (adjust-data-type-to-value data-type value)
969 "Adjust a value to the output data type.
971 Adjustment consist in clamping to minimum/maxmimum values of the data type and
972 rounding for integral types.
974 Returns multiple (3) values as adjusted double value,
975 boolean value to indicate if clamping has been made, and boolean value to
976 indicate if rounding has been made.
979 data-type: target data type
980 value: double value to adjust."
981 (let* ((p-clamped (make-bytevector (sizeof int)))
982 (p-rounded (make-bytevector (sizeof int)))
983 (result (%gdal-adjust-data-type-to-value
986 (bytevector->pointer p-clamped)
987 (bytevector->pointer p-rounded))))
990 (c-bool->boolean (bytevector-sint-ref p-clamped
994 (c-bool->boolean (bytevector-sint-ref p-rounded
999 (export adjust-data-type-to-value)
1001 ;;------------------------------------------------------------------------------
1003 (define-gdal-foreign %gdal-get-non-complex-data-type
1004 int "GDALGetNonComplexDataType" (list int) 23)
1006 (define (get-non-complex-data-type data-type)
1007 "Return the base data type for the specified input.
1009 If the input data type is complex this function returns the base type i.e.
1010 the data type of the real and imaginary parts (non-complex). If the input data
1011 type is already non-complex, then it is returned unchanged.
1014 data-type: type, such as GDT_CFLOAT32."
1015 (if (data-type-valid? data-type)
1016 (%gdal-get-non-complex-data-type data-type)
1017 (error "data-type is out of bounds")))
1019 (export get-non-complex-data-type)
1021 ;;------------------------------------------------------------------------------
1023 (define-gdal-foreign %gdal-data-type-is-conversion-lossy
1024 int "GDALDataTypeIsConversionLossy" (list int int) 23)
1026 (define (data-type-is-conversion-lossy? data-type-from data-type-to)
1027 "Is conversion from data-type-from to data-type-to potentially lossy.
1030 data-type-from: input datatype
1031 data-type-to: output datatype."
1032 (if (and (data-type-valid? data-type-from) (data-type-valid? data-type-to))
1033 (c-bool->boolean (%gdal-data-type-is-conversion-lossy
1036 (error "data-type is out of bounds")))
1038 (export data-type-is-conversion-lossy?)
1040 ;;------------------------------------------------------------------------------
1042 (define-gdal-foreign %gdal-get-async-status-type-name
1043 '* "GDALGetAsyncStatusTypeName" (list int) 20)
1045 (define (get-async-status-type-name async-status-type)
1046 "Get name of AsyncStatus data type.
1048 Returns a symbolic name for the AsyncStatus data type. This is essentially the
1049 the enumerated item name with the GARIO_ prefix removed. So GARIO_COMPLETE
1053 async-status-type: type to get name of."
1054 (let ((ptr (%gdal-get-async-status-type-name async-status-type)))
1055 (if (null-pointer? ptr)
1056 (error "failed to recognize async status type")
1057 (pointer->string ptr))))
1059 (export get-async-status-type-name)
1061 ;;------------------------------------------------------------------------------
1063 (define-gdal-foreign %gdal-get-async-status-type-by-name
1064 int "GDALGetAsyncStatusTypeByName" (list '*) 20)
1066 (define (get-async-status-type-by-name name)
1067 "Get AsyncStatusType by symbolic name.
1069 Returns a data type corresponding to the given symbolic name. This function is
1070 opposite to the get-async-status-type-name.
1073 name: string containing the symbolic name of the type."
1074 (let ((result (%gdal-get-async-status-type-by-name (string->pointer name))))
1075 (if (= GARIO_ERROR result)
1076 (error "failed to recognize async status type")
1079 (export get-async-status-type-by-name)
1081 ;;------------------------------------------------------------------------------
1083 (define-gdal-foreign %gdal-get-color-interpretation-name
1084 '* "GDALGetColorInterpretationName" (list int) 20)
1086 (define (get-color-interpretation-name color-interpretation-type)
1087 "Get name of color interpretation.
1089 Returns a symbolic name for the color interpretation. This is derived from the
1090 enumerated item name with the GCI_ prefix removed, but there are some
1091 variations. So GCI_GRAY_INDEX returns 'Gray' and GCI_RED_BAND returns 'Red'.
1094 color-interpretation-type: color interpretation to get name of."
1095 (let ((ptr (%gdal-get-color-interpretation-name
1096 color-interpretation-type)))
1097 (if (null-pointer? ptr)
1098 (error "failed to recognize color interpretation type")
1099 (pointer->string ptr))))
1101 (export get-color-interpretation-name)
1103 ;;------------------------------------------------------------------------------
1105 (define-gdal-foreign %gdal-get-color-interpretation-by-name
1106 int "GDALGetColorInterpretationByName" (list '*) 20)
1108 (define (get-color-interpretation-by-name name)
1109 "Get color interpretation by symbolic name.
1111 Returns a color interpretation corresponding to the given symbolic name. This
1112 function is opposite to the get-color-interpretation-name.
1115 name: string containing the symbolic name of the color interpretation."
1116 (let ((result (%gdal-get-color-interpretation-by-name
1117 (string->pointer name))))
1118 (if (= GCI_UNDEFINED result)
1119 (error "failed to recognize color interpretation type")
1122 (export get-color-interpretation-by-name)
1124 ;;------------------------------------------------------------------------------
1126 (define-gdal-foreign %gdal-get-palette-interpretation-name
1127 '* "GDALGetPaletteInterpretationName" (list int) 20)
1129 (define (get-palette-interpretation-name palette-interpretation-type)
1130 "Get name of palette interpretation.
1132 Returns a symbolic name for the palette interpretation. This is the the
1133 enumerated item name with the GPI_ prefix removed. So GPI_Gray returns 'Gray'.
1136 palette-interpretation-type: palette interpretation to get name of."
1137 (let ((ptr (%gdal-get-palette-interpretation-name
1138 palette-interpretation-type)))
1139 (if (null-pointer? ptr)
1140 (error "failed to recognize palette interpretation type")
1141 (pointer->string ptr))))
1143 (export get-palette-interpretation-name)
1145 ;;------------------------------------------------------------------------------
1147 (define-gdal-foreign %gdal-create
1148 '* "GDALCreate" (list '* '* int int int int '*) 20)
1150 (define (create-dataset driver file-name x-size y-size n-bands band-type)
1151 "Create a new dataset with this driver.
1155 file-name: the name of the dataset to create
1156 x-size: width of created raster in pixels
1157 y-size: height of created raster in pixels
1158 n-bands: number of bands
1159 band-type: type of raster."
1160 (let ((ptr (%gdal-create driver
1161 (string->pointer file-name)
1167 (if (null-pointer? ptr)
1168 (error "failed to create GDAL dataset")
1171 (export create-dataset)
1173 ;;------------------------------------------------------------------------------
1175 (define-gdal-foreign %gdal-create-copy
1176 '* "GDALCreateCopy" (list '* '* '* int '* '* '*) 20)
1178 (define (copy-dataset driver file-name source-dataset is-strict)
1179 "Create a copy of a dataset.
1183 file-name: the name for the new dataset
1184 source-dataset: the dataset being duplicated.
1185 is-strict: #t if the copy must be strictly equivalent, or more normally
1186 #f indicating that the copy may adapt as needed for the output format."
1187 (let ((ptr (%gdal-create-copy driver
1188 (string->pointer file-name)
1190 (boolean->c-bool is-strict)
1194 (if (null-pointer? ptr)
1195 (error "failed to create GDAL dataset")
1198 (export copy-dataset)
1200 ;;------------------------------------------------------------------------------
1202 (define-gdal-foreign %gdal-identify-driver
1203 '* "GDALIdentifyDriver" (list '* '*) 20)
1205 (define (identify-driver file-name)
1206 "Identify the driver that can open a raster file.
1209 file-name: the name of the file to access. In the case of exotic drivers
1210 this may not refer to a physical file, but instead contain information for the
1211 driver on how to access a dataset."
1212 (let ((ptr (%gdal-identify-driver
1213 (string->pointer file-name)
1215 (if (null-pointer? ptr)
1216 (error "failed to identify driver")
1219 (export identify-driver)
1221 ;;------------------------------------------------------------------------------
1223 (define-gdal-foreign %gdal-open
1224 '* "GDALOpen" (list '* int) 20)
1226 (define (open-dataset file-name access)
1227 "Open a raster file as a GDALDataset pointer.
1230 file-name: the name of the file to access. In the case of exotic drivers
1231 this may not refer to a physical file, but instead contain information for the
1232 driver on how to access a dataset.
1233 access: the desired access, either GA_UPDATE or GA_READONLY. Many drivers
1234 support only read only access."
1235 (let ((ptr (%gdal-open
1236 (string->pointer file-name)
1238 (if (null-pointer? ptr)
1239 (error "failed to open dataset")
1242 (export open-dataset)
1244 ;;------------------------------------------------------------------------------
1246 (define-gdal-foreign %gdal-open-ex
1247 '* "GDALOpenEx" (list '* int '* '* '*) 20)
1249 (define* (open-dataset-ex file-name flags #:key
1250 (allowed-drivers '())
1252 (sibling-files '()))
1253 "Open a raster or vector file as a GDALDataset.
1256 file-name: the name of the file to access. In the case of exotic drivers
1257 this may not refer to a physical file, but instead contain information for the
1258 driver on how to access a dataset.
1259 flags: a combination of GDAL_OF_ flags that may be combined through
1260 logical or operator.
1261 allowed-drivers (optional): empty list '() to consider all candidate
1262 drivers, or a list of strings with the driver short names that must be
1264 open-options (optional): empty list '(), or a list of strings with open
1265 options passed to candidate drivers.
1266 sibling-files (optional): empty list '() or a list of strings that are
1267 filenames that are auxiliary to the main filename."
1268 (let ((ptr (%gdal-open-ex
1269 (string->pointer file-name)
1271 (string-list->pointerpointer allowed-drivers)
1272 (string-list->pointerpointer open-options)
1273 (string-list->pointerpointer sibling-files))))
1274 (if (null-pointer? ptr)
1275 (error "failed to open dataset")
1278 (export open-dataset-ex)
1280 ;;------------------------------------------------------------------------------
1282 (define-gdal-foreign %gdal-open-shared
1283 '* "GDALOpenShared" (list '* int) 20)
1285 (define (open-shared-dataset file-name access)
1286 "Open a raster file as a GDALDataset pointer.
1289 file-name: the name of the file to access. In the case of exotic drivers
1290 this may not refer to a physical file, but instead contain information for the
1291 driver on how to access a dataset.
1292 access: the desired access, either GA_UPDATE or GA_READONLY. Many drivers
1293 support only read only access."
1294 (let ((ptr (%gdal-open-shared
1295 (string->pointer file-name)
1297 (if (null-pointer? ptr)
1298 (error "failed to open dataset")
1301 (export open-shared-dataset)
1303 ;;------------------------------------------------------------------------------
1305 (define-gdal-foreign %gdal-get-driver-by-name
1306 '* "GDALGetDriverByName" (list '*) 20)
1308 (define (get-driver-by-name driver-short-name)
1309 "Fetch a driver based on the short name.
1312 driver-short-name: the short name of the driver, such as 'GTiff' as a
1313 string or GDN_GTIFF as an enum (see GDN_*), being searched for."
1314 (let ((ptr (%gdal-get-driver-by-name
1315 (string->pointer driver-short-name))))
1316 (if (null-pointer? ptr)
1317 (error "failed to find driver")
1320 (export get-driver-by-name)
1322 ;;------------------------------------------------------------------------------
1324 (define-gdal-foreign %gdal-get-driver-count
1325 int "GDALGetDriverCount" '() 20)
1327 (define (get-driver-count)
1328 "Fetch the number of registered drivers."
1329 (%gdal-get-driver-count))
1331 (export get-driver-count)
1333 ;;------------------------------------------------------------------------------
1335 (define-gdal-foreign %gdal-get-driver
1336 '* "GDALGetDriver" (list int) 20)
1338 (define (get-driver driver-index)
1339 "Fetch driver by index.
1342 driver-index: the driver index from 0 to (1- (get-driver-count))."
1343 (let ((ptr (%gdal-get-driver driver-index)))
1344 (if (null-pointer? ptr)
1345 (error "failed to find driver")
1350 ;;------------------------------------------------------------------------------
1352 (define-gdal-foreign %gdal-destroy-driver
1353 void "GDALDestroyDriver" (list '*) 20)
1355 (define (destroy-driver driver)
1356 "Destroy a GDALDriver.
1359 driver: the driver to destroy"
1360 (%gdal-destroy-driver driver))
1362 (export destroy-driver)
1364 ;;------------------------------------------------------------------------------
1366 (define-gdal-foreign %gdal-delete-dataset
1367 int "GDALDeleteDataset" (list '* '*) 20)
1369 (define (delete-dataset driver file-name)
1370 "Delete named dataset.
1373 driver: the driver to use for deleting file-name
1374 file-name: name of dataset to delete."
1375 (let ((result (%gdal-delete-dataset driver (string->pointer file-name))))
1376 (unless (= result CE_NONE)
1377 (error "failed to delete dataset"))))
1379 (export delete-dataset)
1381 ;;------------------------------------------------------------------------------
1383 (define-gdal-foreign %gdal-rename-dataset
1384 int "GDALRenameDataset" (list '* '* '*) 20)
1386 (define (rename-dataset driver new-file-name old-file-name)
1390 driver: the driver to use for deleting file-name
1391 new-file-name: new name for the dataset
1392 old-file-name: old name for the dataset."
1393 (let ((result (%gdal-rename-dataset
1395 (string->pointer new-file-name)
1396 (string->pointer old-file-name))))
1397 (unless (= result CE_NONE)
1398 (error "failed to rename dataset"))))
1400 (export rename-dataset)
1402 ;;------------------------------------------------------------------------------
1404 (define-gdal-foreign %gdal-copy-dataset-files
1405 int "GDALCopyDatasetFiles" (list '* '* '*) 20)
1407 (define (copy-dataset-files driver new-file-name old-file-name)
1408 "Copy all the files associated with a dataset.
1411 driver: the driver to use for deleting file-name
1412 new-file-name: new name for the dataset
1413 old-file-name: old name for the dataset."
1414 (let ((result (%gdal-copy-dataset-files
1416 (string->pointer new-file-name)
1417 (string->pointer old-file-name))))
1418 (unless (= result CE_NONE)
1419 (error "failed to copy dataset files"))))
1421 (export copy-dataset-files)
1423 ;;------------------------------------------------------------------------------
1425 (define-gdal-foreign %gdal-gcps-to-geo-transform
1426 int "GDALGCPsToGeoTransform" (list int '* '* int) 20)
1428 (define (gcps-to-geo-transform gcp-lst is-approx-ok)
1429 "Generate Geotransform from GCPs.
1432 gcp-list: list of GCPs
1433 is-approx-ok: If #f the function will fail if the geotransform is not
1434 essentially an exact fit (within 0.25 pixel) for all GCPs."
1435 (cond ((not (pair? gcp-lst))
1436 (error "input is not a list or empty"))
1437 ((not (= (count gcp? gcp-lst) (length gcp-lst)))
1438 (error "input list has at least one non-gcp record"))
1439 (else (let* ((bv-gcps (make-bytevector (* 6 (sizeof double))))
1440 (result (%gdal-gcps-to-geo-transform
1442 (gcp-list->pointer gcp-lst)
1443 (bytevector->pointer bv-gcps)
1444 (boolean->c-bool is-approx-ok))))
1445 (if (c-bool->boolean result)
1446 (let ((ne (native-endianness))
1450 ((> i coef-max-index))
1452 (bytevector-ieee-double-ref bv-gcps
1453 (* i (sizeof double)) ne)))
1457 (export gcps-to-geo-transform)
1459 ;;------------------------------------------------------------------------------
1461 (define-gdal-foreign %gdal-inv-geo-transform
1462 int "GDALInvGeoTransform" (list '* '*) 20)
1464 (define (inv-geo-transform gt-lst)
1465 "Invert Geotransform.
1468 gt-lst: list of input geotransform (six doubles)."
1469 (cond ((not (pair? gt-lst))
1470 (error "input is not a list or empty"))
1471 ((not (= 6 (length gt-lst)))
1472 (error "insufficient number of coefficients in the list (6 doubles)"))
1473 (else (let* ((bv-gp-out (make-bytevector (* 6 (sizeof double))))
1475 (result (%gdal-inv-geo-transform
1476 (list->pointer gt-lst double)
1477 (bytevector->pointer bv-gp-out))))
1478 (if (c-bool->boolean result)
1479 (let ((coefs-q (make-q)))
1481 ((> i coef-max-index))
1482 (enq! coefs-q (bytevector-ieee-double-native-ref
1484 (* i (sizeof double)))))
1488 (export inv-geo-transform)
1490 ;;------------------------------------------------------------------------------
1492 (define-gdal-foreign %gdal-apply-geo-transform
1493 int "GDALApplyGeoTransform" (list '* double double '* '*) 20)
1495 (define (apply-geo-transform gt-lst pixel line)
1496 "Apply GeoTransform to x/y coordinate.
1499 gt-lst: list of input geotransform (six doubles)
1500 pixel: input pixel location
1501 line: input line location."
1503 (cond ((not (pair? gt-lst))
1504 (error "input is not a list or empty"))
1505 ((not (= 6 (length gt-lst)))
1506 (error "insufficient number of coefficients in the list (6 doubles)"))
1507 (else (let ((bv-geo-x (make-bytevector (sizeof double)))
1508 (bv-geo-y (make-bytevector (sizeof double))))
1509 (%gdal-apply-geo-transform
1510 (list->pointer gt-lst double)
1513 (bytevector->pointer bv-geo-x)
1514 (bytevector->pointer bv-geo-y))
1515 `(,(bytevector-ieee-double-native-ref bv-geo-x 0)
1517 ,(bytevector-ieee-double-native-ref bv-geo-y 0))))))
1519 (export apply-geo-transform)
1521 ;;------------------------------------------------------------------------------
1523 (define-gdal-foreign %gdal-compose-geo-transforms
1524 void "GDALComposeGeoTransforms" (list '* '* '*) 20)
1526 (define (compose-geo-transforms gt1-lst gt2-lst)
1527 "Compose two geotransforms.
1530 gt1-lst: list of first geotransform (six doubles)
1531 gt2-lst: list of first geotransform (six doubles)"
1532 (cond ((not (pair? gt1-lst))
1533 (error "input gt1-lst is not a list or empty"))
1534 ((not (pair? gt2-lst))
1535 (error "input gt2-lst is not a list or empty"))
1536 ((not (= 6 (length gt1-lst)))
1537 (error "insufficient number of coefficients in the list gt1-lst"))
1538 ((not (= 6 (length gt2-lst)))
1539 (error "insufficient number of coefficients in the list gt2-lst"))
1540 (else (let ((bv-gt-out (make-bytevector (* 6 (sizeof double)))))
1541 (%gdal-compose-geo-transforms
1542 (list->pointer gt1-lst double)
1543 (list->pointer gt2-lst double)
1544 (bytevector->pointer bv-gt-out))
1545 (let ((coefs-q (make-q)))
1548 (enq! coefs-q (bytevector-ieee-double-native-ref
1550 (* i (sizeof double)))))
1553 (export compose-geo-transforms)
1555 ;;------------------------------------------------------------------------------
1557 (define-gdal-foreign %gdal-get-metadata-domain-list
1558 '* "GDALGetMetadataDomainList" (list '*) 20)
1560 (define (get-metadata-domain-list h-object)
1561 "Fetch list of metadata domains.
1563 Returns a string list of metadata domains.
1566 h-object: a handle representing various GDAL objects.
1567 See https://www.gdal.org/classGDALMajorObject.html for more information."
1568 (pointerpointer->string-list
1569 (%gdal-get-metadata-domain-list h-object)))
1571 (export get-metadata-domain-list)
1573 ;;------------------------------------------------------------------------------
1575 (define-gdal-foreign %gdal-get-metadata
1576 '* "GDALGetMetadata" (list '* '*) 20)
1578 (define (get-metadata h-object domain)
1579 "Return a string list of metadata which is owned by the object, and may
1580 change at any time. It is formatted as a \"Name=value\" list.
1583 h-object: a handle representing various GDAL objects.
1584 See https://www.gdal.org/classGDALMajorObject.html for more information
1585 domain: the domain of interest. Use empty string \"\" for the default
1587 (pointerpointer->string-list
1588 (%gdal-get-metadata h-object (string->pointer domain))))
1590 (export get-metadata)
1592 ;;------------------------------------------------------------------------------
1594 (define-gdal-foreign %gdal-set-metadata
1595 int "GDALSetMetadata" (list '* '* '*) 20)
1597 (define (set-metadata h-object metadata domain)
1598 "Sets a string list of a metadata where each member is formatted as
1602 h-object: a handle representing various GDAL objects.
1603 See https://www.gdal.org/classGDALMajorObject.html for more information
1604 metadata: the metadata in name=value string list format to apply.
1605 domain: the domain of interest. Use empty string \"\" for the default
1607 (let ((result (%gdal-set-metadata
1609 (string-list->pointerpointer metadata)
1610 (string->pointer domain))))
1611 (unless (= result CE_NONE)
1612 (error "failed to set metadata"))))
1614 (export set-metadata)
1616 ;;------------------------------------------------------------------------------
1618 (define-gdal-foreign %gdal-close
1619 void "GDALClose" (list '*) 20)
1621 (define (close-dataset h-ds)
1622 "Close GDAL dataset.
1625 h-ds: the dataset to close."
1628 (export close-dataset)
1630 ;;------------------------------------------------------------------------------
1632 (define-gdal-foreign %gdal-get-metadata-item
1633 '* "GDALGetMetadataItem" (list '* '* '*) 20)
1635 (define (get-metadata-item h-object name domain)
1636 "Fetch single metadata item.
1639 h-object: a handle representing various GDAL objects
1640 name: the key for the metadata item to fetch
1641 domain: the domain to fetch for, use \"\" for the default domain."
1642 (let ((ptr (%gdal-get-metadata-item
1644 (string->pointer name)
1645 (string->pointer domain))))
1646 (if (null-pointer? ptr)
1648 (pointer->string ptr))))
1650 (export get-metadata-item)
1652 ;;------------------------------------------------------------------------------
1654 (define-gdal-foreign %gdal-set-metadata-item
1655 int "GDALSetMetadataItem" (list '* '* '* '*) 20)
1657 (define (set-metadata-item h-object name value domain)
1658 "Sets a single metadata item which is formatted as \"Name=value\".
1661 h-object: a handle representing various GDAL objects.
1662 See https://www.gdal.org/classGDALMajorObject.html for more information
1663 name: the key for the metadata item to fetch.
1664 value: the value to assign to the key.
1665 domain: the domain to set within, use \"\" for the default domain."
1666 (let ((result (%gdal-set-metadata-item
1668 (string->pointer name)
1669 (string->pointer value)
1670 (string->pointer domain))))
1671 (unless (= result CE_NONE)
1672 (error "failed to set metadata item"))))
1674 (export set-metadata-item)
1676 ;;------------------------------------------------------------------------------
1678 (define-gdal-foreign %gdal-get-description
1679 '* "GDALGetDescription" (list '*) 20)
1681 (define (get-description h-object)
1682 "Fetch object description.
1685 h-object: a handle representing various GDAL objects.
1686 See https://www.gdal.org/classGDALMajorObject.html for more information."
1687 (pointer->string (%gdal-get-description h-object)))
1689 (export get-description)
1691 ;;------------------------------------------------------------------------------
1693 (define-gdal-foreign %gdal-set-description
1694 void "GDALSetDescription" (list '* '*) 20)
1696 (define (set-description h-object description)
1697 "Set object description.
1700 h-object: a handle representing various GDAL objects.
1701 See https://www.gdal.org/classGDALMajorObject.html for more information.
1702 description: new description."
1703 (%gdal-set-description h-object (string->pointer description)))
1705 (export set-description)
1707 ;;------------------------------------------------------------------------------
1709 (define-gdal-foreign %gdal-get-dataset-driver
1710 '* "GDALGetDatasetDriver" (list '*) 20)
1712 (define (get-dataset-driver h-dataset)
1713 "Fetch the driver to which this dataset relates.
1716 h-dataset: a handle representing GDALDataset."
1717 (%gdal-get-dataset-driver h-dataset))
1719 (export get-dataset-driver)
1721 ;;------------------------------------------------------------------------------
1723 (define-gdal-foreign %gdal-get-file-list
1724 '* "GDALGetFileList" (list '*) 20)
1726 (define (get-file-list h-dataset)
1727 "Fetch files forming dataset.
1730 h-dataset: a handle representing GDALDataset."
1731 (pointerpointer->string-list (%gdal-get-file-list h-dataset)))
1733 (export get-file-list)
1735 ;;------------------------------------------------------------------------------
1737 (define-gdal-foreign %gdal-get-raster-x-size
1738 int "GDALGetRasterXSize" (list '*) 20)
1740 (define (get-raster-x-size h-dataset)
1741 "Fetch raster width in pixels.
1744 h-dataset: a handle representing GDALDataset."
1745 (%gdal-get-raster-x-size h-dataset))
1747 (export get-raster-x-size)
1749 ;;------------------------------------------------------------------------------
1751 (define-gdal-foreign %gdal-get-raster-y-size
1752 int "GDALGetRasterYSize" (list '*) 20)
1754 (define (get-raster-y-size h-dataset)
1755 "Fetch raster height in pixels.
1758 h-dataset: a handle representing GDALDataset."
1759 (%gdal-get-raster-y-size h-dataset))
1761 (export get-raster-y-size)
1763 ;;------------------------------------------------------------------------------
1765 (define-gdal-foreign %gdal-get-raster-band-x-size
1766 int "GDALGetRasterBandXSize" (list '*) 20)
1768 (define (get-raster-band-x-size h-band)
1769 "Fetch raster width in pixels for the band.
1772 h-band: a handle representing GDALRasterBandH."
1773 (%gdal-get-raster-band-x-size h-band))
1775 (export get-raster-band-x-size)
1777 ;;------------------------------------------------------------------------------
1779 (define-gdal-foreign %gdal-get-raster-band-y-size
1780 int "GDALGetRasterBandYSize" (list '*) 20)
1782 (define (get-raster-band-y-size h-band)
1783 "Fetch raster height in pixels for the band.
1786 h-band: a handle representing GDALRasterBandH."
1787 (%gdal-get-raster-band-y-size h-band))
1789 (export get-raster-band-y-size)
1791 ;;------------------------------------------------------------------------------
1793 (define-gdal-foreign %gdal-get-raster-count
1794 int "GDALGetRasterCount" (list '*) 20)
1796 (define (get-raster-count h-dataset)
1797 "Fetch the number of raster bands on this dataset.
1800 h-dataset: a handle representing GDALDataset."
1801 (%gdal-get-raster-count h-dataset))
1803 (export get-raster-count)
1805 ;;------------------------------------------------------------------------------
1807 (define-gdal-foreign %gdal-get-raster-band
1808 '* "GDALGetRasterBand" (list '* int) 20)
1810 (define (get-raster-band h-dataset band-id)
1811 "Fetch a band object for a dataset.
1814 h-dataset: a handle representing GDALDataset.
1815 band-id: the index number of the band to fetch, from 1 to get-raster-count."
1816 (%gdal-get-raster-band h-dataset band-id))
1818 (export get-raster-band)
1820 ;;------------------------------------------------------------------------------
1822 (define-gdal-foreign %gdal-add-band
1823 int "GDALAddBand" (list '* int '*) 20)
1825 (define (add-band h-dataset type options)
1826 "Add a band to a dataset.
1829 h-dataset: a handle representing GDALDataset.
1830 type: the data type of the pixels in the new band.
1831 options: the list of NAME=VALUE option strings. The supported options are
1832 format specific. Empty list '() may be passed by default."
1833 (let ((result (%gdal-add-band h-dataset
1835 (string-list->pointerpointer
1837 (unless (= result CE_NONE)
1838 (error "failed to add band"))))
1842 ;;------------------------------------------------------------------------------
1844 (define-gdal-foreign %gdal-raster-io
1845 int "GDALRasterIO" (list '* int int int int int '*
1846 int int int int int) 20)
1848 (define (raster-io h-band rw-flag x-off y-off x-size y-size data
1849 buf-x-size buf-y-size buf-type pixel-space line-space)
1850 "Read/write a region of image data for this band.
1853 h-band: a handle representing GDALRasterBandH.
1854 rw-flag: either GF_READ to read, or GF_WRITE to write a region of data.
1855 x-off: the pixel offset to the top left corner of the region of the band.
1856 y-off: the line offset to the top left corner of the region of the band.
1857 x-size: the width of the region of the band.
1858 y-size: the height of the region of the band.
1859 data: the bytevector buffer into which the data should be read, or from
1860 which it should be written. This buffer must contain at least
1861 (* buf-x-size buf-y-size) words of type buf-type. It is organized in left to
1862 right, top to bottom pixel order. Spacing is controlled by the pixel-space, and
1863 line-space parameters.
1864 buf-x-size: the width of the buffer image into which the desired region is
1865 to be read, or from which it is to be written.
1866 buf-y-size: the height of the buffer image into which the desired region is
1867 to be read, or from which it is to be written.
1868 buf-type: the type of the pixel values to be returned. The pixel values
1869 will automatically be translated to/from the GDALRasterBand data type as needed.
1870 pixel-space: the byte offset from the start of one pixel value in data to
1871 the start of the next pixel value within a scanline. If defaulted (0) the size
1872 of the datatype buf-type is used.
1873 line-space: the byte offset from the start of one scanline in pData to the
1874 start of the next. If defaulted (0) the size of the datatype
1875 (* buf-type buf-x-size) is used."
1876 (let ((result (%gdal-raster-io h-band rw-flag x-off y-off x-size y-size
1877 (bytevector->pointer data)
1878 buf-x-size buf-y-size buf-type
1879 pixel-space line-space)))
1880 (unless (= result CE_NONE)
1881 (error "failed to read/write data for this band"))))
1885 ;;------------------------------------------------------------------------------
1887 (define-gdal-foreign %gdal-dataset-raster-io-ex
1888 int "GDALDatasetRasterIOEx" (list '* int int int int int '*
1889 int int int int '* int64 int64
1892 (define (dataset-raster-io-ex h-dataset rw-flag x-off y-off x-size y-size data
1893 buf-x-size buf-y-size buf-type band-count
1894 band-map pixel-space line-space band-space
1896 "Read/write a region of image data for multiple bands.
1899 h-dataset: a handle representing GDALDatasetH.
1900 rw-flag: either GF_READ to read, or GF_WRITE to write a region of data.
1901 x-off: the pixel offset to the top left corner of the region of the band.
1902 y-off: the line offset to the top left corner of the region of the band.
1903 x-size: the width of the region of the band.
1904 y-size: the height of the region of the band.
1905 data: the bytevector buffer into which the data should be read, or from
1906 which it should be written. This buffer must contain at least
1907 (* buf-x-size buf-y-size band-count) words of type buf-type. It is organized
1908 in left to right, top to bottom pixel order. Spacing is controlled by the
1909 pixel-space, and line-space parameters.
1910 buf-x-size: the width of the buffer image into which the desired region is
1911 to be read, or from which it is to be written.
1912 buf-y-size: the height of the buffer image into which the desired region is
1913 to be read, or from which it is to be written.
1914 buf-type: the type of the pixel values to be returned. The pixel values
1915 will automatically be translated to/from the GDALRasterBand data type as needed.
1916 band-count: the number of bands being read or written.
1917 band-map: the list of band-count numbers being read/written. Note band
1918 numbers are 1 based. This may be empty list '() to select the first band-count
1920 pixel-space: the byte offset from the start of one pixel value in data to
1921 the start of the next pixel value within a scanline. If defaulted (0) the size
1922 of the datatype buf-type is used.
1923 line-space: the byte offset from the start of one scanline in pData to the
1924 start of the next. If defaulted (0) the size of the datatype
1925 (* buf-type buf-x-size) is used.
1926 band-space: the byte offset from the start of one bands data to the start
1927 of the next. If defaulted (0) the value will be (* line-space buf-y-size)
1928 implying band sequential organization of the data buffer.
1929 extra-arg: (new in GDAL 2.0) pointer to a GDALRasterIOExtraArg structure
1930 constructed with \"make-grioea\" function which creates grioea record
1931 with additional arguments to specify resampling and progress callback, or
1932 #f for default behaviour. The GDAL_RASTERIO_RESAMPLING configuration option can
1933 also be defined to override the default resampling to one of BILINEAR, CUBIC,
1934 CUBICSPLINE, LANCZOS, AVERAGE or MODE."
1935 (let ((result (%gdal-dataset-raster-io-ex h-dataset rw-flag x-off y-off x-size
1936 y-size (bytevector->pointer data)
1937 buf-x-size buf-y-size buf-type
1939 (list->pointer band-map int)
1940 pixel-space line-space band-space
1941 (grioea->foreign-pointer extra-arg))
1943 (unless (= result CE_NONE)
1944 (error "failed to read/write data for this band"))))
1946 (export dataset-raster-io-ex)
1948 ;;------------------------------------------------------------------------------
1950 (define-gdal-foreign %gdal-dataset-raster-io
1951 int "GDALDatasetRasterIO" (list '* int int int int int '*
1952 int int int int '* int int int) 20)
1954 (define (dataset-raster-io h-dataset rw-flag x-off y-off x-size y-size data
1955 buf-x-size buf-y-size buf-type band-count
1956 band-map pixel-space line-space band-space)
1957 "Read/write a region of image data for multiple bands. Use
1958 dataset-raster-io-ex if 64 bit spacings or extra arguments (resampling
1959 resolution, progress callback, etc. are needed).
1962 h-dataset: a handle representing GDALDatasetH.
1963 rw-flag: either GF_READ to read, or GF_WRITE to write a region of data.
1964 x-off: the pixel offset to the top left corner of the region of the band.
1965 y-off: the line offset to the top left corner of the region of the band.
1966 x-size: the width of the region of the band.
1967 y-size: the height of the region of the band.
1968 data: the bytevector buffer into which the data should be read, or from
1969 which it should be written. This buffer must contain at least
1970 (* buf-x-size buf-y-size band-count) words of type buf-type. It is organized
1971 in left to right, top to bottom pixel order. Spacing is controlled by the
1972 pixel-space, and line-space parameters.
1973 buf-x-size: the width of the buffer image into which the desired region is
1974 to be read, or from which it is to be written.
1975 buf-y-size: the height of the buffer image into which the desired region is
1976 to be read, or from which it is to be written.
1977 buf-type: the type of the pixel values to be returned. The pixel values
1978 will automatically be translated to/from the GDALRasterBand data type as needed.
1979 band-count: the number of bands being read or written.
1980 band-map: the list of band-count numbers being read/written. Note band
1981 numbers are 1 based. This may be empty list '() to select the first band-count
1983 pixel-space: the byte offset from the start of one pixel value in data to
1984 the start of the next pixel value within a scanline. If defaulted (0) the size
1985 of the datatype buf-type is used.
1986 line-space: the byte offset from the start of one scanline in pData to the
1987 start of the next. If defaulted (0) the size of the datatype
1988 (* buf-type buf-x-size) is used.
1989 band-space: the byte offset from the start of one bands data to the start
1990 of the next. If defaulted (0) the value will be (* line-space buf-y-size)
1991 implying band sequential organization of the data buffer."
1992 (let ((result (%gdal-dataset-raster-io h-dataset rw-flag x-off y-off x-size
1993 y-size (bytevector->pointer data)
1994 buf-x-size buf-y-size buf-type
1996 (list->pointer band-map int)
1997 pixel-space line-space band-space)))
1998 (unless (= result CE_NONE)
1999 (error "failed to read/write data for this band"))))
2001 (export dataset-raster-io)
2003 ;;------------------------------------------------------------------------------
2005 (define-gdal-foreign %gdal-begin-async-reader
2006 '* "GDALBeginAsyncReader" (list '* int int int int '* int int
2007 int int '* int int int '*) 20)
2009 (define (begin-async-reader h-dataset x-off y-off x-size y-size data
2010 buf-x-size buf-y-size buf-type band-count
2011 band-map pixel-space line-space band-space
2013 "Set up an asynchronous data request and return handle representing the
2017 h-dataset: a handle representing GDALDatasetH.
2018 x-off: the pixel offset to the top left corner of the region of the band.
2019 y-off: the line offset to the top left corner of the region of the band.
2020 x-size: the width of the region of the band.
2021 y-size: the height of the region of the band.
2022 data: the bytevector buffer into which the data should be read, or from
2023 which it should be written. This buffer must contain at least
2024 (* buf-x-size buf-y-size band-count) words of type buf-type. It is organized
2025 in left to right, top to bottom pixel order. Spacing is controlled by the
2026 pixel-space, and line-space parameters.
2027 buf-x-size: the width of the buffer image into which the desired region is
2028 to be read, or from which it is to be written.
2029 buf-y-size: the height of the buffer image into which the desired region is
2030 to be read, or from which it is to be written.
2031 buf-type: the type of the pixel values to be returned. The pixel values
2032 will automatically be translated to/from the GDALRasterBand data type as needed.
2033 band-count: the number of bands being read or written.
2034 band-map: the list of band-count numbers being read/written. Note band
2035 numbers are 1 based. This may be empty list '() to select the first band-count
2037 pixel-space: the byte offset from the start of one pixel value in data to
2038 the start of the next pixel value within a scanline. If defaulted (0) the size
2039 of the datatype buf-type is used.
2040 line-space: the byte offset from the start of one scanline in pData to the
2041 start of the next. If defaulted (0) the size of the datatype
2042 (* buf-type buf-x-size) is used.
2043 band-space: the byte offset from the start of one bands data to the start
2044 of the next. If defaulted (0) the value will be (* line-space buf-y-size)
2045 implying band sequential organization of the data buffer.
2046 options: driver specific control options in a string list or empty
2047 list '(). Consult driver documentation for options supported."
2048 (%gdal-begin-async-reader h-dataset x-off y-off x-size y-size
2049 (bytevector->pointer data) buf-x-size buf-y-size
2050 buf-type band-count (list->pointer band-map int)
2051 pixel-space line-space band-space
2052 (string-list->pointerpointer options)))
2054 (export begin-async-reader)
2056 ;;------------------------------------------------------------------------------
2058 (define-gdal-foreign %gdal-end-async-reader
2059 void "GDALEndAsyncReader" (list '* '*) 20)
2061 (define (end-async-reader h-dataset h-async-reader)
2062 "End asynchronous request.
2065 h-dataset: handle representing GDALDataset.
2066 h-async-reader: handle representing async reader request."
2067 (%gdal-end-async-reader h-dataset h-async-reader))
2069 (export end-async-reader)
2071 ;;------------------------------------------------------------------------------
2073 (define-gdal-foreign %gdal-raster-io-ex
2074 int "GDALRasterIOEx" (list '* int int int int int '*
2075 int int int int64 int64 '*) 20)
2077 (define (raster-io-ex h-band rw-flag x-off y-off x-size y-size data
2078 buf-x-size buf-y-size buf-type pixel-space
2079 line-space extra-arg)
2080 "Read/write a region of image data for this band.
2083 h-band: a handle representing GDALRasterBandH.
2084 rw-flag: either GF_READ to read, or GF_WRITE to write a region of data.
2085 x-off: the pixel offset to the top left corner of the region of the band.
2086 y-off: the line offset to the top left corner of the region of the band.
2087 x-size: the width of the region of the band.
2088 y-size: the height of the region of the band.
2089 data: the bytevector buffer into which the data should be read, or from
2090 which it should be written. This buffer must contain at least
2091 (* buf-x-size buf-y-size) words of type buf-type. It is organized in left to
2092 right, top to bottom pixel order. Spacing is controlled by the pixel-space, and
2093 line-space parameters.
2094 buf-x-size: the width of the buffer image into which the desired region is
2095 to be read, or from which it is to be written.
2096 buf-y-size: the height of the buffer image into which the desired region is
2097 to be read, or from which it is to be written.
2098 buf-type: the type of the pixel values to be returned. The pixel values
2099 will automatically be translated to/from the GDALRasterBand data type as needed.
2100 pixel-space: the byte offset from the start of one pixel value in data to
2101 the start of the next pixel value within a scanline. If defaulted (0) the size
2102 of the datatype buf-type is used.
2103 line-space: the byte offset from the start of one scanline in pData to the
2104 start of the next. If defaulted (0) the size of the datatype
2105 (* buf-type buf-x-size) is used.
2106 extra-arg: (new in GDAL 2.0) pointer to a GDALRasterIOExtraArg structure
2107 constructed with \"make-grioea\" function which creates grioea record
2108 with additional arguments to specify resampling and progress callback, or
2109 #f for default behaviour. The GDAL_RASTERIO_RESAMPLING configuration option can
2110 also be defined to override the default resampling to one of BILINEAR, CUBIC,
2111 CUBICSPLINE, LANCZOS, AVERAGE or MODE."
2112 (let ((result (%gdal-raster-io-ex h-band rw-flag x-off y-off x-size y-size
2113 (bytevector->pointer data)
2114 buf-x-size buf-y-size buf-type
2115 pixel-space line-space
2116 (grioea->foreign-pointer extra-arg))))
2117 (unless (= result CE_NONE)
2118 (error "failed to read/write data for this band"))))
2120 (export raster-io-ex)
2122 ;;------------------------------------------------------------------------------
2124 (define-gdal-foreign %gdal-dataset-advise-read
2125 int "GDALDatasetAdviseRead" (list '* int int int int
2126 int int int int '* '*) 20)
2128 (define (dataset-advise-read h-dataset x-off y-off x-size y-size
2129 buf-x-size buf-y-size buf-type band-count
2131 "Advise driver of upcoming read requests. Return CE_FAILURE if the request
2132 is invalid and CE_NONE if it works or is ignored.
2135 h-dataset: a handle representing GDALDatasetH.
2136 x-off: the pixel offset to the top left corner of the region of the band.
2137 y-off: the line offset to the top left corner of the region of the band.
2138 x-size: the width of the region of the band.
2139 y-size: the height of the region of the band.
2140 buf-x-size: the width of the buffer image into which the desired region is
2141 to be read, or from which it is to be written.
2142 buf-y-size: the height of the buffer image into which the desired region is
2143 to be read, or from which it is to be written.
2144 buf-type: the type of the pixel values to be returned. The pixel values
2145 will automatically be translated to/from the GDALRasterBand data type as needed.
2146 band-count: the number of bands being read or written.
2147 band-map: the list of band-count numbers being read/written. Note band
2148 numbers are 1 based. This may be empty list '() to select the first band-count
2150 options: driver specific control options in a string list or empty
2151 list '(). Consult driver documentation for options supported."
2152 (%gdal-dataset-advise-read h-dataset x-off y-off x-size y-size
2153 buf-x-size buf-y-size buf-type band-count
2154 (list->pointer band-map int)
2155 (string-list->pointerpointer options)))
2157 (export dataset-advise-read)
2159 ;;------------------------------------------------------------------------------
2161 (define-gdal-foreign %gdal-get-projection-ref
2162 '* "GDALGetProjectionRef" (list '*) 20)
2164 (define (get-projection-ref h-dataset)
2165 "Fetch the projection definition string for this dataset.
2167 The returned string defines the projection coordinate system of the image in
2170 When a projection definition is not available an empty string is returned.
2173 h-dataset: a handle representing GDALDataset."
2174 (pointer->string (%gdal-get-projection-ref h-dataset)))
2176 (export get-projection-ref)
2178 ;;------------------------------------------------------------------------------
2180 (define-gdal-foreign %gdal-get-spatial-ref
2181 '* "GDALGetSpatialRef" (list '*) 30)
2183 (define (get-spatial-ref h-dataset)
2184 "Fetch the spatial reference for this dataset. Available since GDAL 3.0.
2187 h-dataset: a handle representing GDALDataset."
2188 (%gdal-get-spatial-ref h-dataset))
2190 (export get-spatial-ref)
2192 ;;------------------------------------------------------------------------------
2194 (define-gdal-foreign %gdal-set-projection
2195 int "GDALSetProjection" (list '* '*) 20)
2197 (define (set-projection h-dataset projection)
2198 "Set the projection reference string in OGC WKT or PROJ.4 format for this
2202 h-dataset: a handle representing GDALDataset.
2203 projection: projection reference string."
2204 (let ((result (%gdal-set-projection h-dataset
2205 (string->pointer projection))))
2206 (unless (= result CE_NONE)
2207 (error "failed to set projection"))))
2209 (export set-projection)
2211 ;;------------------------------------------------------------------------------
2213 (define-gdal-foreign %gdal-set-spatial-ref
2214 int "GDALSetSpatialRef" (list '* '*) 30)
2216 (define (set-spatial-ref h-dataset srs)
2217 "Set the spatial reference system for this dataset. Available since
2221 h-dataset: a handle representing GDALDataset.
2222 srs: spatial reference system object. %null-pointer can potentially be
2223 passed for drivers that support unsetting the SRS."
2224 (let ((result (%gdal-set-spatial-ref h-dataset srs)))
2225 (unless (= result CE_NONE)
2226 (error "failed to set spatial reference"))))
2228 (export set-spatial-ref)
2230 ;;------------------------------------------------------------------------------
2232 (define-gdal-foreign %gdal-get-geo-transform
2233 int "GDALGetGeoTransform" (list '* '*) 20)
2235 (define (get-geo-transform h-dataset)
2236 "Return a list of transformation coefficients.
2239 h-dataset: a handle representing GDALDataset."
2241 (let* ((bv-gp-out (make-bytevector (* 6 (sizeof double))))
2243 (result (%gdal-get-geo-transform
2245 (bytevector->pointer bv-gp-out))))
2246 (if (= result CE_FAILURE)
2247 (error "failed to fetch transform")
2248 (let ((coefs-q (make-q)))
2250 ((> i coef-max-index))
2251 (enq! coefs-q (bytevector-ieee-double-native-ref
2253 (* i (sizeof double)))))
2256 (export get-geo-transform)
2258 ;;------------------------------------------------------------------------------
2260 (define-gdal-foreign %gdal-set-geo-transform
2261 int "GDALSetGeoTransform" (list '* '*) 20)
2263 (define (set-geo-transform h-dataset transform)
2264 "Set the affine transformation coefficients.
2267 h-dataset: a handle representing GDALDataset.
2268 transform: a list of transformation coefficients."
2269 (cond ((not (pair? transform))
2270 (error "transform is not a list or empty"))
2271 ((not (= 6 (length transform)))
2272 (error "insufficient number of coefficients in the list (6 doubles)"))
2273 (else (let ((result (%gdal-set-geo-transform
2275 (list->pointer transform double))))
2276 (unless (= result CE_NONE)
2277 (error "failed to set transform"))))))
2279 (export set-geo-transform)
2281 ;;------------------------------------------------------------------------------
2283 (define-gdal-foreign %gdal-get-gcp-count
2284 int "GDALGetGCPCount" (list '*) 20)
2286 (define (get-gcp-count h-dataset)
2287 "Return number of GCPs for this dataset.
2290 h-dataset: a handle representing GDALDataset."
2291 (%gdal-get-gcp-count h-dataset))
2293 (export get-gcp-count)
2295 ;;------------------------------------------------------------------------------
2297 (define-gdal-foreign %gdal-get-gcp-projection
2298 '* "GDALGetGCPProjection" (list '*) 20)
2300 (define (get-gcp-projection h-dataset)
2301 "Return internal projection string for GCPs or empty string if there are
2305 h-dataset: a handle representing GDALDataset."
2306 (pointer->string (%gdal-get-gcp-projection h-dataset)))
2308 (export get-gcp-projection)
2310 ;;------------------------------------------------------------------------------
2312 (define-gdal-foreign %gdal-get-gcp-spatial-ref
2313 '* "GDALGetGCPSpatialRef" (list '*) 30)
2315 (define (get-gcp-spatial-ref h-dataset)
2316 "Return a pointer to an internal object of output spatial reference system
2317 for GCPs. Available since GDAL 3.0.
2320 h-dataset: a handle representing GDALDataset."
2321 (%gdal-get-gcp-spatial-ref h-dataset))
2323 (export get-gcp-spatial-ref)
2325 ;;------------------------------------------------------------------------------
2327 (define-gdal-foreign %gdal-get-gcps
2328 '* "GDALGetGCPs" (list '*) 20)
2330 (define (get-gcps h-dataset)
2331 "Return a list of internal GCP structure.
2334 h-dataset: a handle representing GDALDataset."
2335 (pointer->gcp-list (%gdal-get-gcps h-dataset) (get-gcp-count h-dataset)))
2339 ;;------------------------------------------------------------------------------
2341 (define-gdal-foreign %gdal-set-gcps
2342 int "GDALSetGCPs" (list '* int '* '*) 20)
2344 (define* (set-gcps h-dataset gcp-lst #:key (projection ""))
2348 h-dataset: a handle representing GDALDataset.
2349 gc-lst: list of GCP structures where each structure is created by
2350 \"make-gcp\" function.
2351 projection (optional): string of the new OGC WKT coordinate system to
2352 assign for the GCP output coordinates."
2353 (let ((result (%gdal-set-gcps h-dataset
2355 (gcp-list->pointer gcp-lst)
2356 (string->pointer projection))))
2357 (unless (= result CE_NONE)
2358 (error "failed to set GCPs"))))
2362 ;;------------------------------------------------------------------------------
2364 (define-gdal-foreign %gdal-set-gcps2
2365 int "GDALSetGCPs2" (list '* int '* '*) 30)
2367 (define* (set-gcps2 h-dataset gcp-lst #:key (spatial-ref %null-pointer))
2368 "Assign GCPs. Available since GDAL 3.0.
2371 h-dataset: a handle representing GDALDataset.
2372 gc-lst: list of GCP structures where each structure is created by
2373 \"make-gcp\" function.
2374 spatial-ref (optional): the new coordinate reference system to assign for
2375 the GCP output coordinates."
2376 (let ((result (%gdal-set-gcps2 h-dataset
2378 (gcp-list->pointer gcp-lst)
2380 (unless (= result CE_NONE)
2381 (error "failed to set GCPs"))))
2385 ;;------------------------------------------------------------------------------
2387 (define-gdal-foreign %gdal-get-internal-handle
2388 '* "GDALGetInternalHandle" (list '* '*) 20)
2390 (define (get-internal-handle h-dataset request)
2391 "Fetch a format specific internally meaningful handle.
2394 h-dataset: a handle representing GDALDataset.
2395 request: the handle name desired. The meaningful names will be specific to
2397 (%gdal-get-internal-handle h-dataset (string->pointer request)))
2399 (export get-internal-handle)
2401 ;;------------------------------------------------------------------------------
2403 (define-gdal-foreign %gdal-reference-dataset
2404 int "GDALReferenceDataset" (list '*) 20)
2406 (define (reference-dataset h-dataset)
2407 "Add one to dataset reference count.
2410 h-dataset: a handle representing GDALDataset."
2411 (%gdal-reference-dataset h-dataset))
2413 (export reference-dataset)
2415 ;;------------------------------------------------------------------------------
2417 (define-gdal-foreign %gdal-dereference-dataset
2418 int "GDALDereferenceDataset" (list '*) 20)
2420 (define (dereference-dataset h-dataset)
2421 "Subtract one from dataset reference count.
2424 h-dataset: a handle representing GDALDataset."
2425 (%gdal-dereference-dataset h-dataset))
2427 (export dereference-dataset)
2429 ;;------------------------------------------------------------------------------
2431 (define-gdal-foreign %gdal-release-dataset
2432 int "GDALReleaseDataset" (list '*) 20)
2434 (define (release-dataset h-dataset)
2435 "Drop a reference to this object, and destroy if no longer referenced.
2438 h-dataset: a handle representing GDALDataset."
2439 (%gdal-release-dataset h-dataset))
2441 (export release-dataset)
2443 ;;------------------------------------------------------------------------------
2445 (define-gdal-foreign %gdal-build-overviews
2446 int "GDALBuildOverviews" (list '* '* int '* int '* '* '*) 20)
2448 (define* (build-overviews h-dataset resampling overview-list band-list
2449 #:key (progress-callback '())
2450 (progress-data %null-pointer))
2451 "Build raster overview(s).
2454 h-dataset: a handle representing GDALDatasetH.
2455 resampling: one of GRIORAv2 enums controlling the downsampling method
2457 overview-list: the list of overview decimation factors to build, or '() to
2459 band-list: list of band numbers to build overviews. Build for all bands if
2461 progress-callback (optional): a function to call to report progress.
2462 progress-data (optional): application data to pass to the progress
2464 (let ((result (%gdal-build-overviews h-dataset
2465 (string->pointer (assv-ref
2466 *grioeav2-to-string* resampling))
2467 (length overview-list)
2468 (list->pointer overview-list int)
2470 (list->pointer band-list int)
2471 (gdal-progress-func progress-callback)
2473 (when (= result CE_FAILURE)
2474 (error "failed to build overview"))))
2476 (export build-overviews)
2478 ;;------------------------------------------------------------------------------
2480 (define-gdal-foreign %gdal-get-open-datasets
2481 void "GDALGetOpenDatasets" (list '* '*) 20)
2483 (define (get-open-datasets)
2484 "Return a list of all open GDAL dataset handles."
2485 (let ((bv-ds (make-bytevector (sizeof '*)))
2486 (bv-count (make-bytevector (sizeof '*))))
2487 (%gdal-get-open-datasets (bytevector->pointer bv-ds)
2488 (bytevector->pointer bv-count))
2489 (pointerpointer->list (bytevector->pointer bv-ds)
2491 (bytevector-sint-ref
2496 (export get-open-datasets)
2498 ;;------------------------------------------------------------------------------
2500 (define-gdal-foreign %gdal-get-access
2501 int "GDALGetAccess" (list '*) 20)
2503 (define (get-access h-dataset)
2504 "Return access flag.
2507 h-dataset: a handle representing GDALDataset."
2508 (%gdal-get-access h-dataset))
2511 ;;------------------------------------------------------------------------------
2513 (define-gdal-foreign %gdal-flush-cache
2514 void "GDALFlushCache" (list '*) 20)
2516 (define (flush-cache h-dataset)
2517 "Flush all write cached data to disk.
2520 h-dataset: a handle representing GDALDataset."
2521 (%gdal-flush-cache h-dataset))
2523 (export flush-cache)
2525 ;;------------------------------------------------------------------------------
2527 (define-gdal-foreign %gdal-create-dataset-mask-band
2528 int "GDALCreateDatasetMaskBand" (list '* int) 20)
2530 (define (create-dataset-mask-band h-dataset flags)
2531 "Adds a mask band to the dataset.
2534 h-dataset: a handle representing GDALDataset.
2535 flags: 0 or combination of GMF_PER_DATASET / GMF_ALPHA. GMF_PER_DATASET
2536 will be always set, even if not explicitly specified."
2537 (let ((result (%gdal-create-dataset-mask-band h-dataset flags)))
2538 (unless (= result CE_NONE)
2539 (error "failed to create mask band"))))
2541 (export create-dataset-mask-band)
2543 ;;------------------------------------------------------------------------------
2545 (define-gdal-foreign %gdal-dataset-copy-whole-raster
2546 int "GDALDatasetCopyWholeRaster" (list '* '* '* '* '*) 20)
2548 (define* (dataset-copy-whole-raster src-dataset dst-dataset options
2549 #:key (progress-callback '())
2550 (progress-data %null-pointer))
2551 "Copy all dataset raster data.
2553 Currently the only options value supported are :
2555 \"INTERLEAVE=PIXEL\" to force pixel interleaved operation
2556 \"COMPRESSED=YES\" to force alignment on target dataset block sizes to
2557 achieve best compression.
2558 \"SKIP_HOLES=YES\" to skip chunks for which \"get-data-coverage-status\"
2559 returns GDAL_DATA_COVERAGE_STATUS_EMPTY (GDAL >= 2.2)
2562 src-dataset: the source dataset
2563 dst-dataset: the destination dataset.
2564 options: a list of strings for transfer hints in Name=Value format.
2565 progress-callback (optional): a function to call to report progress.
2566 progress-data (optional): application data to pass to the progress
2568 (let ((result (%gdal-dataset-copy-whole-raster src-dataset
2570 (string-list->pointerpointer
2575 (unless (= result CE_NONE)
2576 (error "failed to copy raster dataset"))))
2578 (export dataset-copy-whole-raster)
2580 ;;------------------------------------------------------------------------------
2582 (define-gdal-foreign %gdal-raster-band-copy-whole-raster
2583 int "GDALRasterBandCopyWholeRaster" (list '* '* '* '* '*) 20)
2585 (define* (raster-band-copy-whole-raster src-band dst-band options
2586 #:key (progress-callback '())
2587 (progress-data %null-pointer))
2588 "Copy a whole raster band.
2590 Currently the only options value supported are :
2592 \"COMPRESSED=YES\" to force alignment on target dataset block sizes to
2593 achieve best compression.
2594 \"SKIP_HOLES=YES\" to skip chunks for which \"get-data-coverage-status\"
2595 returns GDAL_DATA_COVERAGE_STATUS_EMPTY (GDAL >= 2.2)
2598 src-band: the source band.
2599 dst-band: the destination band.
2600 options: a list of strings for transfer hints in Name=Value format.
2601 progress-callback (optional): a function to call to report progress.
2602 progress-data (optional): application data to pass to the progress
2604 (let ((result (%gdal-raster-band-copy-whole-raster
2607 (string-list->pointerpointer options)
2608 (gdal-progress-func progress-callback)
2610 (unless (= result CE_NONE)
2611 (error "failed to copy raster band"))))
2613 (export raster-band-copy-whole-raster)
2615 ;;------------------------------------------------------------------------------
2617 (define-gdal-foreign %gdal-regenerage-overviews
2618 int "GDALRegenerateOverviews" (list '* int '* '* '* '*) 20)
2620 (define* (regenerage-overviews src-band band-list resampling
2621 #:key (progress-callback '())
2622 (progress-data %null-pointer))
2623 "Generate downsampled overviews.
2626 src-band: the source (base level) band.
2627 band-list: the list of downsampled bands to be generated.
2628 resampling: one of GRIORAv2 enums controlling the downsampling method
2630 progress-callback (optional): a function to call to report progress.
2631 progress-data (optional): application data to pass to the progress
2633 (let ((result (%gdal-regenerage-overviews
2636 (list->pointer band-list '*)
2637 (string->pointer (assv-ref
2638 *grioeav2-to-string* resampling))
2639 (gdal-progress-func progress-callback)
2641 (when (= result CE_FAILURE)
2642 (error "failed to regenerate overview"))))
2644 (export regenerage-overviews)
2646 ;;------------------------------------------------------------------------------
2648 (define-gdal-foreign %gdal-dataset-get-layer-count
2649 int "GDALDatasetGetLayerCount" (list '*) 20)
2651 (define (dataset-get-layer-count h-dataset)
2652 "Get the number of layers in this dataset.
2655 h-dataset: a dataset handle."
2656 (%gdal-dataset-get-layer-count h-dataset))
2658 (export dataset-get-layer-count)
2660 ;;------------------------------------------------------------------------------
2662 (define-gdal-foreign %gdal-dataset-get-layer
2663 '* "GDALDatasetGetLayer" (list '* int) 20)
2665 (define (dataset-get-layer h-dataset layer)
2666 "Fetch a layer by index. Return the layer handle or %null-pointer if layer
2667 is out of range or an error occurs.
2670 h-dataset: a dataset handle.
2671 layer: a layer number between 0 and (1- dataset-get-layer-count)"
2672 (%gdal-dataset-get-layer h-dataset layer))
2674 (export dataset-get-layer)
2676 ;;------------------------------------------------------------------------------
2678 (define-gdal-foreign %gdal-dataset-get-layer-by-name
2679 '* "GDALDatasetGetLayerByName" (list '* '*) 20)
2681 (define (dataset-get-layer-by-name h-dataset name)
2682 "Fetch a layer by name. Return the layer handle or %null-pointer if layer
2683 is not found or an error occurs.
2686 h-dataset: a dataset handle.
2687 name: the layer name of the layer to fetch."
2688 (%gdal-dataset-get-layer-by-name h-dataset (string->pointer name)))
2690 (export dataset-get-layer-by-name)
2692 ;;------------------------------------------------------------------------------
2694 (define-gdal-foreign %gdal-dataset-delete-layer
2695 int "GDALDatasetDeleteLayer" (list '* int) 20)
2697 (define (dataset-delete-layer h-dataset layer)
2698 "Delete the indicated layer from the datasource.
2701 h-dataset: a dataset handle.
2702 layer: the index of the layer to delete."
2703 (let ((result (%gdal-dataset-delete-layer h-dataset layer)))
2704 (unless (= result CE_NONE)
2705 (error "failed to delete layer"))))
2707 (export dataset-delete-layer)
2709 ;;------------------------------------------------------------------------------
2711 (define-gdal-foreign %gdal-dataset-create-layer
2712 '* "GDALDatasetCreateLayer" (list '* '* '* int '*) 20)
2714 (define* (dataset-create-layer h-dataset name
2715 #:key (spatial-ref %null-pointer)
2718 "This function attempts to create a new layer on the dataset with the
2719 indicated name, coordinate system, geometry type. Return an handle to the layer
2720 or %null-pointer is returned on failure.
2723 h-dataset: a dataset handle.
2724 name: the name for the new layer. This should ideally not match any
2725 existing layer on the datasource.
2726 spatial-ref (optional): the coordinate system handle to use for the new
2727 layer. Default is %null-pointer where no coordinate system is available.
2728 type (optional): the geometry type for the layer. Default is WKB_UNKNOWN
2729 providing no constraints on the types geometry to be written. Use the module
2730 (gdal ogr) to access WKB enums.
2731 options (optional): a list of strings in name=value format. Default is
2732 empty list. Options are driver specific"
2733 (%gdal-dataset-create-layer h-dataset
2734 (string->pointer name)
2737 (string-list->pointerpointer options)))
2739 (export dataset-create-layer)
2741 ;;------------------------------------------------------------------------------
2743 (define-gdal-foreign %gdal-dataset-copy-layer
2744 '* "GDALDatasetCopyLayer" (list '* '* '* '*) 20)
2746 (define* (dataset-copy-layer h-dataset layer name
2747 #:key (options '()))
2748 "Duplicate an existing layer. Return an handle to the layer or %null-pointer
2752 h-dataset: a dataset handle.
2753 layer: source layer.
2754 name: the name for the new layer. This should ideally not match any
2755 existing layer on the datasource.
2756 options (optional): a list of strings in name=value format. Default is
2757 empty list. Options are driver specific"
2758 (%gdal-dataset-copy-layer h-dataset
2760 (string->pointer name)
2761 (string-list->pointerpointer options)))
2763 (export dataset-copy-layer)
2765 ;;------------------------------------------------------------------------------
2767 (define-gdal-foreign %gdal-dataset-reset-reading
2768 void "GDALDatasetResetReading" (list '*) 20)
2770 (define (dataset-reset-reading h-dataset)
2771 "Reset feature reading to start on the first feature.
2774 h-dataset: a dataset handle."
2775 (%gdal-dataset-reset-reading h-dataset))
2777 (export dataset-reset-reading)
2779 ;;------------------------------------------------------------------------------
2781 (define-gdal-foreign %gdal-dataset-get-next-feature
2782 '* "GDALDatasetGetNextFeature" (list '* '* '* '* '*) 20)
2784 (define* (dataset-get-next-feature h-dataset #:key (progress-callback '())
2785 (progress-data %null-pointer))
2786 "Fetch the next available feature from this dataset. Return multiple values
2787 of feature in a list, belonging layer pointer which the object belongs to and
2788 a double variable for the precentage progress in [0, 1] range, respectively.
2789 Otherwise returns empty list if no more features are available.
2792 h-dataset: a dataset handle.
2793 progress-callback (optional): a function to call to report progress.
2794 progress-data (optional): application data to pass to the progress
2796 (let* ((layer (make-bytevector (sizeof '*)))
2797 (progress (make-bytevector (sizeof double)))
2798 (result (%gdal-dataset-get-next-feature
2800 (bytevector->pointer layer)
2801 (bytevector->pointer progress)
2802 (gdal-progress-func progress-callback)
2804 (if (null-pointer? result)
2806 (list (dereference-pointer (bytevector->pointer layer))
2807 (bytevector-ieee-double-ref progress 0 (native-endianness))))))
2809 (export dataset-get-next-feature)
2811 ;;------------------------------------------------------------------------------
2813 (define-gdal-foreign %gdal-dataset-test-capability
2814 int "GDALDatasetTestCapability" (list '* '*) 20)
2816 (define (dataset-test-capability h-dataset cap)
2817 "Test if capability is available. Return #t if capability available
2820 - ODSC_CREATE_LAYER: True if this datasource can create new layers.
2821 - ODSC_DELETE_LAYER: True if this datasource can delete existing layers.
2822 - ODSC_CREATE_GEOM_FIELD_AFTER_CREATE_LAYER: True if the layers of this
2823 datasource support create-geom-field just after layer creation.
2824 - ODSC_CURVE_GEOMETRIES: True if this datasource supports curve geometries.
2825 - ODSC_TRANSACTIONS: True if this datasource supports (efficient) transactions.
2826 - ODSC_EMULATED_TRANSACTIONS: True if this datasource supports transactions
2828 - ODSC_RANDOM_LAYER_READ: True if this datasource has a dedicated
2829 get-next-feature implementation, potentially returning features from layers in
2830 a non sequential way.
2831 - ODSC_RANDOM_LAYER_WRITE: True if this datasource supports calling
2832 create-feature on layers in a non sequential way.
2835 h-dataset: a dataset handle.
2836 cap: ODCS enum for the capability to test."
2837 (c-bool->boolean (%gdal-dataset-test-capability h-dataset
2838 (string->pointer cap))))
2840 (export dataset-test-capability)
2842 ;;------------------------------------------------------------------------------
2844 (define-gdal-foreign %gdal-dataset-execute-sql
2845 '* "GDALDatasetExecuteSQL" (list '* '* '* '*) 20)
2847 (define* (dataset-execute-sql h-dataset statement #:key
2848 (spatial-filter %null-pointer)
2849 (dialect %null-pointer))
2850 "Execute an SQL statement against the data store. Return a pointer
2851 of an OGRLayer containing the results of the query. Deallocate with
2852 \"release-result-set\".
2855 h-dataset: the dataset handle.
2856 statement: the SQL statement to execute.
2857 spatial-filter: geometry which represents a spatial filter. Default is
2859 dialect: a string that allows control of the statement dialect. By default
2860 the OGR SQL engine will be used."
2861 (%gdal-dataset-execute-sql h-dataset
2862 (string->pointer statement)
2864 (if (null-pointer? dialect)
2866 (string->pointer dialect))))
2868 (export dataset-execute-sql)
2870 ;;------------------------------------------------------------------------------
2872 (define-gdal-foreign %gdal-dataset-release-result-set
2873 void "GDALDatasetReleaseResultSet" (list '* '*) 20)
2875 (define (dataset-release-result-set h-dataset h-layer)
2876 "Release results of dataset-execute-sql.
2879 h-dataset: a dataset handle.
2880 h-layer: the result of a previous dataset-execute-sql call."
2881 (%gdal-dataset-release-result-set h-dataset h-layer))
2883 (export dataset-release-result-set)
2885 ;;------------------------------------------------------------------------------
2887 (define-gdal-foreign %gdal-dataset-get-style-table
2888 '* "GDALDatasetGetStyleTable" (list '*) 20)
2890 (define (dataset-get-style-table h-dataset)
2891 "Return the OGRStyleTableH handle of dataset style table which should not
2892 be modified or freed by the caller.
2895 h-dataset: a dataset handle."
2896 (%gdal-dataset-get-style-table h-dataset))
2898 (export dataset-get-style-table)
2900 ;;------------------------------------------------------------------------------
2902 (define-gdal-foreign %gdal-dataset-set-style-table-directly
2903 void "GDALDatasetSetStyleTableDirectly" (list '* '*) 20)
2905 (define (dataset-set-style-table-directly h-dataset h-style-table)
2906 "Set dataset style table.
2909 h-dataset: a dataset handle.
2910 h-style-table: the style table handle to set."
2911 (%gdal-dataset-set-style-table-directly h-dataset h-style-table))
2913 (export dataset-set-style-table-directly)
2915 ;;------------------------------------------------------------------------------
2917 (define-gdal-foreign %gdal-dataset-set-style-table
2918 void "GDALDatasetSetStyleTable" (list '* '*) 20)
2920 (define (dataset-set-style-table h-dataset h-style-table)
2921 "Set dataset style table. This function operate exactly as
2922 dataset-set-style-table-directly except that it assumes ownership of the
2926 h-dataset: a dataset handle.
2927 h-style-table: the style table handle to set."
2928 (%gdal-dataset-set-style-table h-dataset h-style-table))
2930 (export dataset-set-style-table)
2932 ;;------------------------------------------------------------------------------
2934 (define-gdal-foreign %gdal-dataset-start-transaction
2935 int "GDALDatasetStartTransaction" (list '* int) 20)
2937 (define (dataset-start-transaction h-dataset force)
2938 "For datasources which support transactions, dataset-start-transaction
2939 creates a transaction. Return OGRERR_NONE on success. If starting the
2940 transaction fails, will return OGRERR_FAILURE. Datasources which do not
2941 support transactions will always return OGRERR_UNSUPPORTED_OPERATION.
2944 h-dataset: a handle representing GDALDataset.
2945 force: a boolean value that can be set to #t if an emulation, possibly
2946 slow, of a transaction mechanism is acceptable."
2947 (%gdal-dataset-start-transaction h-dataset
2948 (boolean->c-bool force)))
2950 (export dataset-start-transaction)
2952 ;;------------------------------------------------------------------------------
2954 (define-gdal-foreign %gdal-dataset-commit-transaction
2955 int "GDALDatasetCommitTransaction" (list '*) 20)
2957 (define (dataset-commit-transaction h-dataset)
2958 "For datasources which support transactions, dataset-commit-transaction
2959 commits a transaction. Return OGRERR_NONE on success. If no transaction is
2960 active, or the commit fails, will return OGRERR_FAILURE. Datasources which do
2961 not support transactions will always return OGRERR_UNSUPPORTED_OPERATION.
2964 h-dataset: a handle representing GDALDataset."
2965 (%gdal-dataset-commit-transaction h-dataset))
2967 (export dataset-commit-transaction)
2969 ;;------------------------------------------------------------------------------
2971 (define-gdal-foreign %gdal-dataset-rollback-transaction
2972 int "GDALDatasetRollbackTransaction" (list '*) 20)
2974 (define (dataset-rollback-transaction h-dataset)
2975 "For datasources which support transactions, dataset-rollback-transaction
2976 will roll back a datasource to its state before the start of the current
2977 transaction. Return OGRERR_NONE on success. If no transaction is active, or
2978 the rollback fails, will return OGRERR_FAILURE. Datasources which do not
2979 support transactions will always return OGRERR_UNSUPPORTED_OPERATION.
2982 h-dataset: a handle representing GDALDataset."
2983 (%gdal-dataset-rollback-transaction h-dataset))
2985 (export dataset-rollback-transaction)
2987 ;;------------------------------------------------------------------------------
2989 (define-gdal-foreign %gdal-get-raster-data-type
2990 int "GDALGetRasterDataType" (list '*) 20)
2992 (define (get-raster-data-type h-band)
2993 "Fetch the pixel data type for this band.
2996 h-band: a handle representing GDALRasterBandH."
2997 (%gdal-get-raster-data-type h-band))
2999 (export get-raster-data-type)
3001 ;;------------------------------------------------------------------------------
3003 (define-gdal-foreign %gdal-get-block-size
3004 void "GDALGetBlockSize" (list '* '* '*) 20)
3006 (define (get-block-size h-band)
3007 "Fetch the \"natural\" block size of this band as values of x size and
3008 y size, respectively.
3011 h-band: a handle representing GDALRasterBandH."
3012 (let* ((bv-x-size (make-bytevector (sizeof int)))
3013 (bv-y-size (make-bytevector (sizeof int))))
3014 (%gdal-get-block-size h-band
3015 (bytevector->pointer bv-x-size)
3016 (bytevector->pointer bv-y-size))
3018 (bytevector-sint-ref bv-x-size 0 (native-endianness) (sizeof int))
3019 (bytevector-sint-ref bv-y-size 0 (native-endianness) (sizeof int)))))
3021 (export get-block-size)
3023 ;;------------------------------------------------------------------------------
3025 (define-gdal-foreign %gdal-get-actual-block-size
3026 int "GDALGetActualBlockSize" (list '* int int '* '*) 20)
3028 (define (get-actual-block-size h-band x-block-off y-block-off)
3029 "Retrieve the actual block size for a given block offset as values of the
3030 number of valid pixels in the x direction and y direction, respectively.
3033 h-band: a handle representing GDALRasterBandH.
3034 x-block-off: the horizontal block offset for which to calculate the
3035 number of valid pixels, with zero indicating the left most block, 1 the next
3037 y-block-off: the vertical block offset, with zero indicating the left most
3038 block, 1 the next block and so forth."
3039 (let* ((bv-x-size (make-bytevector (sizeof int)))
3040 (bv-y-size (make-bytevector (sizeof int))))
3041 (%gdal-get-actual-block-size h-band x-block-off y-block-off
3042 (bytevector->pointer bv-x-size)
3043 (bytevector->pointer bv-y-size))
3045 (bytevector-sint-ref bv-x-size 0 (native-endianness) (sizeof int))
3046 (bytevector-sint-ref bv-y-size 0 (native-endianness) (sizeof int)))))
3048 (export get-actual-block-size)
3050 ;;------------------------------------------------------------------------------
3052 (define-gdal-foreign %gdal-raster-advise-read
3053 int "GDALRasterAdviseRead" (list '* int int int int int int int '*) 20)
3055 (define (raster-advise-read h-band x-off y-off x-size y-size
3056 buf-x-size buf-y-size buf-type options)
3057 "Advise driver of upcoming read requests. Return CE_FAILURE if the request
3058 is invalid and CE_NONE if it works or is ignored.
3061 h-band: a handle representing GDALRasterBandH.
3062 x-off: the pixel offset to the top left corner of the region of the band.
3063 y-off: the line offset to the top left corner of the region of the band.
3064 x-size: the width of the region of the band.
3065 y-size: the height of the region of the band.
3066 buf-x-size: the width of the buffer image into which the desired region is
3067 to be read, or from which it is to be written.
3068 buf-y-size: the height of the buffer image into which the desired region is
3069 to be read, or from which it is to be written.
3070 buf-type: the type of the pixel values to be returned. The pixel values
3071 will automatically be translated to/from the GDALRasterBand data type as needed.
3072 options: driver specific control options in a string list or empty
3073 list '(). Consult driver documentation for options supported."
3074 (%gdal-raster-advise-read h-band x-off y-off x-size y-size
3075 buf-x-size buf-y-size buf-type
3076 (string-list->pointerpointer options)))
3078 (export raster-advise-read)
3080 ;;------------------------------------------------------------------------------
3082 (define-gdal-foreign %gdal-read-block
3083 int "GDALReadBlock" (list '* int int '*) 20)
3085 (define (read-block h-band x-block-off y-block-off data)
3086 "Read a block of image data efficiently.
3089 h-band: a handle representing GDALRasterBandH.
3090 x-block-off: the horizontal block offset, with zero indicating the left
3091 most block, 1 the next block and so forth
3092 y-block-off: the vertical block offset, with zero indicating the top most
3093 block, 1 the next block and so forth.
3094 data: the bytevector buffer into which the data should be read. The buffer
3095 must be large enough to hold (* block-x-size block-y-size) words of type
3097 (let ((result (%gdal-read-block h-band x-block-off y-block-off
3098 (bytevector->pointer data))))
3099 (unless (= result CE_NONE)
3100 (error "failed to read a block of data for this band"))))
3104 ;;------------------------------------------------------------------------------
3106 (define-gdal-foreign %gdal-write-block
3107 int "GDALWriteBlock" (list '* int int '*) 20)
3109 (define (write-block h-band x-block-off y-block-off data)
3110 "Write a block of image data efficiently.
3113 h-band: a handle representing GDALRasterBandH.
3114 x-block-off: the horizontal block offset, with zero indicating the left
3115 most block, 1 the next block and so forth
3116 y-block-off: the vertical block offset, with zero indicating the top most
3117 block, 1 the next block and so forth.
3118 data: the bytevector buffer from which the data will be written. The buffer
3119 must be large enough to hold (* block-x-size block-y-size) words of type
3121 (let ((result (%gdal-write-block h-band x-block-off y-block-off
3122 (bytevector->pointer data))))
3123 (unless (= result CE_NONE)
3124 (error "failed to write a block of data for this band"))))
3126 (export write-block)
3128 ;;------------------------------------------------------------------------------
3130 (define-gdal-foreign %gdal-get-raster-access
3131 int "GDALGetRasterAccess" (list '*) 20)
3133 (define (get-raster-access h-band)
3134 "Find out if we have update permission for this band.
3137 h-band: a handle representing GDALRasterBandH."
3138 (%gdal-get-raster-access h-band))
3140 (export get-raster-access)
3142 ;;------------------------------------------------------------------------------
3144 (define-gdal-foreign %gdal-get-band-number
3145 int "GDALGetBandNumber" (list '*) 20)
3147 (define (get-band-number h-band)
3148 "Fetch the band number for this band.
3151 h-band: a handle representing GDALRasterBandH."
3152 (%gdal-get-band-number h-band))
3154 (export get-band-number)
3156 ;;------------------------------------------------------------------------------
3158 (define-gdal-foreign %gdal-get-band-dataset
3159 '* "GDALGetBandDataset" (list '*) 20)
3161 (define (get-band-dataset h-band)
3162 "Fetch the owning dataset handle for this band.
3165 h-band: a handle representing GDALRasterBandH."
3166 (%gdal-get-band-dataset h-band))
3168 (export get-band-dataset)
3170 ;;------------------------------------------------------------------------------
3172 (define-gdal-foreign %gdal-get-raster-color-interpretation
3173 '* "GDALGetRasterColorInterpretation" (list '*) 20)
3175 (define (get-raster-color-interpretation h-band)
3176 "Fetch the handle of GDALColorInterp to figure out how this band is
3177 interpreted as color.
3180 h-band: a handle representing GDALRasterBandH."
3181 (%gdal-get-raster-color-interpretation h-band))
3183 (export get-raster-color-interpretation)
3185 ;;------------------------------------------------------------------------------
3187 (define-gdal-foreign %gdal-set-raster-color-interpretation
3188 int "GDALSetRasterColorInterpretation" (list '* '*) 20)
3190 (define (set-raster-color-interpretation h-band color-interp)
3191 "Set color interpretation of a band.
3194 h-band: a handle representing GDALRasterBandH.
3195 color-interp: a handle of the new color interpretation to apply to this
3197 (let ((result (%gdal-set-raster-color-interpretation h-band
3199 (unless (= result CE_NONE)
3200 (error "failed to set color interpretation"))))
3202 (export set-raster-color-interpretation)
3204 ;;------------------------------------------------------------------------------
3206 (define-gdal-foreign %gdal-get-raster-color-table
3207 '* "GDALGetRasterColorTable" (list '*) 20)
3209 (define (get-raster-color-table h-band)
3210 "Fetch the color table associated with band.
3213 h-band: a handle representing GDALRasterBandH."
3214 (%gdal-get-raster-color-table h-band))
3216 (export get-raster-color-table)
3218 ;;------------------------------------------------------------------------------
3220 (define-gdal-foreign %gdal-set-raster-color-table
3221 int "GDALSetRasterColorTable" (list '* '*) 20)
3223 (define (set-raster-color-table h-band color-table)
3224 "Set the raster color table of a band.
3227 h-band: a handle representing GDALRasterBandH.
3228 color-table: the color table to apply. This may be %null-pointer to clear
3229 the color table (where supported)."
3230 (let ((result (%gdal-set-raster-color-table h-band
3232 (unless (= result CE_NONE)
3233 (error "failed to set color table"))))
3235 (export set-raster-color-table)
3237 ;;------------------------------------------------------------------------------
3239 (define-gdal-foreign %gdal-has-arbitrary-overviews
3240 int "GDALHasArbitraryOverviews" (list '*) 20)
3242 (define (has-arbitrary-overviews h-band)
3243 "Check for arbitrary overviews. Return #t if arbitrary overviews available
3244 (efficiently), otherwise #f.
3247 h-band: a handle representing GDALRasterBandH."
3248 (c-bool->boolean (%gdal-has-arbitrary-overviews h-band)))
3250 (export has-arbitrary-overviews)
3252 ;;------------------------------------------------------------------------------
3254 (define-gdal-foreign %gdal-get-overview-count
3255 int "GDALGetOverviewCount" (list '*) 20)
3257 (define (get-overview-count h-band)
3258 "Return the number of overview layers available.
3261 h-band: a handle representing GDALRasterBandH."
3262 (%gdal-get-overview-count h-band))
3264 (export get-overview-count)
3266 ;;------------------------------------------------------------------------------
3268 (define-gdal-foreign %gdal-get-overview
3269 '* "GDALGetOverview" (list '* int) 20)
3271 (define (get-overview h-band id)
3272 "Fetch overview raster band object.
3275 h-band: a handle representing GDALRasterBandH.
3276 id: overview index between 0 and (- (get-overview-count h-band) 1)"
3277 (%gdal-get-overview h-band id))
3279 (export get-overview)
3281 ;;------------------------------------------------------------------------------
3283 (define-gdal-foreign %gdal-get-raster-no-data-value
3284 double "GDALGetRasterNoDataValue" (list '* '*) 20)
3286 (define (get-raster-no-data-value h-band)
3287 "Fetch the no data value as double for this band, or report an error
3288 to indicate if no value is actually associated with this layer.
3291 h-band: a handle representing GDALRasterBandH."
3292 (let* ((bv-success (make-bytevector (sizeof int)))
3293 (no-data (%gdal-get-raster-no-data-value
3295 (bytevector->pointer bv-success))))
3296 (if (c-bool->boolean (bytevector-sint-ref bv-success
3301 (error "failed to fetch no data value"))))
3303 (export get-raster-no-data-value)
3305 ;;------------------------------------------------------------------------------
3307 (define-gdal-foreign %gdal-set-raster-no-data-value
3308 int "GDALSetRasterNoDataValue" (list '* double) 20)
3310 (define (set-raster-no-data-value h-band no-data)
3311 "Set the no data value for this band.
3314 h-band: a handle representing GDALRasterBandH.
3315 no-data: the value to set."
3316 (let* ((result (%gdal-set-raster-no-data-value
3319 (unless (= result CE_NONE)
3320 (error "failed to set no data"))))
3322 (export set-raster-no-data-value)
3324 ;;------------------------------------------------------------------------------
3326 (define-gdal-foreign %gdal-delete-raster-no-data-value
3327 int "GDALDeleteRasterNoDataValue" (list '*) 20)
3329 (define (delete-raster-no-data-value h-band)
3330 "Remove the no data value for this band.
3333 h-band: a handle representing GDALRasterBandH."
3334 (let ((result (%gdal-delete-raster-no-data-value h-band)))
3335 (unless (= result CE_NONE)
3336 (error "failed to delete no-data value"))))
3338 (export delete-raster-no-data-value)
3340 ;;------------------------------------------------------------------------------
3342 (define-gdal-foreign %gdal-get-raster-category-names
3343 '* "GDALGetRasterCategoryNames" (list '*) 20)
3345 (define (get-raster-category-names h-band)
3346 "Fetch the list of category names for this raster as a list of strings.
3349 h-band: a handle representing GDALRasterBandH."
3350 (pointerpointer->string-list (%gdal-get-raster-category-names h-band)))
3352 (export get-raster-category-names)
3354 ;;------------------------------------------------------------------------------
3356 (define-gdal-foreign %gdal-set-raster-category-names
3357 int "GDALSetRasterCategoryNames" (list '* '*) 20)
3359 (define* (set-raster-category-names h-band #:key (category-names '()))
3360 "Set the category names for this band.
3363 h-band: a handle representing GDALRasterBandH.
3364 category-names (optional): a list of strings for category names. Default is
3365 empty list '() that clears the existing list."
3366 (let ((result (%gdal-set-raster-category-names
3368 (string-list->pointerpointer category-names))))
3369 (unless (= result CE_NONE)
3370 (error "failed to set category names"))))
3372 (export set-raster-category-names)
3374 ;;------------------------------------------------------------------------------
3376 (define-gdal-foreign %gdal-get-raster-minimum
3377 double "GDALGetRasterMinimum" (list '* '*) 20)
3379 (define (get-raster-minimum h-band)
3380 "Return values of minimum value for this band (excluding no data pixels) and
3381 a boolean, to indicate if the returned value is a tight minimum or not,
3385 h-band: a handle representing GDALRasterBandH."
3386 (let* ((bv-success (make-bytevector (sizeof int)))
3387 (minimum (%gdal-get-raster-minimum
3389 (bytevector->pointer bv-success))))
3390 (values minimum (c-bool->boolean
3391 (bytevector-sint-ref bv-success
3396 (export get-raster-minimum)
3398 ;;------------------------------------------------------------------------------
3400 (define-gdal-foreign %gdal-get-raster-maximum
3401 double "GDALGetRasterMaximum" (list '* '*) 20)
3403 (define (get-raster-maximum h-band)
3404 "Return values of maximum value for this band (excluding no data pixels) and
3405 a boolean, to indicate if the returned value is a tight maximum or not,
3409 h-band: a handle representing GDALRasterBandH."
3410 (let* ((bv-success (make-bytevector (sizeof int)))
3411 (maximum (%gdal-get-raster-maximum
3413 (bytevector->pointer bv-success))))
3414 (values maximum (c-bool->boolean
3415 (bytevector-sint-ref bv-success
3420 (export get-raster-maximum)
3422 ;;------------------------------------------------------------------------------
3424 (define-gdal-foreign %gdal-get-raster-statistics
3425 int "GDALGetRasterStatistics" (list '* int int '* '* '* '*) 20)
3427 (define (get-raster-statistics h-band approx-ok force)
3428 "Fetch image statistics as multiple values of minimum, maximum, mean and
3429 standard deviation, respectively.
3432 h-band: a handle representing GDALRasterBandH.
3433 approx-ok: a boolean value. If #t statistics may be computed based on
3434 overviews or a subset of all tiles.
3435 force: a boolean value. if #f statistics will only be returned if it can
3436 be done without rescanning the image."
3437 (let* ((bv-min (make-bytevector (sizeof double)))
3438 (bv-max (make-bytevector (sizeof double)))
3439 (bv-mean (make-bytevector (sizeof double)))
3440 (bv-std-dev (make-bytevector (sizeof double)))
3441 (result (%gdal-get-raster-statistics
3443 (boolean->c-bool approx-ok)
3444 (boolean->c-bool force)
3445 (bytevector->pointer bv-min)
3446 (bytevector->pointer bv-max)
3447 (bytevector->pointer bv-mean)
3448 (bytevector->pointer bv-std-dev))))
3449 (if (= result CE_NONE)
3450 (values (bytevector-ieee-double-ref bv-min 0 (native-endianness))
3451 (bytevector-ieee-double-ref bv-max 0 (native-endianness))
3452 (bytevector-ieee-double-ref bv-mean 0 (native-endianness))
3453 (bytevector-ieee-double-ref bv-std-dev 0 (native-endianness)))
3454 (error "failed to compute raster statistics"))))
3456 (export get-raster-statistics)
3458 ;;------------------------------------------------------------------------------
3460 (define-gdal-foreign %gdal-compute-raster-statistics
3461 int "GDALComputeRasterStatistics" (list '* int '* '* '* '* '* '*) 20)
3463 (define* (compute-raster-statistics h-band approx-ok
3464 #:key (progress-callback '())
3465 (progress-data %null-pointer))
3466 "Compute image statistics as multiple values of minimum, maximum, mean and
3467 standard deviation, respectively. Once computed, the statistics will generally
3468 be \"set\" back on the raster band using \"set-render-statistics\".
3471 h-band: a handle representing GDALRasterBandH.
3472 approx-ok: a boolean value. If #t statistics may be computed based on
3473 overviews or a subset of all tiles.
3474 progress-callback (optional): a function to call to report progress.
3475 progress-data (optional): application data to pass to the progress
3477 (let* ((bv-min (make-bytevector (sizeof double)))
3478 (bv-max (make-bytevector (sizeof double)))
3479 (bv-mean (make-bytevector (sizeof double)))
3480 (bv-std-dev (make-bytevector (sizeof double)))
3481 (result (%gdal-compute-raster-statistics
3483 (boolean->c-bool approx-ok)
3484 (bytevector->pointer bv-min)
3485 (bytevector->pointer bv-max)
3486 (bytevector->pointer bv-mean)
3487 (bytevector->pointer bv-std-dev)
3488 (gdal-progress-func progress-callback)
3490 (if (= result CE_NONE)
3491 (values (bytevector-ieee-double-ref bv-min 0 (native-endianness))
3492 (bytevector-ieee-double-ref bv-max 0 (native-endianness))
3493 (bytevector-ieee-double-ref bv-mean 0 (native-endianness))
3494 (bytevector-ieee-double-ref bv-std-dev 0 (native-endianness)))
3495 (error "failed to compute raster statistics"))))
3497 (export compute-raster-statistics)
3499 ;;------------------------------------------------------------------------------
3501 (define-gdal-foreign %gdal-set-raster-statistics
3502 int "GDALSetRasterStatistics" (list '* double double double double) 20)
3504 (define (set-raster-statistics h-band minimum maximum mean std-dev)
3505 "Set image statistics on band.
3508 h-band: a handle representing GDALRasterBandH.
3509 minimum: minimum pixel value.
3510 maximum: maximum pixel value.
3511 mean: mean (average) of all pixel values.
3512 std-dev: standard deviation of all pixel values."
3513 (let ((result (%gdal-set-raster-statistics
3519 (unless (= result CE_NONE)
3520 (error "failed to set raster statistics"))))
3522 (export set-raster-statistics)
3524 ;;------------------------------------------------------------------------------
3526 (define-gdal-foreign %gdal-raster-band-as-md-array
3527 '* "GDALRasterBandAsMDArray" (list '*) 31)
3529 (define (raster-band-as-md-array h-band)
3530 "Return a view of this raster band as a 2D multidimensional GDALMDArray.
3531 The returned pointer must be released with \"md-array-release\".
3534 h-band: a handle representing GDALRasterBandH."
3535 (%gdal-raster-band-as-md-array h-band))
3537 (export raster-band-as-md-array)
3539 ;;------------------------------------------------------------------------------
3541 (define-gdal-foreign %gdal-get-raster-unit-type
3542 '* "GDALGetRasterUnitType" (list '*) 20)
3544 (define (get-raster-unit-type h-band)
3545 "Return raster unit type as a string.
3548 h-band: a handle representing GDALRasterBandH."
3549 (pointer->string (%gdal-get-raster-unit-type h-band)))
3551 (export get-raster-unit-type)
3553 ;;------------------------------------------------------------------------------
3555 (define-gdal-foreign %gdal-set-raster-unit-type
3556 int "GDALSetRasterUnitType" (list '* '*) 18)
3558 (define (set-raster-unit-type h-band new-value)
3562 h-band: a handle representing GDALRasterBandH.
3563 new-value: the new unit type value."
3564 (unless (= CE_NONE (%gdal-set-raster-unit-type
3566 (string->pointer new-value)))
3567 (error "failed to set raster unit type")))
3569 (export set-raster-unit-type)
3571 ;;------------------------------------------------------------------------------
3573 (define-gdal-foreign %gdal-get-raster-offset
3574 double "GDALGetRasterOffset" (list '* '*) 20)
3576 (define (get-raster-offset h-band)
3577 "Fetch the raster value offset.
3580 h-band: a handle representing GDALRasterBandH."
3581 (let* ((bv-success (make-bytevector (sizeof int)))
3582 (offset (%gdal-get-raster-offset
3584 (bytevector->pointer bv-success))))
3585 (if (c-bool->boolean (bytevector-sint-ref bv-success
3590 (error "failed to get raster offset"))))
3592 (export get-raster-offset)
3594 ;;------------------------------------------------------------------------------
3596 (define-gdal-foreign %gdal-set-raster-offset
3597 int "GDALSetRasterOffset" (list '* double) 20)
3599 (define (set-raster-offset h-band new-offset)
3600 "Set scaling offset.
3603 h-band: a handle representing GDALRasterBandH.
3604 new-offset: the new offset."
3605 (unless (= CE_NONE (%gdal-set-raster-offset
3608 (error "failed to set raster offset")))
3610 (export set-raster-offset)
3612 ;;------------------------------------------------------------------------------
3614 (define-gdal-foreign %gdal-get-raster-scale
3615 double "GDALGetRasterScale" (list '* '*) 20)
3617 (define (get-raster-scale h-band)
3618 "Fetch the raster value scale.
3621 h-band: a handle representing GDALRasterBandH."
3622 (let* ((bv-success (make-bytevector (sizeof int)))
3623 (scale (%gdal-get-raster-scale
3625 (bytevector->pointer bv-success))))
3626 (if (c-bool->boolean (bytevector-sint-ref bv-success
3631 (error "failed to get raster scale"))))
3633 (export get-raster-scale)
3635 ;;------------------------------------------------------------------------------
3637 (define-gdal-foreign %gdal-set-raster-scale
3638 int "GDALSetRasterScale" (list '* double) 20)
3640 (define (set-raster-scale h-band new-scale)
3644 h-band: a handle representing GDALRasterBandH.
3645 new-scale: the new scale."
3646 (unless (= CE_NONE (%gdal-set-raster-scale
3649 (error "failed to set raster scale")))
3651 (export set-raster-scale)
3653 ;;------------------------------------------------------------------------------
3655 (define-gdal-foreign %gdal-compute-raster-min-max
3656 void "GDALComputeRasterMinMax" (list '* int '*) 20)
3658 (define (compute-raster-min-max h-band approx-ok)
3659 "Compute the min/max values for a band and return as values with minimum
3660 and maximum, respectively.
3663 h-band: a handle representing GDALRasterBandH.
3664 approx-ok: #t if an approximate (faster) answer is OK, otherwise #f."
3665 (let ((bv-minmax (make-bytevector (* 2 (sizeof double)))))
3666 (%gdal-compute-raster-min-max h-band
3667 (boolean->c-bool approx-ok)
3668 (bytevector->pointer bv-minmax))
3670 (bytevector-ieee-double-ref bv-minmax
3672 (native-endianness))
3673 (bytevector-ieee-double-ref bv-minmax
3675 (native-endianness)))))
3677 (export compute-raster-min-max)
3679 ;;------------------------------------------------------------------------------
3681 (define-gdal-foreign %gdal-flush-raster-cache
3682 int "GDALFlushRasterCache" (list '*) 20)
3684 (define (flush-raster-cache h-band)
3685 "Flush raster data cache.
3688 h-band: a handle representing GDALRasterBandH."
3689 (unless (= CE_NONE (%gdal-flush-raster-cache h-band))
3690 (error "failed to flush raster cache")))
3692 (export flush-raster-cache)
3694 ;;------------------------------------------------------------------------------
3696 (define-gdal-foreign %gdal-get-raster-histogram-ex
3697 int "GDALGetRasterHistogramEx" (list '* double double int '*
3700 (define* (get-raster-histogram h-band minimum maximum n-buckets
3701 histogram include-out-of-range approx-ok
3702 #:key (progress-callback '())
3703 (progress-data %null-pointer))
3704 "Compute raster histogram.
3707 h-band: a handle representing GDALRasterBandH.
3708 minimum: the lower bound of the histogram.
3709 maximum: the upper bound of the histogram.
3710 n-buckets: the number of buckets in histogram.
3711 histogram: int64 buffer of bytevector into which the histogram totals are
3713 include-out-of-range: if #t values below the histogram range will mapped
3714 into histogram[0], and values above will be mapped into histogram[n-buckets-1]
3715 otherwise out of range values are discarded.
3716 approx-ok: #t if an approximate, or incomplete histogram OK.
3717 progress-callback (optional): a function to call to report progress.
3718 progress-data (optional): application data to pass to the progress
3720 (let ((result (%gdal-get-raster-histogram-ex h-band
3724 (bytevector->pointer histogram)
3726 include-out-of-range)
3727 (boolean->c-bool approx-ok)
3731 (when (= result CE_FAILURE)
3732 (error "failed to get raster histogram"))))
3734 (export get-raster-histogram)
3736 ;;------------------------------------------------------------------------------
3738 (define-gdal-foreign %gdal-get-default-histogram-ex
3739 int "GDALGetDefaultHistogramEx" (list '* '* '* '* '* int '* '*) 20)
3741 (define* (get-default-histogram h-band is-force
3742 #:key (progress-callback '())
3743 (progress-data %null-pointer))
3744 "Fetch default raster histogram. Return values of the lower bound of the
3745 histogram, the upper bound of the histogram, number of buckets and a int
3746 bytevector of histogram, respectively.
3749 h-band: a handle representing GDALRasterBandH.
3750 is-force: #t to force the computation. If #f and no default histogram is
3751 available, the method will return CE_WARNING.
3752 progress-callback (optional): a function to call to report progress.
3753 progress-data (optional): application data to pass to the progress
3755 (let* ((bv-min (make-bytevector (sizeof double)))
3756 (bv-max (make-bytevector (sizeof double)))
3757 (bv-n-buckets (make-bytevector (sizeof int)))
3758 (bv-histogram (make-bytevector (sizeof '*)))
3759 (result (%gdal-get-default-histogram-ex
3761 (bytevector->pointer bv-min)
3762 (bytevector->pointer bv-max)
3763 (bytevector->pointer bv-n-buckets)
3764 (bytevector->pointer bv-histogram)
3770 (if (= result CE_FAILURE)
3771 (error "failed to get default histogram")
3772 (let ((minimum (bytevector-ieee-double-ref
3774 (native-endianness)))
3775 (maximum (bytevector-ieee-double-ref
3777 (native-endianness)))
3778 (n-buckets (bytevector-sint-ref bv-n-buckets
3785 (pointer->list (dereference-pointer
3786 (bytevector->pointer bv-histogram))
3790 (export get-default-histogram)
3792 ;;------------------------------------------------------------------------------
3794 (define-gdal-foreign %gdal-set-default-histogram-ex
3795 int "GDALSetDefaultHistogramEx" (list '* double double int '*) 20)
3797 (define (set-default-histogram h-band minimum maximum n-buckets histogram)
3798 "Set default histogram.
3801 h-band: a handle representing GDALRasterBandH.
3802 minimum: the lower bound of the histogram.
3803 maximum: the upper bound of the histogram.
3804 n-buckets: the number of buckets in histogram.
3805 histogram: the int64 bytevector of the histogram."
3806 (let ((result (%gdal-set-default-histogram-ex
3811 (bytevector->pointer histogram))))
3812 (unless (= result CE_NONE)
3813 (error "failed to set default histogram"))))
3815 (export set-default-histogram)
3817 ;;------------------------------------------------------------------------------
3819 (define-gdal-foreign %gdal-get-random-raster-sample
3820 int "GDALGetRandomRasterSample" (list '* int '*) 20)
3822 (define (get-random-raster-sample h-band count)
3823 "Return a list of random pixels as floating point numbers on the band.
3826 h-band: a handle representing GDALRasterBandH.
3827 count: number of samples."
3828 (let* ((bv-buffer (make-bytevector (* count (sizeof float))))
3829 (real-count (%gdal-get-random-raster-sample
3832 (bytevector->pointer bv-buffer))))
3833 (pointer->list (bytevector->pointer bv-buffer) real-count float)))
3835 (export get-random-raster-sample)
3837 ;;------------------------------------------------------------------------------
3839 (define-gdal-foreign %gdal-get-raster-sample-overview-ex
3840 '* "GDALGetRasterSampleOverviewEx" (list '* int64) 20)
3842 (define (get-raster-sample-overview h-band desired-samples)
3843 "Fetch best sampling overview.
3846 h-band: a handle representing GDALRasterBandH.
3847 desired-samples: the returned band will have at least this many pixels."
3848 (%gdal-get-raster-sample-overview-ex h-band desired-samples))
3850 (export get-raster-sample-overview)
3852 ;;------------------------------------------------------------------------------
3854 (define-gdal-foreign %gdal-fill-raster
3855 int "GDALFillRaster" (list '* double double) 20)
3857 (define* (fill-raster h-band real #:key (imaginary 0))
3858 "Fill this band with a constant value.
3861 h-band: a handle representing GDALRasterBandH.
3862 real: real component of fill value.
3863 imaginary (optional): imaginary component of fill value, defaults to zero."
3864 (let ((result (%gdal-fill-raster h-band real imaginary)))
3865 (unless (= result CE_NONE)
3866 (error "failed to fill raster"))))
3868 (export fill-raster)
3870 ;;------------------------------------------------------------------------------
3872 (define-gdal-foreign %gdal-compute-band-stats
3873 int "GDALComputeBandStats" (list '* int '* '* '* '*) 20)
3875 (define* (compute-band-stats h-band n-sample-step
3876 #:key (progress-callback '())
3877 (progress-data %null-pointer))
3878 "Compute image statistics as multiple values of mean and standard deviation,
3882 h-band: a handle representing GDALRasterBandH.
3883 n-sample-step: a number of sample steps.
3884 progress-callback (optional): a function to call to report progress.
3885 progress-data (optional): application data to pass to the progress
3887 (let* ((bv-mean (make-bytevector (sizeof double)))
3888 (bv-std-dev (make-bytevector (sizeof double)))
3889 (result (%gdal-compute-band-stats
3892 (bytevector->pointer bv-mean)
3893 (bytevector->pointer bv-std-dev)
3894 (gdal-progress-func progress-callback)
3896 (if (= result CE_NONE)
3897 (values (bytevector-ieee-double-ref bv-mean 0 (native-endianness))
3898 (bytevector-ieee-double-ref bv-std-dev 0 (native-endianness)))
3899 (error "failed to compute band statistics"))))
3901 (export compute-band-stats)
3903 ;;------------------------------------------------------------------------------
3905 (define-gdal-foreign %gdal-get-default-rat
3906 '* "GDALGetDefaultRAT" (list '*) 20)
3908 (define (get-default-rat h-band)
3909 "Fetch default Raster Attribute Table. Returns #f if not set.
3912 h-band: a handle representing GDALRasterBandH."
3913 (let ((ptr (%gdal-get-default-rat h-band)))
3914 (if (null-pointer? ptr)
3918 (export get-default-rat)
3920 ;;------------------------------------------------------------------------------
3922 (define-gdal-foreign %gdal-set-default-rat
3923 int "GDALSetDefaultRAT" (list '* '*) 20)
3925 (define (set-default-rat h-band h-rat)
3926 "Set default Raster Attribute Table.
3929 h-band: a handle representing GDALRasterBandH.
3930 h-rat: a handle for raster attribute table to set."
3931 (let ((result (%gdal-set-default-rat h-band h-rat)))
3932 (unless (= result CE_NONE)
3933 (error "failed to set raster attribute table"))))
3935 (export set-default-rat)
3937 ;;------------------------------------------------------------------------------
3939 (define-gdal-foreign %gdal-create-raster-attribute-table
3940 '* "GDALCreateRasterAttributeTable" '() 20)
3942 (define (make-raster-attribute-table)
3943 "Construct empty table."
3944 (%gdal-create-raster-attribute-table))
3946 (export make-raster-attribute-table)
3948 ;;------------------------------------------------------------------------------
3950 (define-gdal-foreign %gdal-destroy-raster-attribute-table
3951 void "GDALDestroyRasterAttributeTable" (list '*) 20)
3953 (define (destroy-raster-attribute-table h-rat)
3955 (%gdal-destroy-raster-attribute-table h-rat))
3957 (export destroy-raster-attribute-table)
3959 ;;------------------------------------------------------------------------------
3961 (define-gdal-foreign %gdal-rat-get-column-count
3962 int "GDALRATGetColumnCount" (list '*) 20)
3964 (define (rat-get-column-count h-rat)
3965 "Fetch table column count.
3968 h-rat: handle representing raster attribute table."
3969 (%gdal-rat-get-column-count h-rat))
3971 (export rat-get-column-count)
3973 ;;------------------------------------------------------------------------------
3975 (define-gdal-foreign %gdal-rat-get-name-of-col
3976 '* "GDALRATGetNameOfCol" (list '* int) 20)
3978 (define (get-rat-name-of-column h-rat i-col)
3979 "Fetch name of indicated column.
3982 h-rat: handle representing raster attribute table.
3983 i-col: column index."
3984 (let ((ptr (%gdal-rat-get-name-of-col h-rat i-col)))
3985 (if (null-pointer? ptr)
3986 (error "failed to get name of column")
3987 (pointer->string ptr))))
3989 (export get-rat-name-of-column)
3991 ;;------------------------------------------------------------------------------
3993 (define-gdal-foreign %gdal-rat-get-usage-of-col
3994 int "GDALRATGetUsageOfCol" (list '* int) 20)
3996 (define (rat-get-usage-of-column h-rat i-col)
3997 "Fetch column usage value. See GFU_* enums for possible values.
4000 h-rat: handle representing raster attribute table.
4001 i-col: column index."
4002 (%gdal-rat-get-usage-of-col h-rat i-col))
4004 (export rat-get-usage-of-column)
4006 ;;------------------------------------------------------------------------------
4008 (define-gdal-foreign %gdal-rat-get-type-of-col
4009 int "GDALRATGetTypeOfCol" (list '* int) 20)
4011 (define (rat-get-type-of-column h-rat i-col)
4012 "Fetch column type. See GFT_* enums for possible values.
4015 h-rat: handle representing raster attribute table.
4016 i-col: column index."
4017 (%gdal-rat-get-usage-of-col h-rat i-col))
4019 (export rat-get-type-of-column)
4021 ;;------------------------------------------------------------------------------
4023 (define-gdal-foreign %gdal-rat-get-col-of-usage
4024 int "GDALRATGetColOfUsage" (list '* int) 20)
4026 (define (rat-get-col-of-usage h-rat usage)
4027 "Fetch column index for given usage.
4030 h-rat: handle representing raster attribute table.
4031 usage: field usage. see GFU_* enums for possible values"
4032 (%gdal-rat-get-col-of-usage h-rat usage))
4034 (export rat-get-col-of-usage)
4036 ;;------------------------------------------------------------------------------
4038 (define-gdal-foreign %gdal-rat-get-row-count
4039 int "GDALRATGetRowCount" (list '*) 20)
4041 (define (rat-get-row-count h-rat)
4042 "Fetch table row count.
4045 h-rat: handle representing raster attribute table."
4046 (%gdal-rat-get-row-count h-rat))
4048 (export rat-get-row-count)
4050 ;;------------------------------------------------------------------------------
4052 (define-gdal-foreign %gdal-rat-get-value-as-string
4053 '* "GDALRATGetValueAsString" (list '* int int) 20)
4055 (define (rat-get-value-as-string h-rat i-row i-field)
4056 "Fetch field value as a string.
4059 h-rat: handle representing raster attribute table.
4061 i-field: column index"
4062 (let ((ptr (%gdal-rat-get-value-as-string h-rat i-row i-field)))
4063 (if (null-pointer? ptr)
4064 (error "failed to get value as string")
4065 (pointer->string ptr))))
4067 (export rat-get-value-as-string)
4069 ;;------------------------------------------------------------------------------
4071 (define-gdal-foreign %gdal-rat-get-value-as-int
4072 int "GDALRATGetValueAsInt" (list '* int int) 20)
4074 (define (rat-get-value-as-int h-rat i-row i-field)
4075 "Fetch field value as an integer.
4078 h-rat: handle representing raster attribute table.
4080 i-field: column index."
4081 (%gdal-rat-get-value-as-int h-rat i-row i-field))
4083 (export rat-get-value-as-int)
4085 ;;------------------------------------------------------------------------------
4087 (define-gdal-foreign %gdal-rat-get-value-as-double
4088 double "GDALRATGetValueAsDouble" (list '* int int) 20)
4090 (define (rat-get-value-as-double h-rat i-row i-field)
4091 "Fetch field value as a double.
4094 h-rat: handle representing raster attribute table.
4096 i-field: column index."
4097 (%gdal-rat-get-value-as-double h-rat i-row i-field))
4099 (export rat-get-value-as-double)
4101 ;;------------------------------------------------------------------------------
4103 (define-gdal-foreign %gdal-rat-set-value-as-string
4104 void "GDALRATSetValueAsString" (list '* int int '*) 20)
4106 (define (rat-set-value-as-string h-rat i-row i-field value)
4107 "Set field value from string.
4110 h-rat: handle representing raster attribute table.
4112 i-field: column index.
4113 value: string value to set."
4114 (%gdal-rat-set-value-as-string h-rat i-row i-field (string->pointer value)))
4116 (export rat-set-value-as-string)
4118 ;;------------------------------------------------------------------------------
4120 (define-gdal-foreign %gdal-rat-set-value-as-int
4121 void "GDALRATSetValueAsInt" (list '* int int int) 20)
4123 (define (rat-set-value-as-int h-rat i-row i-field value)
4124 "Set field value from integer.
4127 h-rat: handle representing raster attribute table.
4129 i-field: column index.
4130 value: integer value to set."
4131 (%gdal-rat-set-value-as-int h-rat i-row i-field value))
4133 (export rat-set-value-as-int)
4135 ;;------------------------------------------------------------------------------
4137 (define-gdal-foreign %gdal-rat-set-value-as-double
4138 void "GDALRATSetValueAsDouble" (list '* int int double) 20)
4140 (define (rat-set-value-as-double h-rat i-row i-field value)
4141 "Set field value from double.
4144 h-rat: handle representing raster attribute table.
4146 i-field: column index.
4147 value: double value to set."
4148 (%gdal-rat-set-value-as-double h-rat i-row i-field value))
4150 (export rat-set-value-as-double)
4152 ;;------------------------------------------------------------------------------
4154 (define-gdal-foreign %gdal-rat-changes-are-written-to-file
4155 int "GDALRATChangesAreWrittenToFile" (list '*) 20)
4157 (define (rat-changes-are-written-to-file h-rat)
4158 "Determine whether changes made to this RAT are reflected directly
4162 h-rat: handle representing raster attribute table."
4163 (c-bool->boolean (%gdal-rat-changes-are-written-to-file h-rat)))
4165 (export rat-changes-are-written-to-file)
4167 ;;------------------------------------------------------------------------------
4169 (define-gdal-foreign %gdal-rat-values-io-as-double
4170 int "GDALRATValuesIOAsDouble" (list '* int int int int '*) 20)
4172 (define (rat-read-values-as-double h-rat i-field i-start-row i-length)
4173 "Read a block of doubles from the Attribute Table.
4176 h-rat: handle representing raster attribute table.
4177 i-field: column index.
4178 i-start-row: row index to start reading (zero based).
4179 i-length: number of rows to read."
4180 (let* ((bv (make-bytevector (* i-length (sizeof double))))
4181 (result (%gdal-rat-values-io-as-double h-rat GF_READ
4184 (bytevector->pointer bv))))
4185 (if (= result CE_FAILURE)
4186 (error "failed to read values as doubles")
4187 (pointer->list (bytevector->pointer bv) i-length double))))
4189 (export rat-read-values-as-double)
4191 (define (rat-write-values-as-double h-rat i-field i-start-row lst)
4192 "Write a block of doubles to the Attribute Table.
4195 h-rat: handle representing raster attribute table.
4196 i-field: column index.
4197 i-start-row: row index to start writing (zero based).
4198 lst: list of doubles to write."
4199 (let ((result (%gdal-rat-values-io-as-double
4203 (list->pointer lst double))))
4204 (if (= result CE_FAILURE)
4205 (error "failed to write values as doubles"))))
4207 (export rat-write-values-as-double)
4209 ;;------------------------------------------------------------------------------
4211 (define-gdal-foreign %gdal-rat-values-io-as-integer
4212 int "GDALRATValuesIOAsInteger" (list '* int int int int '*) 20)
4214 (define (rat-read-values-as-integer h-rat i-field i-start-row i-length)
4215 "Read a block of integers from the Attribute Table.
4218 h-rat: handle representing raster attribute table.
4219 i-field: column index.
4220 i-start-row: row index to start reading (zero based).
4221 i-length: number of rows to read."
4222 (let* ((bv (make-bytevector (* i-length (sizeof int))))
4223 (result (%gdal-rat-values-io-as-integer h-rat GF_READ
4226 (bytevector->pointer bv))))
4227 (if (= result CE_FAILURE)
4228 (error "failed to read values as integers")
4229 (bytevector->sint-list bv (native-endianness) i-length))))
4231 (export rat-read-values-as-integer)
4233 (define (rat-write-values-as-integer h-rat i-field i-start-row lst)
4234 "Write a block of integers to the Attribute Table.
4237 h-rat: handle representing raster attribute table.
4238 i-field: column index.
4239 i-start-row: row index to start writing (zero based).
4240 lst: list of integers to write."
4241 (let ((result (%gdal-rat-values-io-as-integer
4245 (sint-list->bytevector lst (native-endianness)
4247 (if (= result CE_FAILURE)
4248 (error "failed to write values as integers"))))
4250 (export rat-write-values-as-integer)
4252 ;;------------------------------------------------------------------------------
4254 (define-gdal-foreign %gdal-rat-values-io-as-string
4255 int "GDALRATValuesIOAsString" (list '* int int int int '*) 20)
4257 (define (rat-read-values-as-string h-rat i-field i-start-row i-length)
4258 "Read a block of strings from the Attribute Table.
4261 h-rat: handle representing raster attribute table.
4262 i-field: column index.
4263 i-start-row: row index to start reading (zero based).
4264 i-length: number of rows to read."
4265 (let* ((bv (make-bytevector (* i-length (sizeof '*))))
4266 (result (%gdal-rat-values-io-as-string h-rat GF_READ
4269 (bytevector->pointer bv))))
4270 (if (= result CE_FAILURE)
4271 (error "failed to read values as strings")
4272 (pointerpointer->string-list (bytevector->pointer bv)))))
4274 (export rat-read-values-as-string)
4276 (define (rat-write-values-as-string h-rat i-field i-start-row lst)
4277 "Write a block of strings to the Attribute Table.
4280 h-rat: handle representing raster attribute table.
4281 i-field: column index.
4282 i-start-row: row index to start writing (zero based).
4283 lst: list of strings to write."
4284 (let ((result (%gdal-rat-values-io-as-string
4288 (string-list->pointerpointer lst))))
4289 (if (= result CE_FAILURE)
4290 (error "failed to write values as strings"))))
4292 (export rat-write-values-as-string)
4294 ;;------------------------------------------------------------------------------
4296 (define-gdal-foreign %gdal-rat-set-row-count
4297 void "GDALRATSetRowCount" (list '* int) 20)
4299 (define (rat-set-row-count h-rat new-count)
4303 h-rat: handle representing raster attribute table.
4304 new-count: the new number of rows."
4305 (%gdal-rat-set-row-count h-rat new-count))
4307 (export rat-set-row-count)
4309 ;;------------------------------------------------------------------------------
4311 (define-gdal-foreign %gdal-rat-create-column
4312 int "GDALRATCreateColumn" (list '* '* int int) 20)
4314 (define (rat-create-column h-rat field-name field-type field-usage)
4315 "Create new column. If the table already has rows, all row values for the
4316 new column will be initialized to the default value (\"\", or zero). The new
4317 column is always created as the last column, column index will be
4318 \"(- (get-column-count) 1)\" after rat-create-column has completed successfully.
4321 h-rat: handle representing raster attribute table.
4322 field-name: the name of the field to create.
4323 field-type: the field type. see GFT_* enums for possible values.
4324 field-usage: the field usage. see GFU_* enums for possible values."
4325 (let ((result (%gdal-rat-create-column h-rat (string->pointer field-name)
4328 (if (= result CE_FAILURE)
4329 (error "failed to create column"))))
4331 (export rat-create-column)
4333 ;;------------------------------------------------------------------------------
4335 (define-gdal-foreign %gdal-rat-set-linear-binning
4336 int "GDALRATSetLinearBinning" (list '* double double) 20)
4338 (define (rat-set-linear-binning h-rat row-min bin-size)
4339 "Set linear binning information.
4341 For RATs with equal sized categories (in pixel value space) that are evenly
4342 spaced, this method may be used to associate the linear binning information
4346 h-rat: handle representing raster attribute table.
4347 row-min: the lower bound (pixel value) of the first category.
4348 bin-size:the width of each category (in pixel value units)."
4349 (let ((result (%gdal-rat-set-linear-binning h-rat row-min bin-size)))
4350 (if (= result CE_FAILURE)
4351 (error "failed to set linear binning information"))))
4353 (export rat-set-linear-binning)
4355 ;;------------------------------------------------------------------------------
4357 (define-gdal-foreign %gdal-rat-get-linear-binning
4358 int "GDALRATGetLinearBinning" (list '* '* '*) 20)
4360 (define (rat-get-linear-binning h-rat)
4361 "Get linear binning information. Returns values of (#t, row-min, bin-size)
4362 if linear binning information exists or (values #f 0.0 0.0) if there is none.
4363 row-min is the lower bound (pixel value) of the first category, and bin-size
4364 is the width of each category (in pixel value units).
4367 h-rat: handle representing raster attribute table."
4368 (let* ((row-min ((make-bytevector (sizeof double))))
4369 (bin-size ((make-bytevector (sizeof double))))
4370 (result (%gdal-rat-get-linear-binning h-rat
4371 (bytevector->pointer row-min)
4372 (bytevector->pointer bin-size))))
4373 (if (c-bool->boolean result)
4375 (bytevector-ieee-double-ref row-min 0 (native-endianness))
4376 (bytevector-ieee-double-ref bin-size 0 (native-endianness)))
4377 (values #f 0.0 0.0))))
4379 (export rat-get-linear-binning)
4381 ;;------------------------------------------------------------------------------
4383 (define-gdal-foreign %gdal-rat-set-table-type
4384 int "GDALRATSetTableType" (list '* int) 24)
4386 (define (rat-set-table-type h-rat table-type)
4387 "Set whether the RAT is thematic or athematic (continuous).
4390 h-rat: handle for raster attribute table to set.
4391 table-type: table type to set."
4392 (let ((result (%gdal-rat-set-table-type h-rat table-type)))
4393 (unless (= result CE_NONE)
4394 (error "failed to set table type"))))
4396 (export rat-set-table-type)
4398 ;;------------------------------------------------------------------------------
4400 (define-gdal-foreign %gdal-rat-get-table-type
4401 int "GDALRATGetTableType" (list '*) 24)
4403 (define (rat-get-table-type h-rat)
4404 "Indicates whether the RAT is thematic or athematic (continuous).
4407 h-rat: handle representing raster attribute table."
4408 (%gdal-rat-get-table-type h-rat))
4410 (export rat-get-table-type)
4412 ;;------------------------------------------------------------------------------
4414 (define-gdal-foreign %gdal-rat-initialize-from-color-table
4415 int "GDALRATInitializeFromColorTable" (list '* '*) 20)
4417 (define (make-rat-from-color-table h-rat h-table)
4418 "Initialize from color table.
4420 This method will setup a whole raster attribute table based on the contents of
4421 the passed color table. The Value (GFU_MIN_MAX), Red (GFU_RED),
4422 Green (GFU_GREEN), Blue (GFU_BLUE), and Alpha (GFU_ALPHA) fields are created,
4423 and a row is set for each entry in the color table.
4425 The raster attribute table must be empty before calling
4426 make-rat-from-color-table
4428 The Value fields are set based on the implicit assumption with color tables
4429 that entry 0 applies to pixel value 0, 1 to 1, etc.
4432 h-rat: handle for raster attribute table to set.
4433 h-table: color table to copy from."
4434 (let ((result (%gdal-rat-initialize-from-color-table h-rat h-table)))
4435 (unless (= result CE_NONE)
4436 (error "failed to make rat from color table"))))
4438 (export make-rat-from-color-table)
4440 ;;------------------------------------------------------------------------------
4442 (define-gdal-foreign %gdal-rat-translate-to-color-table
4443 '* "GDALRATTranslateToColorTable" (list '* int) 20)
4445 (define (rat-translate-to-color-table h-rat entry-count)
4446 "Translate to a color table.
4449 h-rat: handle representing raster attribute table.
4450 entry-count: the number of entries to produce (0 to entry-count - 1)."
4451 (let ((result (%gdal-rat-translate-to-color-table h-rat entry-count)))
4452 (if (null-pointer? result)
4453 (error "failed to translate to color table")
4456 (export rat-translate-to-color-table)
4458 ;;------------------------------------------------------------------------------
4460 (define-gdal-foreign %gdal-rat-clone
4461 '* "GDALRATClone" (list '*) 20)
4463 (define (clone-rat h-rat)
4464 "Copy Raster Attribute Table.
4467 h-rat: handle representing raster attribute table."
4468 (%gdal-rat-clone h-rat))
4472 ;;------------------------------------------------------------------------------
4474 (define-gdal-foreign %gdal-rat-get-row-of-value
4475 int "GDALRATGetRowOfValue" (list '* double) 20)
4477 (define (rat-get-row-of-value h-rat value)
4478 "Get row for pixel value.
4480 Given a raw pixel value, the raster attribute table is scanned to determine
4481 which row in the table applies to the pixel value. The row index is returned.
4484 h-rat: handle representing raster attribute table.
4485 value: the pixel value."
4486 (%gdal-rat-get-row-of-value h-rat value))
4488 (export rat-get-row-of-value)
4490 ;;------------------------------------------------------------------------------
4492 (define-gdal-foreign %gdal-rat-remove-statistics
4493 void "GDALRATRemoveStatistics" (list '*) 24)
4495 (define (rat-remove-statistics h-rat)
4496 "Remove statistics from the RAT.
4499 h-rat: handle representing raster attribute table."
4500 (%gdal-rat-remove-statistics h-rat))
4502 (export rat-remove-statistics)
4504 ;;------------------------------------------------------------------------------
4506 (define-gdal-foreign %gdal-set-cache-max
4507 void "GDALSetCacheMax" (list int) 20)
4509 (define (set-cache-max new-size-in-bytes)
4510 "Set maximum cache memory.
4512 This function sets the maximum amount of memory that GDAL is permitted to use
4513 for GDALRasterBlock caching. The unit of the value is bytes.
4515 The maximum value is 2GB, due to the use of a signed 32 bit integer.
4518 new-size-in-bytes: the maximum number of bytes for caching."
4519 (%gdal-set-cache-max new-size-in-bytes))
4521 (export set-cache-max)
4523 ;;------------------------------------------------------------------------------
4525 (define-gdal-foreign %gdal-set-cache-max-64
4526 void "GDALSetCacheMax64" (list int64) 18)
4528 (define (set-cache-max-64 new-size-in-bytes)
4529 "Set maximum cache memory.
4531 This function sets the maximum amount of memory that GDAL is permitted to use
4532 for GDALRasterBlock caching. The unit of the value is bytes.
4534 Note: On 32 bit platforms, the maximum amount of memory that can be addressed
4535 by a process might be 2 GB or 3 GB, depending on the operating system
4536 capabilities. This function will not make any attempt to check the consistency
4537 of the passed value with the effective capabilities of the OS.
4540 new-size-in-bytes: the maximum number of bytes for caching."
4541 (%gdal-set-cache-max-64 new-size-in-bytes))
4543 (export set-cache-max-64)
4545 ;;------------------------------------------------------------------------------
4547 (define-gdal-foreign %gdal-get-cache-max
4548 int "GDALGetCacheMax" '() 20)
4550 (define (get-cache-max)
4551 "Get maximum cache memory.
4553 Gets the maximum amount of memory available to the GDALRasterBlock caching
4554 system for caching GDAL read/write imagery.
4556 The first type this function is called, it will read the GDAL_CACHEMAX
4557 configuration option to initialize the maximum cache memory. Starting with
4558 GDAL 2.1, the value can be expressed as x% of the usable physical RAM
4559 (which may potentially be used by other processes). Otherwise it is expected to
4562 This function cannot return a value higher than 2 GB. Use get-cache-max-64 to
4563 get a non-truncated value."
4564 (%gdal-get-cache-max))
4566 (export get-cache-max)
4568 ;;------------------------------------------------------------------------------
4570 (define-gdal-foreign %gdal-get-cache-max-64
4571 int64 "GDALGetCacheMax64" '() 18)
4573 (define (get-cache-max-64)
4574 "Get maximum cache memory.
4576 Gets the maximum amount of memory available to the GDALRasterBlock caching
4577 system for caching GDAL read/write imagery.
4579 The first type this function is called, it will read the GDAL_CACHEMAX
4580 configuration option to initialize the maximum cache memory. Starting with
4581 GDAL 2.1, the value can be expressed as x% of the usable physical RAM
4582 (which may potentially be used by other processes). Otherwise it is expected
4583 to be a value in MB."
4584 (%gdal-get-cache-max-64))
4586 (export get-cache-max-64)
4588 ;;------------------------------------------------------------------------------
4590 (define-gdal-foreign %gdal-get-cache-used
4591 int "GDALGetCacheUsed" '() 20)
4593 (define (get-cache-used)
4594 "Get cache memory used."
4595 (%gdal-get-cache-used))
4597 (export get-cache-used)
4599 ;;------------------------------------------------------------------------------
4601 (define-gdal-foreign %gdal-get-cache-used-64
4602 int64 "GDALGetCacheUsed64" '() 18)
4604 (define (get-cache-used-64)
4605 "Get cache memory used."
4606 (%gdal-get-cache-used-64))
4608 (export get-cache-used-64)
4610 ;;------------------------------------------------------------------------------
4612 (define-gdal-foreign %gdal-flush-cache-block
4613 int "GDALFlushCacheBlock" '() 20)
4615 (define (flush-cache-block)
4616 "Try to flush one cached raster block.
4618 This function will search the first unlocked raster block and will flush it to
4619 release the associated memory.
4621 Returns #t if one block was flushed, #f if there are no cached blocks or if
4622 they are currently locked."
4623 (c-bool->boolean (%gdal-flush-cache-block)))
4625 (export flush-cache-block)
4627 ;;------------------------------------------------------------------------------
4629 (define-gdal-foreign %gdal-create-multi-multidimensional
4630 '* "GDALCreateMultiDimensional" (list '* '* '* '*) 31)
4632 (define* (make-multidimensional-dataset h-driver file-name #:key
4633 (root-group-options '())
4635 "Create a new multidimensional dataset with this driver.
4637 Only drivers that advertise the GDAL_DCAP_MULTIDIM_RASTER capability and
4638 implement the pfnCreateMultiDimensional method might return a non nullptr
4642 file-name: the name of the dataset to create.
4643 root-group-options (optional): driver specific options regarding the
4644 creation of the root group.
4645 options (optional): driver specific options regarding the creation of the
4647 (let ((ptr (%gdal-create-multi-multidimensional
4649 (string->pointer file-name)
4650 (string-list->pointerpointer root-group-options)
4651 (string-list->pointerpointer options))))
4652 (if (null-pointer? ptr)
4653 (error "failed to create multidimensional dataset")
4656 (export make-multidimensional-dataset)
4658 ;;------------------------------------------------------------------------------
4660 (define-gdal-foreign %gdal-group-get-vector-layer-names
4661 '* "GDALGroupGetVectorLayerNames" (list '* '*) 34)
4663 (define* (group-get-vector-layer-names h-group #:key
4665 "Return the list of layer names contained in this group.
4668 h-group: handle of the group.
4669 options (optional): driver specific options determining how layers should
4671 (let ((ptr (%gdal-group-get-vector-layer-names
4673 (string-list->pointerpointer options))))
4674 (pointerpointer->string-list ptr)))
4676 (export group-get-vector-layer-names)
4678 ;;------------------------------------------------------------------------------