PostGIS  2.5.7dev-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 199 of file rt_band.c.

207  {
208  GDALDatasetH hdsSrc = NULL;
209  int nband = 0;
210  GDALRasterBandH hbandSrc = NULL;
211 
212  GDALDataType gdpixtype;
213  rt_pixtype pt = PT_END;
214 
215  /* open outdb raster file */
217  hdsSrc = rt_util_gdal_open(path, GA_ReadOnly, 1);
218  if (hdsSrc == NULL && !force) {
219  rterror("rt_band_new_offline_from_path: Cannot open offline raster: %s", path);
220  return NULL;
221  }
222 
223  nband = GDALGetRasterCount(hdsSrc);
224  if (!nband && !force) {
225  rterror("rt_band_new_offline_from_path: No bands found in offline raster: %s", path);
226  GDALClose(hdsSrc);
227  return NULL;
228  }
229  /* bandNum is 1-based */
230  else if (bandNum > nband && !force) {
231  rterror(
232  "rt_band_new_offline_from_path: Specified band %d not found in offline raster: %s",
233  bandNum,
234  path
235  );
236  GDALClose(hdsSrc);
237  return NULL;
238  }
239 
240  hbandSrc = GDALGetRasterBand(hdsSrc, bandNum);
241  if (hbandSrc == NULL && !force) {
242  rterror(
243  "rt_band_new_offline_from_path: Cannot get band %d from GDAL dataset",
244  bandNum
245  );
246  GDALClose(hdsSrc);
247  return NULL;
248  }
249 
250  gdpixtype = GDALGetRasterDataType(hbandSrc);
251  pt = rt_util_gdal_datatype_to_pixtype(gdpixtype);
252  if (pt == PT_END && !force) {
253  rterror(
254  "rt_band_new_offline_from_path: Unsupported pixel type %s of band %d from GDAL dataset",
255  GDALGetDataTypeName(gdpixtype),
256  bandNum
257  );
258  GDALClose(hdsSrc);
259  return NULL;
260  }
261 
262  /* use out-db band's nodata value if nodataval not already set */
263  if (!hasnodata)
264  nodataval = GDALGetRasterNoDataValue(hbandSrc, &hasnodata);
265 
266  GDALClose(hdsSrc);
267 
268  return rt_band_new_offline(
269  width, height,
270  pt,
271  hasnodata, nodataval,
272  bandNum - 1, path
273  );
274 }
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
rt_pixtype rt_util_gdal_datatype_to_pixtype(GDALDataType gdt)
Convert GDALDataType to rt_pixtype.
Definition: rt_util.c:153
int rt_util_gdal_register_all(int force_register_all)
Definition: rt_util.c:336
rt_pixtype
Definition: librtcore.h:185
@ PT_END
Definition: librtcore.h:197
GDALDatasetH rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared)
Definition: rt_util.c:381
nband
Definition: pixval.py:52
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:124

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: