" an appropriate tile size using the first raster and applied to\n"
" all rasters.\n"
));
+ printf(_(
+ " -P Pad right-most and bottom-most tiles to guarantee that all tiles\n"
+ " have the same width and height.\n"
+ ));
printf(_(
" -R Register the raster as an out-of-db (filesystem) raster. Provided\n"
" raster should have absolute path to the file\n"
config->nband = NULL;
config->nband_count = 0;
memset(config->tile_size, 0, sizeof(int) * 2);
+ config->pad_tile = 0;
config->outdb = 0;
config->opt = 'c';
config->idx = 0;
VRTDatasetH hdsDst;
VRTSourcedRasterBandH hbandDst;
int tile_size[2] = {0};
+ int _tile_size[2] = {0};
int ntiles[2] = {1, 1};
int xtile = 0;
int ytile = 0;
/* tile overview */
/* each tile is a VRT with constraints set for just the data required for the tile */
for (ytile = 0; ytile < ntiles[1]; ytile++) {
+
+ /* edge y tile */
+ if (!config->pad_tile && ntiles[1] > 1 && (ytile + 1) == ntiles[1])
+ _tile_size[1] = dimOv[1] - (ytile * tile_size[1]);
+ else
+ _tile_size[1] = tile_size[1];
+
for (xtile = 0; xtile < ntiles[0]; xtile++) {
/*
char fn[100];
sprintf(fn, "/tmp/ovtile%d.vrt", (ytile * ntiles[0]) + xtile);
*/
+ /* edge x tile */
+ if (!config->pad_tile && ntiles[0] > 1 && (xtile + 1) == ntiles[0])
+ _tile_size[0] = dimOv[0] - (xtile * tile_size[0]);
+ else
+ _tile_size[0] = tile_size[0];
+
/* compute tile's upper-left corner */
GDALApplyGeoTransform(
gtOv,
);
/* create VRT dataset */
- hdsDst = VRTCreate(tile_size[0], tile_size[1]);
+ hdsDst = VRTCreate(_tile_size[0], _tile_size[1]);
/*
GDALSetDescription(hdsDst, fn);
*/
VRTAddSimpleSource(
hbandDst, GDALGetRasterBand(hdsOv, j + 1),
xtile * tile_size[0], ytile * tile_size[1],
- tile_size[0], tile_size[1],
+ _tile_size[0], _tile_size[1],
0, 0,
- tile_size[0], tile_size[1],
+ _tile_size[0], _tile_size[1],
"near", VRT_NODATA_UNSET
);
}
int nband = 0;
int i = 0;
int ntiles[2] = {1, 1};
+ int _tile_size[2] = {0, 0};
int xtile = 0;
int ytile = 0;
double gt[6] = {0.};
/* each tile is a raster */
for (ytile = 0; ytile < ntiles[1]; ytile++) {
+ /* edge y tile */
+ if (!config->pad_tile && ntiles[1] > 1 && (ytile + 1) == ntiles[1])
+ _tile_size[1] = info->dim[1] - (ytile * info->tile_size[1]);
+ else
+ _tile_size[1] = info->tile_size[1];
+
for (xtile = 0; xtile < ntiles[0]; xtile++) {
+ /* edge x tile */
+ if (!config->pad_tile && ntiles[0] > 1 && (xtile + 1) == ntiles[0])
+ _tile_size[0] = info->dim[0] - (xtile * info->tile_size[0]);
+ else
+ _tile_size[0] = info->tile_size[0];
+
/* compute tile's upper-left corner */
GDALApplyGeoTransform(
info->gt,
);
/* create raster object */
- rast = rt_raster_new(info->tile_size[0], info->tile_size[1]);
+ rast = rt_raster_new(_tile_size[0], _tile_size[1]);
if (rast == NULL) {
rterror(_("convert_raster: Could not create raster"));
return 0;
/* add bands */
for (i = 0; i < info->nband_count; i++) {
band = rt_band_new_offline(
- info->tile_size[0], info->tile_size[1],
+ _tile_size[0], _tile_size[1],
info->bandtype[i],
info->hasnodata[i], info->nodataval[i],
info->nband[i] - 1,
/* each tile is a VRT with constraints set for just the data required for the tile */
for (ytile = 0; ytile < ntiles[1]; ytile++) {
+
+ /* edge y tile */
+ if (!config->pad_tile && ntiles[1] > 1 && (ytile + 1) == ntiles[1])
+ _tile_size[1] = info->dim[1] - (ytile * info->tile_size[1]);
+ else
+ _tile_size[1] = info->tile_size[1];
+
for (xtile = 0; xtile < ntiles[0]; xtile++) {
/*
char fn[100];
sprintf(fn, "/tmp/tile%d.vrt", (ytile * ntiles[0]) + xtile);
*/
+ /* edge x tile */
+ if (!config->pad_tile && ntiles[0] > 1 && (xtile + 1) == ntiles[0])
+ _tile_size[0] = info->dim[0] - (xtile * info->tile_size[0]);
+ else
+ _tile_size[0] = info->tile_size[0];
+
/* compute tile's upper-left corner */
GDALApplyGeoTransform(
info->gt,
*/
/* create VRT dataset */
- hdsDst = VRTCreate(info->tile_size[0], info->tile_size[1]);
+ hdsDst = VRTCreate(_tile_size[0], _tile_size[1]);
/*
GDALSetDescription(hdsDst, fn);
*/
VRTAddSimpleSource(
hbandDst, GDALGetRasterBand(hdsSrc, info->nband[i]),
xtile * info->tile_size[0], ytile * info->tile_size[1],
- info->tile_size[0], info->tile_size[1],
+ _tile_size[0], _tile_size[1],
0, 0,
- info->tile_size[0], info->tile_size[1],
+ _tile_size[0], _tile_size[1],
"near", VRT_NODATA_UNSET
);
}
}
}
}
+ /* pad tiles */
+ else if (CSEQUAL(argv[i], "-P")) {
+ config->pad_tile = 1;
+ }
/* out-of-db raster */
else if (CSEQUAL(argv[i], "-R")) {
config->outdb = 1;