1351 GDALDatasetH hdsSrc;
1353 VRTSourcedRasterBandH hbandOv;
1354 double gtOv[6] = {0.};
1359 const char *ovtable = NULL;
1362 VRTSourcedRasterBandH hbandDst;
1363 int tile_size[2] = {0};
1364 int _tile_size[2] = {0};
1365 int ntiles[2] = {1, 1};
1368 double gt[6] = {0.};
1374 hdsSrc = GDALOpenShared(config->
rt_file[idx], GA_ReadOnly);
1375 if (hdsSrc == NULL) {
1376 rterror(
_(
"build_overview: Could not open raster: %s"), config->
rt_file[idx]);
1381 memcpy(gtOv, info->
gt,
sizeof(
double) * 6);
1384 rterror(
_(
"build_overview: Invalid overview index: %d"), ovx);
1392 rterror(
_(
"build_overview: Overview factor %d is not between %d and %d"), factor,
MINOVFACTOR, MAXOVFACTOR);
1396 dimOv[0] = (int) (info->
dim[0] + (factor / 2)) / factor;
1397 dimOv[1] = (int) (info->
dim[1] + (factor / 2)) / factor;
1400 hdsOv = VRTCreate(dimOv[0], dimOv[1]);
1404 GDALSetProjection(hdsOv, info->
srs);
1410 GDALSetGeoTransform(hdsOv, gtOv);
1415 hbandOv = (VRTSourcedRasterBandH) GDALGetRasterBand(hdsOv, j + 1);
1418 GDALSetRasterNoDataValue(hbandOv, info->
nodataval[j]);
1421 hbandOv, GDALGetRasterBand(hdsSrc, info->
nband[j]),
1423 info->
dim[0], info->
dim[1],
1426 "near", VRT_NODATA_UNSET
1431 VRTFlushCache(hdsOv);
1435 tile_size[0] = dimOv[0];
1439 tile_size[1] = dimOv[1];
1445 tile_size[0] != dimOv[0] &&
1446 tile_size[1] != dimOv[1]
1448 ntiles[0] = (dimOv[0] + tile_size[0] - 1) / tile_size[0];
1449 ntiles[1] = (dimOv[1] + tile_size[1] - 1) / tile_size[1];
1453 memcpy(gt, gtOv,
sizeof(
double) * 6);
1457 for (ytile = 0; ytile < ntiles[1]; ytile++) {
1460 if (!config->
pad_tile && ntiles[1] > 1 && (ytile + 1) == ntiles[1])
1461 _tile_size[1] = dimOv[1] - (ytile * tile_size[1]);
1463 _tile_size[1] = tile_size[1];
1465 for (xtile = 0; xtile < ntiles[0]; xtile++) {
1472 if (!config->
pad_tile && ntiles[0] > 1 && (xtile + 1) == ntiles[0])
1473 _tile_size[0] = dimOv[0] - (xtile * tile_size[0]);
1475 _tile_size[0] = tile_size[0];
1478 GDALApplyGeoTransform(
1480 xtile * tile_size[0], ytile * tile_size[1],
1485 hdsDst = VRTCreate(_tile_size[0], _tile_size[1]);
1489 GDALSetProjection(hdsDst, info->
srs);
1490 GDALSetGeoTransform(hdsDst, gt);
1495 hbandDst = (VRTSourcedRasterBandH) GDALGetRasterBand(hdsDst, j + 1);
1498 GDALSetRasterNoDataValue(hbandDst, info->
nodataval[j]);
1501 hbandDst, GDALGetRasterBand(hdsOv, j + 1),
1502 xtile * tile_size[0], ytile * tile_size[1],
1503 _tile_size[0], _tile_size[1],
1505 _tile_size[0], _tile_size[1],
1506 "near", VRT_NODATA_UNSET
1511 VRTFlushCache(hdsDst);
1516 rterror(
_(
"build_overview: Could not convert VRT dataset to PostGIS raster"));
1529 rterror(
_(
"build_overview: Could not convert PostGIS raster to hex WKB"));
1540 if (tileset->
length > 10) {
1547 rterror(
_(
"build_overview: Could not convert raster tiles into INSERT or COPY statements"));
GDALDataType * gdalbandtype
static void rtdealloc_stringbuffer(STRINGBUFFER *buffer, int freebuffer)
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
static int append_stringbuffer(STRINGBUFFER *buffer, const char *str)
static int insert_records(const char *schema, const char *table, const char *column, const char *filename, const char *file_column_name, int copy_statements, int out_srid, STRINGBUFFER *tileset, STRINGBUFFER *buffer)
char * rt_raster_to_hexwkb(rt_raster raster, int outasin, uint32_t *hexwkbsize)
Return this raster in HEXWKB form (null-terminated hex)
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
static void raster_destroy(rt_raster raster)
rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds)
Return a raster from a GDAL dataset.