PostGIS  2.5.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 195 of file rt_band.c.

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().

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