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().
580 {
581 GDALDatasetH hdsSrc = NULL;
583 VRTDatasetH hdsDst = NULL;
584 VRTSourcedRasterBandH hbandDst = NULL;
585 double ogt[6] = {0};
586 double offset[2] = {0};
587
590 int aligned = 0;
592
593 assert(band != NULL);
594 assert(
band->raster != NULL);
595
596 if (!
band->offline) {
597 rterror(
"rt_band_load_offline_data: Band is not offline");
599 }
600 else if (!strlen(
band->data.offline.path)) {
601 rterror(
"rt_band_load_offline_data: Offline band does not a have a specified file");
603 }
604
605
607 rterror(
"rt_band_load_offline_data: Access to offline bands disabled");
609 }
610
613 if (hdsSrc == NULL) {
614 rterror(
"rt_band_load_offline_data: Cannot open offline raster: %s",
band->data.offline.path);
616 }
617
618
619 nband = GDALGetRasterCount(hdsSrc);
620 if (!nband) {
621 rterror(
"rt_band_load_offline_data: No bands found in offline raster: %s",
band->data.offline.path);
622 GDALClose(hdsSrc);
624 }
625
626 else if (
band->data.offline.bandNum + 1 > nband) {
627 rterror(
"rt_band_load_offline_data: Specified band %d not found in offline raster: %s",
band->data.offline.bandNum,
band->data.offline.path);
628 GDALClose(hdsSrc);
630 }
631
632
633 if (GDALGetGeoTransform(hdsSrc, ogt) != CE_None) {
634 RASTER_DEBUG(4,
"Using default geotransform matrix (0, 1, 0, 0, 0, -1)");
635 ogt[0] = 0;
636 ogt[1] = 1;
637 ogt[2] = 0;
638 ogt[3] = 0;
639 ogt[4] = 0;
640 ogt[5] = -1;
641 }
642 RASTER_DEBUGF(3,
"Offline geotransform (%f, %f, %f, %f, %f, %f)",
643 ogt[0], ogt[1], ogt[2], ogt[3], ogt[4], ogt[5]);
644
645
651
653 rterror(
"rt_band_load_offline_data: Could not test alignment of in-db representation of out-db raster");
654 GDALClose(hdsSrc);
656 }
657 else if (!aligned) {
658 rtwarn(
"The in-db representation of the out-db raster is not aligned. Band data may be incorrect");
659 }
660
661
664 ogt[0], ogt[3],
665 &(offset[0]), &(offset[1]),
666 NULL
667 );
668
670
671
672 hdsDst = VRTCreate(
band->width,
band->height);
673 GDALSetGeoTransform(hdsDst, ogt);
674
675
676
677
678
680 hbandDst = (VRTSourcedRasterBandH) GDALGetRasterBand(hdsDst, 1);
681
683 GDALSetRasterNoDataValue(hbandDst,
band->nodataval);
684
685 VRTAddSimpleSource(
686 hbandDst, GDALGetRasterBand(hdsSrc,
band->data.offline.bandNum + 1),
687 fabs(offset[0]), fabs(offset[1]),
689 0, 0,
691 "near", VRT_NODATA_UNSET
692 );
693
694
695 VRTFlushCache(hdsDst);
696
697
699
700 GDALClose(hdsDst);
701 GDALClose(hdsSrc);
702
703
704
705
706
707
708
709
710
711 if (_rast == NULL) {
712 rterror(
"rt_band_load_offline_data: Cannot load data from offline raster: %s",
band->data.offline.path);
714 }
715
717 if (_band == NULL) {
718 rterror(
"rt_band_load_offline_data: Cannot load data from offline raster: %s",
band->data.offline.path);
721 }
722
723
724 if (
band->data.offline.mem != NULL) {
726 band->data.offline.mem = NULL;
727 }
728
730
733
735}
void rterror(const char *fmt,...) __attribute__((format(printf
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.
void void void rtwarn(const char *fmt,...) __attribute__((format(printf
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.
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.
bool enable_outdb_rasters
union rt_band_t::@12 data