Load offline band's data.
Loaded data is internally owned and should not be released by the caller. Data will be released when band is destroyed with rt_band_destroy().
429 {
430 GDALDatasetH hdsSrc = NULL;
432 VRTDatasetH hdsDst = NULL;
433 VRTSourcedRasterBandH hbandDst = NULL;
434 double ogt[6] = {0};
435 double offset[2] = {0};
436
439 int aligned = 0;
441
442 assert(band != NULL);
443 assert(
band->raster != NULL);
444
445 if (!
band->offline) {
446 rterror(
"rt_band_load_offline_data: Band is not offline");
448 }
449 else if (!strlen(
band->data.offline.path)) {
450 rterror(
"rt_band_load_offline_data: Offline band does not a have a specified file");
452 }
453
454
456 rterror(
"rt_band_load_offline_data: Access to offline bands disabled");
458 }
459
462 if (hdsSrc == NULL) {
463 rterror(
"rt_band_load_offline_data: Cannot open offline raster: %s",
band->data.offline.path);
465 }
466
467
468 nband = GDALGetRasterCount(hdsSrc);
469 if (!nband) {
470 rterror(
"rt_band_load_offline_data: No bands found in offline raster: %s",
band->data.offline.path);
471 GDALClose(hdsSrc);
473 }
474
475 else if (
band->data.offline.bandNum + 1 > nband) {
476 rterror(
"rt_band_load_offline_data: Specified band %d not found in offline raster: %s",
band->data.offline.bandNum,
band->data.offline.path);
477 GDALClose(hdsSrc);
479 }
480
481
482 if (GDALGetGeoTransform(hdsSrc, ogt) != CE_None) {
483 RASTER_DEBUG(4,
"Using default geotransform matrix (0, 1, 0, 0, 0, -1)");
484 ogt[0] = 0;
485 ogt[1] = 1;
486 ogt[2] = 0;
487 ogt[3] = 0;
488 ogt[4] = 0;
489 ogt[5] = -1;
490 }
491 RASTER_DEBUGF(3,
"Offline geotransform (%f, %f, %f, %f, %f, %f)",
492 ogt[0], ogt[1], ogt[2], ogt[3], ogt[4], ogt[5]);
493
494
500
502 rterror(
"rt_band_load_offline_data: Could not test alignment of in-db representation of out-db raster");
503 GDALClose(hdsSrc);
505 }
506 else if (!aligned) {
507 rtwarn(
"The in-db representation of the out-db raster is not aligned. Band data may be incorrect");
508 }
509
510
513 ogt[0], ogt[3],
514 &(offset[0]), &(offset[1]),
515 NULL
516 );
517
519
520
521 hdsDst = VRTCreate(
band->width,
band->height);
522 GDALSetGeoTransform(hdsDst, ogt);
523
524
525
526
527
529 hbandDst = (VRTSourcedRasterBandH) GDALGetRasterBand(hdsDst, 1);
530
532 GDALSetRasterNoDataValue(hbandDst,
band->nodataval);
533
534 VRTAddSimpleSource(
535 hbandDst, GDALGetRasterBand(hdsSrc,
band->data.offline.bandNum + 1),
536 fabs(offset[0]), fabs(offset[1]),
538 0, 0,
540 "near", VRT_NODATA_UNSET
541 );
542
543
544 VRTFlushCache(hdsDst);
545
546
548
549 GDALClose(hdsDst);
550 GDALClose(hdsSrc);
551
552
553
554
555
556
557
558
559
560 if (_rast == NULL) {
561 rterror(
"rt_band_load_offline_data: Cannot load data from offline raster: %s",
band->data.offline.path);
563 }
564
566 if (_band == NULL) {
567 rterror(
"rt_band_load_offline_data: Cannot load data from offline raster: %s",
band->data.offline.path);
570 }
571
572
573 if (
band->data.offline.mem != NULL) {
575 band->data.offline.mem = NULL;
576 }
577
579
582
584}
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
#define RASTER_DEBUG(level, msg)
int rt_util_gdal_register_all(int force_register_all)
#define RASTER_DEBUGF(level, msg,...)
void rt_raster_set_geotransform_matrix(rt_raster raster, double *gt)
Set raster's geotransform using 6-element array.
rt_errorstate rt_raster_geopoint_to_cell(rt_raster raster, double xw, double yw, double *xr, double *yr, double *igt)
Convert an xw, yw map point to a xr, yr raster point.
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
GDALDataType rt_util_pixtype_to_gdal_datatype(rt_pixtype pt)
Convert rt_pixtype to GDALDataType.
rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds)
Return a raster from a GDAL dataset.
void rtwarn(const char *fmt,...)
GDALDatasetH rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared)
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
void rtdealloc(void *mem)
rt_errorstate rt_raster_same_alignment(rt_raster rast1, rt_raster rast2, int *aligned, char **reason)
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
char enable_outdb_rasters