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().
588 {
589 GDALDatasetH hdsSrc = NULL;
591 VRTDatasetH hdsDst = NULL;
592 VRTSourcedRasterBandH hbandDst = NULL;
593 double ogt[6] = {0};
594 double offset[2] = {0};
595
598 int aligned = 0;
600
601 assert(band != NULL);
602 assert(
band->raster != NULL);
603
604 if (!
band->offline) {
605 rterror(
"rt_band_load_offline_data: Band is not offline");
607 }
608 else if (!strlen(
band->data.offline.path)) {
609 rterror(
"rt_band_load_offline_data: Offline band does not a have a specified file");
611 }
612
613
615 rterror(
"rt_band_load_offline_data: Access to offline bands disabled");
617 }
618
621 if (hdsSrc == NULL) {
622 rterror(
"rt_band_load_offline_data: Cannot open offline raster: %s",
band->data.offline.path);
624 }
625
626
627 nband = GDALGetRasterCount(hdsSrc);
628 if (!nband) {
629 rterror(
"rt_band_load_offline_data: No bands found in offline raster: %s",
band->data.offline.path);
630 GDALClose(hdsSrc);
632 }
633
634 else if (
band->data.offline.bandNum + 1 > nband) {
635 rterror(
"rt_band_load_offline_data: Specified band %d not found in offline raster: %s",
band->data.offline.bandNum,
band->data.offline.path);
636 GDALClose(hdsSrc);
638 }
639
640
641 if (GDALGetGeoTransform(hdsSrc, ogt) != CE_None) {
642 RASTER_DEBUG(4,
"Using default geotransform matrix (0, 1, 0, 0, 0, -1)");
643 ogt[0] = 0;
644 ogt[1] = 1;
645 ogt[2] = 0;
646 ogt[3] = 0;
647 ogt[4] = 0;
648 ogt[5] = -1;
649 }
650 RASTER_DEBUGF(3,
"Offline geotransform (%f, %f, %f, %f, %f, %f)",
651 ogt[0], ogt[1], ogt[2], ogt[3], ogt[4], ogt[5]);
652
653
659
661 rterror(
"rt_band_load_offline_data: Could not test alignment of in-db representation of out-db raster");
662 GDALClose(hdsSrc);
664 }
665 else if (!aligned) {
666 rtwarn(
"The in-db representation of the out-db raster is not aligned. Band data may be incorrect");
667 }
668
669
672 ogt[0], ogt[3],
673 &(offset[0]), &(offset[1]),
674 NULL
675 );
676
678
679
680 hdsDst = VRTCreate(
band->width,
band->height);
681 GDALSetGeoTransform(hdsDst, ogt);
682
683
684
685
686
688 hbandDst = (VRTSourcedRasterBandH) GDALGetRasterBand(hdsDst, 1);
689
691 GDALSetRasterNoDataValue(hbandDst,
band->nodataval);
692
693 VRTAddSimpleSource(
694 hbandDst, GDALGetRasterBand(hdsSrc,
band->data.offline.bandNum + 1),
695 fabs(offset[0]), fabs(offset[1]),
697 0, 0,
699 "near", VRT_NODATA_UNSET
700 );
701
702
703 VRTFlushCache(hdsDst);
704
705
707
708 GDALClose(hdsDst);
709 GDALClose(hdsSrc);
710
711
712
713
714
715
716
717
718
719 if (_rast == NULL) {
720 rterror(
"rt_band_load_offline_data: Cannot load data from offline raster: %s",
band->data.offline.path);
722 }
723
725 if (_band == NULL) {
726 rterror(
"rt_band_load_offline_data: Cannot load data from offline raster: %s",
band->data.offline.path);
729 }
730
731
732 if (
band->data.offline.mem != NULL) {
734 band->data.offline.mem = NULL;
735 }
736
738
741
743}
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