32 #define _LARGEFILE64_SOURCE 1
64 uint16_t width, uint16_t height,
66 uint32_t hasnodata,
double nodataval,
75 rterror(
"rt_band_new_inline: Out of memory allocating rt_band");
81 band->pixtype = pixtype;
84 band->height = height;
85 band->hasnodata = hasnodata ? 1 : 0;
96 rterror(
"rt_band_new_inline: Could not set NODATA value");
125 uint16_t width, uint16_t height,
127 uint32_t hasnodata,
double nodataval,
128 uint8_t bandNum,
const char* path
133 assert(NULL != path);
137 rterror(
"rt_band_new_offline: Out of memory allocating rt_band");
145 band->pixtype = pixtype;
148 band->height = height;
149 band->hasnodata = hasnodata ? 1 : 0;
157 rterror(
"rt_band_new_offline: Could not set NODATA value");
162 band->data.offline.bandNum = bandNum;
165 pathlen = strlen(path);
166 band->data.offline.path =
rtalloc(
sizeof(
char) * (pathlen + 1));
167 if (
band->data.offline.path == NULL) {
168 rterror(
"rt_band_new_offline: Out of memory allocating offline path");
172 memcpy(
band->data.offline.path, path, pathlen);
173 band->data.offline.path[pathlen] =
'\0';
175 band->data.offline.mem = NULL;
208 GDALDatasetH hdsSrc = NULL;
210 GDALRasterBandH hbandSrc = NULL;
212 GDALDataType gdpixtype;
218 if (hdsSrc == NULL && !force) {
219 rterror(
"rt_band_new_offline_from_path: Cannot open offline raster: %s", path);
223 nband = GDALGetRasterCount(hdsSrc);
224 if (!
nband && !force) {
225 rterror(
"rt_band_new_offline_from_path: No bands found in offline raster: %s", path);
230 else if (bandNum >
nband && !force) {
232 "rt_band_new_offline_from_path: Specified band %d not found in offline raster: %s",
240 hbandSrc = GDALGetRasterBand(hdsSrc, bandNum);
241 if (hbandSrc == NULL && !force) {
243 "rt_band_new_offline_from_path: Cannot get band %d from GDAL dataset",
250 gdpixtype = GDALGetRasterDataType(hbandSrc);
252 if (pt ==
PT_END && !force) {
254 "rt_band_new_offline_from_path: Unsupported pixel type %s of band %d from GDAL dataset",
255 GDALGetDataTypeName(gdpixtype),
264 nodataval = GDALGetRasterNoDataValue(hbandSrc, &hasnodata);
271 hasnodata, nodataval,
290 assert(
band != NULL);
298 band->data.offline.bandNum, (
const char *)
band->data.offline.path
303 uint8_t *
data = NULL;
306 rterror(
"rt_band_duplicate: Out of memory allocating online band data");
321 rterror(
"rt_band_duplicate: Could not copy band");
330 assert(NULL !=
band);
331 return band->offline ? 1 : 0;
349 if (
band->data.offline.mem != NULL)
352 if (
band->data.offline.path != NULL)
356 else if (
band->data.mem != NULL &&
band->ownsdata)
365 assert(NULL !=
band);
368 if (!
band->offline) {
369 RASTER_DEBUG(3,
"rt_band_get_ext_path: Band is not offline");
372 return band->data.offline.path;
377 assert(NULL !=
band);
378 assert(NULL != bandnum);
382 if (!
band->offline) {
383 RASTER_DEBUG(3,
"rt_band_get_ext_band_num: Band is not offline");
387 *bandnum =
band->data.offline.bandNum;
401 assert(NULL !=
band);
404 if (
band->data.offline.mem != NULL)
405 return band->data.offline.mem;
410 return band->data.offline.mem;
413 return band->data.mem;
430 GDALDatasetH hdsSrc = NULL;
432 VRTDatasetH hdsDst = NULL;
433 VRTSourcedRasterBandH hbandDst = NULL;
435 double offset[2] = {0};
442 assert(
band != NULL);
443 assert(
band->raster != NULL);
445 if (!
band->offline) {
446 rterror(
"rt_band_load_offline_data: Band is not offline");
449 else if (!strlen(
band->data.offline.path)) {
450 rterror(
"rt_band_load_offline_data: Offline band does not a have a specified file");
456 rterror(
"rt_band_load_offline_data: Access to offline bands disabled");
462 if (hdsSrc == NULL) {
463 rterror(
"rt_band_load_offline_data: Cannot open offline raster: %s",
band->data.offline.path);
468 nband = GDALGetRasterCount(hdsSrc);
470 rterror(
"rt_band_load_offline_data: No bands found in offline raster: %s",
band->data.offline.path);
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);
482 if (GDALGetGeoTransform(hdsSrc, ogt) != CE_None) {
483 RASTER_DEBUG(4,
"Using default geotransform matrix (0, 1, 0, 0, 0, -1)");
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]);
502 rterror(
"rt_band_load_offline_data: Could not test alignment of in-db representation of out-db raster");
507 rtwarn(
"The in-db representation of the out-db raster is not aligned. Band data may be incorrect");
514 &(offset[0]), &(offset[1]),
521 hdsDst = VRTCreate(
band->width,
band->height);
522 GDALSetGeoTransform(hdsDst, ogt);
529 hbandDst = (VRTSourcedRasterBandH) GDALGetRasterBand(hdsDst, 1);
532 GDALSetRasterNoDataValue(hbandDst,
band->nodataval);
535 hbandDst, GDALGetRasterBand(hdsSrc,
band->data.offline.bandNum + 1),
536 fabs(offset[0]), fabs(offset[1]),
540 "near", VRT_NODATA_UNSET
544 VRTFlushCache(hdsDst);
561 rterror(
"rt_band_load_offline_data: Cannot load data from offline raster: %s",
band->data.offline.path);
567 rterror(
"rt_band_load_offline_data: Cannot load data from offline raster: %s",
band->data.offline.path);
573 if (
band->data.offline.mem != NULL) {
575 band->data.offline.mem = NULL;
589 assert(NULL !=
band);
590 if (!
band->offline) {
591 rterror(
"rt_band_get_file_size: Band is not offline");
596 rterror(
"rt_band_get_file_size: Access to offline bands disabled");
600 if( VSIStatL(
band->data.offline.path, &sStat) != 0 ) {
601 rterror(
"rt_band_get_file_size: Cannot access file");
605 return sStat.st_size;
611 assert(NULL !=
band);
612 if (!
band->offline) {
613 rterror(
"rt_band_get_file_timestamp: Band is not offline");
618 rterror(
"rt_band_get_file_timestamp: Access to offline bands disabled");
622 if( VSIStatL(
band->data.offline.path, &sStat) != 0 ) {
623 rterror(
"rt_band_get_file_timestamp: Cannot access file");
627 return sStat.st_mtime;
633 assert(NULL !=
band);
636 return band->pixtype;
642 assert(NULL !=
band);
651 assert(NULL !=
band);
660 assert(NULL !=
band);
662 return band->ownsdata ? 1 : 0;
668 assert(NULL !=
band);
670 band->ownsdata = flag ? 1 : 0;
675 assert(NULL !=
band);
677 return band->hasnodata ? 1 : 0;
683 assert(NULL !=
band);
685 band->hasnodata = (flag) ? 1 : 0;
688 if (!
band->hasnodata &&
band->isnodata) {
689 RASTER_DEBUG(3,
"Setting isnodata to FALSE as band no longer has NODATA");
696 assert(NULL !=
band);
698 if (!
band->hasnodata) {
703 rterror(
"rt_band_set_isnodata_flag: Cannot set isnodata flag as band has no NODATA");
708 band->isnodata = (flag) ? 1 : 0;
715 assert(NULL !=
band);
718 return band->isnodata ? 1 : 0;
735 int32_t checkvalint = 0;
736 uint32_t checkvaluint = 0;
737 float checkvalfloat = 0;
738 double checkvaldouble = 0;
740 assert(NULL !=
band);
742 if (converted != NULL)
745 pixtype =
band->pixtype;
753 checkvalint =
band->nodataval;
758 checkvalint =
band->nodataval;
763 checkvalint =
band->nodataval;
768 checkvalint =
band->nodataval;
773 checkvalint =
band->nodataval;
778 checkvalint =
band->nodataval;
783 checkvalint =
band->nodataval;
788 checkvalint =
band->nodataval;
793 checkvaluint =
band->nodataval;
798 checkvalfloat =
band->nodataval;
802 band->nodataval = val;
803 checkvaldouble =
band->nodataval;
807 rterror(
"rt_band_set_nodata: Unknown pixeltype %d", pixtype);
823 checkvalint, checkvaluint,
824 checkvalfloat, checkvaldouble,
826 ) && converted != NULL) {
856 void *vals, uint32_t len
860 uint8_t *
data = NULL;
863 assert(NULL !=
band);
864 assert(vals != NULL && len > 0);
869 rterror(
"rt_band_set_pixel_line not implemented yet for OFFDB bands");
873 pixtype =
band->pixtype;
877 x < 0 || x >=
band->width ||
878 y < 0 || y >=
band->height
880 rterror(
"rt_band_set_pixel_line: Coordinates out of range (%d, %d) vs (%d, %d)",
x,
y,
band->width,
band->height);
885 offset =
x + (
y *
band->width);
889 if (len > (
band->width *
band->height) - offset) {
890 rterror(
"rt_band_set_pixel_line: Could not apply pixels as values length exceeds end of data");
902 memcpy(ptr, vals, size * len);
906 uint16_t *ptr = (uint16_t *)
data;
908 memcpy(ptr, vals, size * len);
912 int16_t *ptr = (int16_t *)
data;
914 memcpy(ptr, vals, size * len);
918 uint32_t *ptr = (uint32_t *)
data;
920 memcpy(ptr, vals, size * len);
924 int32_t *ptr = (int32_t *)
data;
926 memcpy(ptr, vals, size * len);
930 float *ptr = (
float *)
data;
932 memcpy(ptr, vals, size * len);
936 double *ptr = (
double *)
data;
938 memcpy(ptr, vals, size * len);
942 rterror(
"rt_band_set_pixel_line: Unknown pixeltype %d", pixtype);
947 #if POSTGIS_DEBUG_LEVEL > 0
981 uint8_t *
data = NULL;
984 int32_t checkvalint = 0;
985 uint32_t checkvaluint = 0;
986 float checkvalfloat = 0;
987 double checkvaldouble = 0;
989 assert(NULL !=
band);
991 if (converted != NULL)
995 rterror(
"rt_band_set_pixel not implemented yet for OFFDB bands");
999 pixtype =
band->pixtype;
1002 x < 0 || x >=
band->width ||
1003 y < 0 || y >=
band->height
1005 rterror(
"rt_band_set_pixel: Coordinates out of range");
1017 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
1018 rtwarn(
"Value for pixel %d x %d has been corrected as clamped value becomes NODATA",
x,
y);
1022 if (converted != NULL)
1028 offset =
x + (
y *
band->width);
1033 checkvalint =
data[offset];
1038 checkvalint =
data[offset];
1043 checkvalint =
data[offset];
1048 checkvalint = (int8_t)
data[offset];
1053 checkvalint =
data[offset];
1057 int16_t *ptr = (int16_t*)
data;
1059 checkvalint = (int16_t) ptr[offset];
1063 uint16_t *ptr = (uint16_t*)
data;
1065 checkvalint = ptr[offset];
1069 int32_t *ptr = (int32_t*)
data;
1071 checkvalint = (int32_t) ptr[offset];
1075 uint32_t *ptr = (uint32_t*)
data;
1077 checkvaluint = ptr[offset];
1081 float *ptr = (
float*)
data;
1083 checkvalfloat = ptr[offset];
1087 double *ptr = (
double*)
data;
1089 checkvaldouble = ptr[offset];
1093 rterror(
"rt_band_set_pixel: Unknown pixeltype %d", pixtype);
1100 RASTER_DEBUG(3,
"Band has a value that is not NODATA. Setting isnodata to FALSE");
1107 checkvalint, checkvaluint,
1108 checkvalfloat, checkvaldouble,
1110 ) && converted != NULL) {
1141 void **vals, uint16_t *nvals
1143 uint8_t *_vals = NULL;
1145 uint8_t *
data = NULL;
1146 uint32_t offset = 0;
1147 uint16_t _nvals = 0;
1149 uint8_t *ptr = NULL;
1151 assert(NULL !=
band);
1152 assert(vals != NULL && nvals != NULL);
1158 x < 0 || x >=
band->width ||
1159 y < 0 || y >=
band->height
1161 rtwarn(
"Attempting to get pixel values with out of range raster coordinates: (%d, %d)",
x,
y);
1170 rterror(
"rt_band_get_pixel_line: Cannot get band data");
1175 offset =
x + (
y *
band->width);
1183 maxlen =
band->width *
band->height;
1185 if (((
int) (offset + _nvals)) > maxlen) {
1186 _nvals = maxlen - offset;
1187 rtwarn(
"Limiting returning number values to %d", _nvals);
1191 ptr =
data + (offset * pixsize);
1193 _vals =
rtalloc(_nvals * pixsize);
1194 if (_vals == NULL) {
1195 rterror(
"rt_band_get_pixel_line: Could not allocate memory for pixel values");
1200 memcpy(_vals, ptr, _nvals * pixsize);
1223 double xr,
double yr,
1225 double *r_value,
int *r_nodata
1230 band, xr, yr, r_value, r_nodata
1235 band, floor(xr), floor(yr),
1240 rtwarn(
"Invalid resample type requested %d", resample);
1262 double xr,
double yr,
1263 double *r_value,
int *r_nodata)
1265 double xcenter, ycenter;
1266 double values[2][2];
1267 double nodatavalue = 0.0;
1274 uint16_t width, height;
1277 xcell = (int)floor(xr);
1278 ycell = (int)floor(yr);
1279 xcenter = xcell + 0.5;
1280 ycenter = ycell + 0.5;
1287 if(xcell < 0 || ycell < 0 || xcell >= width || ycell >= height) {
1288 rtwarn(
"Attempting to get pixel value with out of range raster coordinates: (%d, %d)", xcell, ycell);
1293 xdir = xr < xcenter ? 1 : 0;
1294 ydir = yr < ycenter ? 1 : 0;
1304 for (i = 0; i < 2; i++) {
1305 for (j = 0; j < 2; j++) {
1306 double value = nodatavalue;
1308 int xij = xcell + (i - xdir);
1309 int yij = ycell + (j - ydir);
1311 if(xij < 0 || yij < 0 || xij >= width || yij >= height) {
1324 values[i][j] =
value;
1325 nodatas[i][j] = nodata;
1330 if (nodatas[xdir][ydir]) {
1331 *r_value = nodatavalue;
1338 xr = xr - (
x[0][0] + 0.5);
1339 yr = yr - (
y[0][0] + 0.5);
1344 for (i = 0; i < 2; i++) {
1345 for (j = 0; j < 2; j++) {
1347 values[i][j] = values[xdir][ydir];
1354 *r_value = values[0][0] * (1-xr) * (1-yr) +
1355 values[1][0] * (1-yr) * xr +
1356 values[0][1] * (1-xr) * yr +
1357 values[1][1] * xr * yr;
1383 uint8_t*
data = NULL;
1384 uint32_t offset = 0;
1386 assert(NULL !=
band);
1387 assert(NULL !=
value);
1394 x < 0 || x >=
band->width ||
1395 y < 0 || y >=
band->height
1397 rtwarn(
"Attempting to get pixel value with out of range raster coordinates: (%d, %d)",
x,
y);
1402 if (
band->isnodata) {
1403 RASTER_DEBUG(3,
"Band's isnodata flag is TRUE. Returning NODATA value");
1405 if (nodata != NULL) *nodata = 1;
1411 rterror(
"rt_band_get_pixel: Cannot get band data");
1416 offset =
x + (
y *
band->width);
1418 pixtype =
band->pixtype;
1422 #ifdef OPTIMIZE_SPACE
1424 int byteOffset = offset / 8;
1425 int bitOffset = offset % 8;
1429 *
value = getBits(
data, val, 1, bitOffset);
1434 #ifdef OPTIMIZE_SPACE
1436 int byteOffset = offset / 4;
1437 int bitOffset = offset % 4;
1441 *
value = getBits(
data, val, 2, bitOffset);
1446 #ifdef OPTIMIZE_SPACE
1448 int byteOffset = offset / 2;
1449 int bitOffset = offset % 2;
1453 *
value = getBits(
data, val, 2, bitOffset);
1458 int8_t val = (int8_t)
data[offset];
1463 uint8_t val =
data[offset];
1468 int16_t *ptr = (int16_t*)
data;
1469 *
value = ptr[offset];
1473 uint16_t *ptr = (uint16_t*)
data;
1474 *
value = ptr[offset];
1478 int32_t *ptr = (int32_t*)
data;
1479 *
value = ptr[offset];
1483 uint32_t *ptr = (uint32_t*)
data;
1484 *
value = ptr[offset];
1488 float *ptr = (
float*)
data;
1489 *
value = ptr[offset];
1493 double *ptr = (
double*)
data;
1494 *
value = ptr[offset];
1498 rterror(
"rt_band_get_pixel: Unknown pixeltype %d", pixtype);
1504 if (
band->hasnodata && nodata != NULL) {
1532 uint16_t distancex, uint16_t distancey,
1533 int exclude_nodata_value,
1537 int extent[4] = {0};
1538 int max_extent[4] = {0};
1541 uint32_t _d[2] = {0};
1556 assert(NULL !=
band);
1557 assert(NULL != npixels);
1574 exclude_nodata_value && (
1575 (x < 0 || x >
band->width) ||
1576 (y < 0 || y >
band->height)
1583 else if (
x >
band->width)
1588 else if (
y >
band->height)
1601 RASTER_DEBUG(4,
"No nearest pixels possible for provided pixel and distances");
1607 if (!
band->hasnodata)
1608 exclude_nodata_value =
FALSE;
1610 else if (exclude_nodata_value &&
band->isnodata) {
1611 RASTER_DEBUG(4,
"No nearest pixels possible as band is NODATA and excluding NODATA values");
1621 b = abs(
x -
band->width);
1630 b = abs(
y -
band->height);
1654 max_extent[0], max_extent[1], max_extent[2], max_extent[3]);
1662 extent[0] =
x - (int)_d[0];
1663 extent[1] =
y - (int)_d[1];
1664 extent[2] =
x + (int)_d[0];
1665 extent[3] =
y + (int)_d[1];
1667 RASTER_DEBUGF(4,
"Processing distances: %d x %d", _d[0], _d[1]);
1669 extent[0], extent[1], extent[2], extent[3]);
1671 for (i = 0; i < 2; i++) {
1675 _max = extent[2] - extent[0] + 1;
1678 _max = extent[3] - extent[1] + 1;
1681 for (j = 0; j < 2; j++) {
1710 for (k = 0; k < (uint32_t) _max; k++) {
1713 _x < max_extent[0] || _x > max_extent[2] ||
1714 _y < max_extent[1] || _y > max_extent[3]
1722 (_x < 0 || _x >=
band->width) ||
1723 (_y < 0 || _y >=
band->height)
1726 if (!
band->hasnodata)
1731 RASTER_DEBUGF(4,
"NODATA pixel outside band extent: (x, y, val) = (%d, %d, %f)", _x, _y,
pixval);
1742 rterror(
"rt_band_get_nearest_pixel: Could not get pixel value");
1751 if (!exclude_nodata_value || (exclude_nodata_value && !isnodata)) {
1753 RASTER_DEBUGF(4,
"Adding pixel to set of nearest pixels: (x, y, val) = (%d, %d, %f)", _x, _y,
pixval);
1756 if (*npixels == NULL)
1760 if (*npixels == NULL) {
1761 rterror(
"rt_band_get_nearest_pixel: Could not allocate memory for nearest pixel(s)");
1765 npixel = &((*npixels)[
count - 1]);
1771 if (!inextent && !
band->hasnodata)
1785 else if (d0 &&
count)
1811 double *searchset,
int searchcount,
1825 assert(NULL !=
band);
1826 assert(NULL != pixels);
1827 assert(NULL != searchset && searchcount > 0);
1829 if (!
band->hasnodata)
1830 exclude_nodata_value =
FALSE;
1832 else if (exclude_nodata_value &&
band->isnodata) {
1833 RASTER_DEBUG(4,
"Pixels cannot be searched as band is NODATA and excluding NODATA values");
1837 for (
x = 0;
x <
band->width;
x++) {
1838 for (
y = 0;
y <
band->height;
y++) {
1841 rterror(
"rt_band_get_pixel_of_value: Cannot get band pixel");
1844 else if (exclude_nodata_value && isnodata)
1847 for (i = 0; i < searchcount; i++) {
1857 if (*pixels == NULL)
1861 if (*pixels == NULL) {
1862 rterror(
"rt_band_get_pixel_of_value: Could not allocate memory for pixel(s)");
1888 assert(NULL !=
band);
1889 assert(NULL != nodata);
1891 *nodata =
band->nodataval;
1893 if (!
band->hasnodata) {
1894 rterror(
"rt_band_get_nodata: Band has no NODATA value");
1903 assert(NULL !=
band);
1914 assert(NULL !=
band);
1918 if (!
band->hasnodata) {
1923 pxValue =
band->nodataval;
1926 for (i = 0; i <
band->width; i++) {
1927 for (j = 0; j <
band->height; j++) {
1930 rterror(
"rt_band_check_is_nodata: Cannot get band pixel");
1933 else if (!isnodata) {
1958 assert(NULL !=
band);
1961 if (!
band->hasnodata)
1971 val,
band->nodataval,
1975 return isequal ? 1 : 0;
1994 double *newval,
int *corrected
1998 assert(NULL !=
band);
1999 assert(NULL != newval);
2001 if (corrected != NULL)
2013 switch (
band->pixtype) {
2015 *newval = !
band->nodataval;
2067 *newval += FLT_EPSILON;
2069 *newval -= FLT_EPSILON;
2074 rterror(
"rt_band_corrected_clamped_value: Unknown pixeltype %d",
band->pixtype);
2078 if (corrected != NULL)
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
rt_pixtype rt_util_gdal_datatype_to_pixtype(GDALDataType gdt)
Convert GDALDataType to rt_pixtype.
#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.
int8_t rt_util_clamp_to_8BSI(double value)
uint8_t rt_util_clamp_to_1BB(double value)
int32_t rt_util_clamp_to_32BSI(double value)
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.
int rt_util_dbl_trunc_warning(double initialvalue, int32_t checkvalint, uint32_t checkvaluint, float checkvalfloat, double checkvaldouble, rt_pixtype pixtype)
GDALDataType rt_util_pixtype_to_gdal_datatype(rt_pixtype pt)
Convert rt_pixtype to GDALDataType.
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
struct rt_pixel_t * rt_pixel
rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds)
Return a raster from a GDAL dataset.
uint8_t rt_util_clamp_to_2BUI(double value)
void rtwarn(const char *fmt,...)
rt_errorstate rt_pixtype_compare_clamped_values(rt_pixtype pixtype, double val, double refval, int *isequal)
Test to see if two values are equal when clamped.
uint8_t rt_util_clamp_to_8BUI(double value)
GDALDatasetH rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared)
rt_errorstate
Enum definitions.
int16_t rt_util_clamp_to_16BSI(double value)
void * rtrealloc(void *mem, size_t size)
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
uint8_t rt_util_clamp_to_4BUI(double value)
const char * rt_pixtype_name(rt_pixtype pixtype)
void rtdealloc(void *mem)
uint16_t rt_util_clamp_to_16BUI(double value)
uint32_t rt_util_clamp_to_32BUI(double value)
float rt_util_clamp_to_32F(double value)
rt_errorstate rt_raster_same_alignment(rt_raster rast1, rt_raster rast2, int *aligned, char **reason)
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
This library is the generic raster handling section of PostGIS.
static double distance(double x1, double y1, double x2, double y2)
rt_band rt_band_new_inline(uint16_t width, uint16_t height, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, uint8_t *data)
Create an in-db rt_band with no data.
void rt_band_set_ownsdata_flag(rt_band band, int flag)
int rt_band_get_pixel_of_value(rt_band band, int exclude_nodata_value, double *searchset, int searchcount, rt_pixel *pixels)
Search band for pixel(s) with search values.
rt_band rt_band_duplicate(rt_band band)
Create a new band duplicated from source band.
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
void rt_band_set_hasnodata_flag(rt_band band, int flag)
Set hasnodata flag value.
rt_errorstate rt_band_set_isnodata_flag(rt_band band, int flag)
Set isnodata flag value.
const char * rt_band_get_ext_path(rt_band band)
Return band's external path (only valid when rt_band_is_offline returns non-zero).
rt_errorstate rt_band_load_offline_data(rt_band band)
Load offline band's data.
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
double rt_band_get_min_value(rt_band band)
Returns the minimal possible value for the band according to the pixel type.
uint64_t rt_band_get_file_size(rt_band band)
Return file size in bytes.
bool enable_outdb_rasters
int rt_band_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
rt_errorstate rt_band_set_pixel_line(rt_band band, int x, int y, void *vals, uint32_t len)
Set values of multiple pixels.
void rt_band_destroy(rt_band band)
Destroy a raster band.
rt_errorstate rt_band_corrected_clamped_value(rt_band band, double val, double *newval, int *corrected)
Correct value when clamped value is equal to clamped NODATA value.
rt_band rt_band_new_offline(uint16_t width, uint16_t height, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, uint8_t bandNum, const char *path)
Create an out-db rt_band.
rt_errorstate rt_band_get_ext_band_num(rt_band band, uint8_t *bandnum)
Return bands' external band number (only valid when rt_band_is_offline returns non-zero).
uint64_t rt_band_get_file_timestamp(rt_band band)
Return file timestamp.
rt_errorstate rt_band_get_pixel_resample(rt_band band, double xr, double yr, rt_resample_type resample, double *r_value, int *r_nodata)
Retrieve a point value from the raster using a world coordinate and selected interpolation.
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
rt_band rt_band_new_offline_from_path(uint16_t width, uint16_t height, int hasnodata, double nodataval, uint8_t bandNum, const char *path, int force)
Create an out-db rt_band from path.
uint32_t rt_band_get_nearest_pixel(rt_band band, int x, int y, uint16_t distancex, uint16_t distancey, int exclude_nodata_value, rt_pixel *npixels)
Get nearest pixel(s) with value (not NODATA) to specified pixel.
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
rt_errorstate rt_band_get_pixel_bilinear(rt_band band, double xr, double yr, double *r_value, int *r_nodata)
Retrieve a point value from the raster using a world coordinate and bilinear interpolation.
int rt_band_clamped_value_is_nodata(rt_band band, double val)
Compare clamped value to band's clamped NODATA value.
int rt_band_get_ownsdata_flag(rt_band band)
Return 0 (FALSE) or non-zero (TRUE) indicating if rt_band is responsible for managing the memory for ...
int rt_band_is_offline(rt_band band)
Return non-zero if the given band data is on the filesystem.
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
rt_errorstate rt_band_get_pixel_line(rt_band band, int x, int y, uint16_t len, void **vals, uint16_t *nvals)
Get values of multiple pixels.
union rt_band_t::@11 data