PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ 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 350 of file rt_band.c.

358  {
359  GDALDatasetH hdsSrc = NULL;
360  int nband = 0;
361  GDALRasterBandH hbandSrc = NULL;
362 
363  GDALDataType gdpixtype;
364  rt_pixtype pt = PT_END;
365 
366  /* open outdb raster file */
368  hdsSrc = rt_util_gdal_open(path, GA_ReadOnly, 1);
369  if (hdsSrc == NULL && !force) {
370  rterror("rt_band_new_offline_from_path: Cannot open offline raster: %s", path);
371  return NULL;
372  }
373 
374  nband = GDALGetRasterCount(hdsSrc);
375  if (!nband && !force) {
376  rterror("rt_band_new_offline_from_path: No bands found in offline raster: %s", path);
377  GDALClose(hdsSrc);
378  return NULL;
379  }
380  /* bandNum is 1-based */
381  else if (bandNum > nband && !force) {
382  rterror(
383  "rt_band_new_offline_from_path: Specified band %d not found in offline raster: %s",
384  bandNum,
385  path
386  );
387  GDALClose(hdsSrc);
388  return NULL;
389  }
390 
391  hbandSrc = GDALGetRasterBand(hdsSrc, bandNum);
392  if (hbandSrc == NULL && !force) {
393  rterror(
394  "rt_band_new_offline_from_path: Cannot get band %d from GDAL dataset",
395  bandNum
396  );
397  GDALClose(hdsSrc);
398  return NULL;
399  }
400 
401  gdpixtype = GDALGetRasterDataType(hbandSrc);
402  pt = rt_util_gdal_datatype_to_pixtype(gdpixtype);
403  if (pt == PT_END && !force) {
404  rterror(
405  "rt_band_new_offline_from_path: Unsupported pixel type %s of band %d from GDAL dataset",
406  GDALGetDataTypeName(gdpixtype),
407  bandNum
408  );
409  GDALClose(hdsSrc);
410  return NULL;
411  }
412 
413  /* use out-db band's nodata value if nodataval not already set */
414  if (!hasnodata)
415  nodataval = GDALGetRasterNoDataValue(hbandSrc, &hasnodata);
416 
417  GDALClose(hdsSrc);
418 
419  return rt_band_new_offline(
420  width, height,
421  pt,
422  hasnodata, nodataval,
423  bandNum - 1, path
424  );
425 }
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:162
int rt_util_gdal_register_all(int force_register_all)
Definition: rt_util.c:347
rt_pixtype
Definition: librtcore.h:187
@ PT_END
Definition: librtcore.h:199
GDALDatasetH rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared)
Definition: rt_util.c:394
nband
Definition: pixval.py:54
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:275

References pixval::nband, 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: