PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ rt_band_new_offline_from_path()

rt_band rt_band_new_offline_from_path ( uint16_t  width,
uint16_t  height,
int  hasnodata,
double  nodataval,
uint8_t  bandNum,
const char *  path,
int  force 
)

Create an out-db rt_band from path.

Parameters
width: number of pixel columns
height: number of pixel rows
hasnodata: indicates if the band has nodata value
nodataval: the nodata value, will be appropriately
bandNum: 1-based band number in the external file to associate this band with.
path: NULL-terminated path string pointing to the file containing band data. The string will NOT be copied, ownership is left to caller which is responsible to keep it allocated for the whole lifetime of the returned rt_band.
force: if True, ignore all validation checks
Returns
an rt_band, or 0 on failure

Definition at line 358 of file rt_band.c.

366 {
367 GDALDatasetH hdsSrc = NULL;
368 int nband = 0;
369 GDALRasterBandH hbandSrc = NULL;
370
371 GDALDataType gdpixtype;
372 rt_pixtype pt = PT_END;
373
374 /* open outdb raster file */
376 hdsSrc = rt_util_gdal_open(path, GA_ReadOnly, 1);
377 if (hdsSrc == NULL && !force) {
378 rterror("rt_band_new_offline_from_path: Cannot open offline raster: %s", path);
379 return NULL;
380 }
381
382 nband = GDALGetRasterCount(hdsSrc);
383 if (!nband && !force) {
384 rterror("rt_band_new_offline_from_path: No bands found in offline raster: %s", path);
385 GDALClose(hdsSrc);
386 return NULL;
387 }
388 /* bandNum is 1-based */
389 else if (bandNum > nband && !force) {
390 rterror(
391 "rt_band_new_offline_from_path: Specified band %d not found in offline raster: %s",
392 bandNum,
393 path
394 );
395 GDALClose(hdsSrc);
396 return NULL;
397 }
398
399 hbandSrc = GDALGetRasterBand(hdsSrc, bandNum);
400 if (hbandSrc == NULL && !force) {
401 rterror(
402 "rt_band_new_offline_from_path: Cannot get band %d from GDAL dataset",
403 bandNum
404 );
405 GDALClose(hdsSrc);
406 return NULL;
407 }
408
409 gdpixtype = GDALGetRasterDataType(hbandSrc);
410 pt = rt_util_gdal_datatype_to_pixtype(gdpixtype);
411 if (pt == PT_END && !force) {
412 rterror(
413 "rt_band_new_offline_from_path: Unsupported pixel type %s of band %d from GDAL dataset",
414 GDALGetDataTypeName(gdpixtype),
415 bandNum
416 );
417 GDALClose(hdsSrc);
418 return NULL;
419 }
420
421 /* use out-db band's nodata value if nodataval not already set */
422 if (!hasnodata)
423 nodataval = GDALGetRasterNoDataValue(hbandSrc, &hasnodata);
424
425 GDALClose(hdsSrc);
426
427 return rt_band_new_offline(
428 width, height,
429 pt,
430 hasnodata, nodataval,
431 bandNum - 1, path
432 );
433}
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
rt_pixtype rt_util_gdal_datatype_to_pixtype(GDALDataType gdt)
Convert GDALDataType to rt_pixtype.
Definition rt_util.c:255
int rt_util_gdal_register_all(int force_register_all)
Definition rt_util.c:444
rt_pixtype
Definition librtcore.h:188
@ PT_END
Definition librtcore.h:201
GDALDatasetH rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared)
Definition rt_util.c:491
nband
Definition pixval.py:56
rt_band rt_band_new_offline(uint16_t width, uint16_t height, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, uint8_t bandNum, const char *path)
Create an out-db rt_band.
Definition rt_band.c:283

References PT_END, rt_band_new_offline(), rt_util_gdal_datatype_to_pixtype(), rt_util_gdal_open(), rt_util_gdal_register_all(), and rterror().

Referenced by RASTER_addBandOutDB(), RASTER_setBandPath(), and test_band_new_offline_from_path().

Here is the call graph for this function:
Here is the caller graph for this function: