33#define _LARGEFILE64_SOURCE 1
65 uint16_t width, uint16_t height,
67 uint32_t hasnodata,
double nodataval,
76 rterror(
"rt_band_new_inline: Out of memory allocating rt_band");
82 band->pixtype = pixtype;
85 band->height = height;
86 band->hasnodata = hasnodata ? 1 : 0;
87 band->isnodata =
FALSE;
89 band->data.mem = data;
93 RASTER_DEBUGF(3,
"Created rt_band with dimensions %d x %d", band->width, band->height);
97 rterror(
"rt_band_new_inline: Could not set NODATA value");
117 assert(band != NULL);
118 assert(band->data.mem != NULL);
120 uint32_t width = band->width;
121 uint32_t height = band->height;
122 uint32_t numval = width * height;
123 void *mem = band->data.mem;
127 int32_t checkvalint = 0;
128 uint32_t checkvaluint = 0;
129 double checkvaldouble = 0;
130 float checkvalfloat = 0;
133 if (
FLT_EQ(initval, 0.0)) {
134 memset(mem, 0, memsize);
143 for (uint32_t i = 0; i < numval; i++)
144 ptr[i] = clamped_initval;
145 checkvalint = ptr[0];
152 for (uint32_t i = 0; i < numval; i++)
153 ptr[i] = clamped_initval;
154 checkvalint = ptr[0];
161 for (uint32_t i = 0; i < numval; i++)
162 ptr[i] = clamped_initval;
163 checkvalint = ptr[0];
170 for (uint32_t i = 0; i < numval; i++)
171 ptr[i] = clamped_initval;
172 checkvalint = ptr[0];
179 for (uint32_t i = 0; i < numval; i++)
180 ptr[i] = clamped_initval;
181 checkvalint = ptr[0];
188 for (uint32_t i = 0; i < numval; i++)
189 ptr[i] = clamped_initval;
190 checkvalint = ptr[0];
196 for (uint32_t i = 0; i < numval; i++)
197 ptr[i] = clamped_initval;
198 checkvalint = ptr[0];
205 for (uint32_t i = 0; i < numval; i++)
213 for (uint32_t i = 0; i < numval; i++)
214 ptr[i] = clamped_initval;
215 checkvalint = ptr[0];
222 for (uint32_t i = 0; i < numval; i++)
223 ptr[i] = clamped_initval;
224 checkvaluint = ptr[0];
231 for (uint32_t i = 0; i < numval; i++)
232 ptr[i] = clamped_initval;
233 checkvalfloat = ptr[0];
239 for (uint32_t i = 0; i < numval; i++)
241 checkvaldouble = ptr[0];
246 rterror(
"%s: Unknown pixeltype %d", __func__, pixtype);
254 checkvalint, checkvaluint,
255 checkvalfloat, checkvaldouble,
284 uint16_t width, uint16_t height,
286 uint32_t hasnodata,
double nodataval,
287 uint8_t bandNum,
const char* path
292 assert(NULL != path);
296 rterror(
"rt_band_new_offline: Out of memory allocating rt_band");
304 band->pixtype = pixtype;
307 band->height = height;
308 band->hasnodata = hasnodata ? 1 : 0;
310 band->isnodata =
FALSE;
316 rterror(
"rt_band_new_offline: Could not set NODATA value");
321 band->data.offline.bandNum = bandNum;
324 pathlen = strlen(path);
325 band->data.offline.path =
rtalloc(
sizeof(
char) * (pathlen + 1));
326 if (band->data.offline.path == NULL) {
327 rterror(
"rt_band_new_offline: Out of memory allocating offline path");
331 memcpy(band->data.offline.path, path, pathlen);
332 band->data.offline.path[pathlen] =
'\0';
334 band->data.offline.mem = NULL;
367 GDALDatasetH hdsSrc = NULL;
369 GDALRasterBandH hbandSrc = NULL;
371 GDALDataType gdpixtype;
377 if (hdsSrc == NULL && !force) {
378 rterror(
"rt_band_new_offline_from_path: Cannot open offline raster: %s", path);
382 nband = GDALGetRasterCount(hdsSrc);
383 if (!nband && !force) {
384 rterror(
"rt_band_new_offline_from_path: No bands found in offline raster: %s", path);
389 else if (bandNum > nband && !force) {
391 "rt_band_new_offline_from_path: Specified band %d not found in offline raster: %s",
399 hbandSrc = GDALGetRasterBand(hdsSrc, bandNum);
400 if (hbandSrc == NULL && !force) {
402 "rt_band_new_offline_from_path: Cannot get band %d from GDAL dataset",
409 gdpixtype = GDALGetRasterDataType(hbandSrc);
411 if (pt ==
PT_END && !force) {
413 "rt_band_new_offline_from_path: Unsupported pixel type %s of band %d from GDAL dataset",
414 GDALGetDataTypeName(gdpixtype),
423 nodataval = GDALGetRasterNoDataValue(hbandSrc, &hasnodata);
430 hasnodata, nodataval,
449 assert(band != NULL);
454 band->width, band->height,
456 band->hasnodata, band->nodataval,
457 band->data.offline.bandNum, (
const char *) band->data.offline.path
462 uint8_t *data = NULL;
465 rterror(
"rt_band_duplicate: Out of memory allocating online band data");
468 memcpy(data, band->data.mem, (
size_t)
rt_pixtype_size(band->pixtype) * band->width * band->height);
471 band->width, band->height,
473 band->hasnodata, band->nodataval,
480 rterror(
"rt_band_duplicate: Could not copy band");
489 assert(NULL != band);
490 return band->offline ? 1 : 0;
508 if (band->data.offline.mem != NULL)
511 if (band->data.offline.path != NULL)
515 else if (band->data.mem != NULL && band->ownsdata)
524 assert(NULL != band);
527 if (!band->offline) {
528 RASTER_DEBUG(3,
"rt_band_get_ext_path: Band is not offline");
531 return band->data.offline.path;
536 assert(NULL != band);
537 assert(NULL != bandnum);
541 if (!band->offline) {
542 RASTER_DEBUG(3,
"rt_band_get_ext_band_num: Band is not offline");
546 *bandnum = band->data.offline.bandNum;
560 assert(NULL != band);
563 if (band->data.offline.mem != NULL)
564 return band->data.offline.mem;
569 return band->data.offline.mem;
572 return band->data.mem;
589 GDALDatasetH hdsSrc = NULL;
591 VRTDatasetH hdsDst = NULL;
592 VRTSourcedRasterBandH hbandDst = NULL;
594 double offset[2] = {0};
601 assert(band != NULL);
602 assert(band->raster != NULL);
604 if (!band->offline) {
605 rterror(
"rt_band_load_offline_data: Band is not offline");
608 else if (!strlen(band->data.offline.path)) {
609 rterror(
"rt_band_load_offline_data: Offline band does not a have a specified file");
615 rterror(
"rt_band_load_offline_data: Access to offline bands disabled");
621 if (hdsSrc == NULL) {
622 rterror(
"rt_band_load_offline_data: Cannot open offline raster: %s", band->data.offline.path);
627 nband = GDALGetRasterCount(hdsSrc);
629 rterror(
"rt_band_load_offline_data: No bands found in offline raster: %s", band->data.offline.path);
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);
641 if (GDALGetGeoTransform(hdsSrc, ogt) != CE_None) {
642 RASTER_DEBUG(4,
"Using default geotransform matrix (0, 1, 0, 0, 0, -1)");
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]);
661 rterror(
"rt_band_load_offline_data: Could not test alignment of in-db representation of out-db raster");
666 rtwarn(
"The in-db representation of the out-db raster is not aligned. Band data may be incorrect");
673 &(offset[0]), &(offset[1]),
680 hdsDst = VRTCreate(band->width, band->height);
681 GDALSetGeoTransform(hdsDst, ogt);
688 hbandDst = (VRTSourcedRasterBandH) GDALGetRasterBand(hdsDst, 1);
691 GDALSetRasterNoDataValue(hbandDst, band->nodataval);
694 hbandDst, GDALGetRasterBand(hdsSrc, band->data.offline.bandNum + 1),
695 fabs(offset[0]), fabs(offset[1]),
696 band->width, band->height,
698 band->width, band->height,
699 "near", VRT_NODATA_UNSET
703 VRTFlushCache(hdsDst);
720 rterror(
"rt_band_load_offline_data: Cannot load data from offline raster: %s", band->data.offline.path);
726 rterror(
"rt_band_load_offline_data: Cannot load data from offline raster: %s", band->data.offline.path);
732 if (band->data.offline.mem != NULL) {
734 band->data.offline.mem = NULL;
737 band->data.offline.mem = _band->
data.
mem;
748 assert(NULL != band);
749 if (!band->offline) {
750 rterror(
"rt_band_get_file_size: Band is not offline");
755 rterror(
"rt_band_get_file_size: Access to offline bands disabled");
759 if( VSIStatL(band->data.offline.path, &sStat) != 0 ) {
760 rterror(
"rt_band_get_file_size: Cannot access file");
764 return sStat.st_size;
770 assert(NULL != band);
771 if (!band->offline) {
772 rterror(
"rt_band_get_file_timestamp: Band is not offline");
777 rterror(
"rt_band_get_file_timestamp: Access to offline bands disabled");
781 if( VSIStatL(band->data.offline.path, &sStat) != 0 ) {
782 rterror(
"rt_band_get_file_timestamp: Cannot access file");
786 return sStat.st_mtime;
792 assert(NULL != band);
795 return band->pixtype;
801 assert(NULL != band);
810 assert(NULL != band);
819 assert(NULL != band);
821 return band->ownsdata ? 1 : 0;
827 assert(NULL != band);
829 band->ownsdata = flag ? 1 : 0;
834 assert(NULL != band);
836 return band->hasnodata ? 1 : 0;
842 assert(NULL != band);
844 band->hasnodata = (flag) ? 1 : 0;
847 if (!band->hasnodata && band->isnodata) {
848 RASTER_DEBUG(3,
"Setting isnodata to FALSE as band no longer has NODATA");
855 assert(NULL != band);
857 if (!band->hasnodata) {
862 rterror(
"rt_band_set_isnodata_flag: Cannot set isnodata flag as band has no NODATA");
867 band->isnodata = (flag) ? 1 : 0;
874 assert(NULL != band);
877 return band->isnodata ? 1 : 0;
894 int32_t checkvalint = 0;
895 uint32_t checkvaluint = 0;
896 float checkvalfloat = 0;
897 double checkvaldouble = 0;
899 assert(NULL != band);
901 if (converted != NULL)
904 pixtype = band->pixtype;
912 checkvalint = band->nodataval;
917 checkvalint = band->nodataval;
922 checkvalint = band->nodataval;
927 checkvalint = band->nodataval;
932 checkvalint = band->nodataval;
937 checkvalint = band->nodataval;
942 checkvalint = band->nodataval;
947 checkvalint = band->nodataval;
952 checkvaluint = band->nodataval;
959 checkvalfloat = (float)band->nodataval;
964 checkvalfloat = band->nodataval;
968 band->nodataval = val;
969 checkvaldouble = band->nodataval;
973 rterror(
"rt_band_set_nodata: Unknown pixeltype %d", pixtype);
979 RASTER_DEBUGF(3,
"rt_band_set_nodata: band->hasnodata = %d", band->hasnodata);
980 RASTER_DEBUGF(3,
"rt_band_set_nodata: band->nodataval = %f", band->nodataval);
989 checkvalint, checkvaluint,
990 checkvalfloat, checkvaldouble,
992 ) && converted != NULL) {
1022 void *vals, uint32_t len
1026 uint8_t *data = NULL;
1027 uint32_t offset = 0;
1029 assert(NULL != band);
1030 assert(vals != NULL && len > 0);
1034 if (band->offline) {
1035 rterror(
"rt_band_set_pixel_line not implemented yet for OFFDB bands");
1039 pixtype = band->pixtype;
1043 x < 0 || x >= band->width ||
1044 y < 0 || y >= band->height
1046 rterror(
"rt_band_set_pixel_line: Coordinates out of range (%d, %d) vs (%d, %d)", x, y, band->width, band->height);
1051 offset = x + (y * band->width);
1055 if (len > (band->width * band->height) - offset) {
1056 rterror(
"rt_band_set_pixel_line: Could not apply pixels as values length exceeds end of data");
1066 uint8_t *ptr = data;
1068 memcpy(ptr, vals, (
size_t)size * len);
1072 uint16_t *ptr = (uint16_t *) data;
1074 memcpy(ptr, vals, (
size_t)size * len);
1078 int16_t *ptr = (int16_t *) data;
1080 memcpy(ptr, vals, (
size_t)size * len);
1084 uint32_t *ptr = (uint32_t *) data;
1086 memcpy(ptr, vals, (
size_t)size * len);
1090 int32_t *ptr = (int32_t *) data;
1092 memcpy(ptr, vals, (
size_t)size * len);
1096 float *ptr = (
float *) data;
1098 memcpy(ptr, vals, (
size_t)size * len);
1102 double *ptr = (
double *) data;
1104 memcpy(ptr, vals, (
size_t)size * len);
1108 rterror(
"rt_band_set_pixel_line: Unknown pixeltype %d", pixtype);
1113#if POSTGIS_DEBUG_LEVEL > 0
1147 uint8_t *data = NULL;
1148 uint32_t offset = 0;
1150 int32_t checkvalint = 0;
1151 uint32_t checkvaluint = 0;
1152 float checkvalfloat = 0;
1153 double checkvaldouble = 0;
1155 assert(NULL != band);
1157 if (converted != NULL)
1160 if (band->offline) {
1161 rterror(
"rt_band_set_pixel not implemented yet for OFFDB bands");
1165 pixtype = band->pixtype;
1168 x < 0 || x >= band->width ||
1169 y < 0 || y >= band->height
1171 rterror(
"rt_band_set_pixel: Coordinates out of range");
1176 if (band->hasnodata && pixtype !=
PT_64BF) {
1183#if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
1184 rtwarn(
"Value for pixel %d x %d has been corrected as clamped value becomes NODATA", x, y);
1188 if (converted != NULL)
1194 offset = x + (y * band->width);
1200 checkvalint = data[offset];
1205 checkvalint = data[offset];
1210 checkvalint = data[offset];
1215 checkvalint = (int8_t) data[offset];
1220 checkvalint = data[offset];
1224 int16_t *ptr = (int16_t*) data;
1226 checkvalint = (int16_t) ptr[offset];
1230 uint16_t *ptr = (uint16_t*) data;
1232 checkvalint = ptr[offset];
1236 int32_t *ptr = (int32_t*) data;
1238 checkvalint = (int32_t) ptr[offset];
1242 uint32_t *ptr = (uint32_t *)data;
1244 checkvaluint = ptr[offset];
1248 uint16_t *ptr = (uint16_t *)data;
1256 float *ptr = (
float *)data;
1258 checkvalfloat = ptr[offset];
1262 double *ptr = (
double*) data;
1264 checkvaldouble = ptr[offset];
1268 rterror(
"rt_band_set_pixel: Unknown pixeltype %d", pixtype);
1275 RASTER_DEBUG(3,
"Band has a value that is not NODATA. Setting isnodata to FALSE");
1276 band->isnodata =
FALSE;
1282 checkvalint, checkvaluint,
1283 checkvalfloat, checkvaldouble,
1285 ) && converted != NULL) {
1316 void **vals, uint16_t *nvals
1318 uint8_t *_vals = NULL;
1320 uint8_t *data = NULL;
1321 uint32_t offset = 0;
1322 uint16_t _nvals = 0;
1324 uint8_t *ptr = NULL;
1326 assert(NULL != band);
1327 assert(vals != NULL && nvals != NULL);
1333 x < 0 || x >= band->width ||
1334 y < 0 || y >= band->height
1336 rtwarn(
"Attempting to get pixel values with out of range raster coordinates: (%d, %d)", x, y);
1345 rterror(
"rt_band_get_pixel_line: Cannot get band data");
1350 offset = x + (y * band->width);
1358 maxlen = band->width * band->height;
1360 if (((
int) (offset + _nvals)) > maxlen) {
1361 _nvals = maxlen - offset;
1362 rtwarn(
"Limiting returning number values to %d", _nvals);
1366 ptr = data + ((size_t)offset * pixsize);
1368 _vals =
rtalloc((
size_t)_nvals * pixsize);
1369 if (_vals == NULL) {
1370 rterror(
"rt_band_get_pixel_line: Could not allocate memory for pixel values");
1375 memcpy(_vals, ptr, (
size_t)_nvals * pixsize);
1398 double xr,
double yr,
1400 double *r_value,
int *r_nodata
1405 band, xr, yr, r_value, r_nodata
1410 band, floor(xr), floor(yr),
1415 rtwarn(
"Invalid resample type requested %d", resample);
1437 double xr,
double yr,
1438 double *r_value,
int *r_nodata)
1440 double xcenter, ycenter;
1441 double values[2][2];
1442 double nodatavalue = 0.0;
1449 uint16_t width, height;
1452 xcell = (int)floor(xr);
1453 ycell = (int)floor(yr);
1454 xcenter = xcell + 0.5;
1455 ycenter = ycell + 0.5;
1462 if(xcell < 0 || ycell < 0 || xcell >= width || ycell >= height) {
1463 rtwarn(
"Attempting to get pixel value with out of range raster coordinates: (%d, %d)", xcell, ycell);
1468 xdir = xr < xcenter ? 1 : 0;
1469 ydir = yr < ycenter ? 1 : 0;
1479 for (i = 0; i < 2; i++) {
1480 for (j = 0; j < 2; j++) {
1481 double value = nodatavalue;
1483 int xij = xcell + (i - xdir);
1484 int yij = ycell + (j - ydir);
1486 if(xij < 0 || yij < 0 || xij >= width || yij >= height) {
1499 values[i][j] = value;
1500 nodatas[i][j] = nodata;
1505 if (nodatas[xdir][ydir]) {
1506 *r_value = nodatavalue;
1513 xr = xr - (x[0][0] + 0.5);
1514 yr = yr - (y[0][0] + 0.5);
1519 for (i = 0; i < 2; i++) {
1520 for (j = 0; j < 2; j++) {
1522 values[i][j] = values[xdir][ydir];
1529 *r_value = values[0][0] * (1-xr) * (1-yr) +
1530 values[1][0] * (1-yr) * xr +
1531 values[0][1] * (1-xr) * yr +
1532 values[1][1] * xr * yr;
1558 uint8_t* data = NULL;
1559 uint32_t offset = 0;
1561 assert(NULL != band);
1562 assert(NULL != value);
1569 x < 0 || x >= band->width ||
1570 y < 0 || y >= band->height
1572 rtwarn(
"Attempting to get pixel value with out of range raster coordinates: (%d, %d)", x, y);
1577 if (band->isnodata) {
1578 RASTER_DEBUG(3,
"Band's isnodata flag is TRUE. Returning NODATA value");
1579 *value = band->nodataval;
1580 if (nodata != NULL) *nodata = 1;
1586 rterror(
"rt_band_get_pixel: Cannot get band data");
1591 offset = x + (y * band->width);
1593 pixtype = band->pixtype;
1597#ifdef OPTIMIZE_SPACE
1599 int byteOffset = offset / 8;
1600 int bitOffset = offset % 8;
1604 *value = getBits(data, val, 1, bitOffset);
1609#ifdef OPTIMIZE_SPACE
1611 int byteOffset = offset / 4;
1612 int bitOffset = offset % 4;
1616 *value = getBits(data, val, 2, bitOffset);
1621#ifdef OPTIMIZE_SPACE
1623 int byteOffset = offset / 2;
1624 int bitOffset = offset % 2;
1628 *value = getBits(data, val, 2, bitOffset);
1633 int8_t val = (int8_t)data[offset];
1638 uint8_t val = data[offset];
1643 int16_t *ptr = (int16_t*) data;
1644 *value = ptr[offset];
1648 uint16_t *ptr = (uint16_t*) data;
1649 *value = ptr[offset];
1653 int32_t *ptr = (int32_t*) data;
1654 *value = ptr[offset];
1658 uint32_t *ptr = (uint32_t *)data;
1659 *value = ptr[offset];
1663 uint16_t *ptr = (uint16_t *)data;
1668 float *ptr = (
float *)data;
1669 *value = ptr[offset];
1673 double *ptr = (
double*) data;
1674 *value = ptr[offset];
1678 rterror(
"rt_band_get_pixel: Unknown pixeltype %d", pixtype);
1684 if (band->hasnodata && nodata != NULL) {
1712 uint16_t distancex, uint16_t distancey,
1713 int exclude_nodata_value,
1717 int extent[4] = {0};
1718 int max_extent[4] = {0};
1721 uint32_t _d[2] = {0};
1736 assert(NULL != band);
1737 assert(NULL != npixels);
1754 exclude_nodata_value && (
1755 (x < 0 || x > band->width) ||
1756 (y < 0 || y > band->height)
1763 else if (x > band->width)
1768 else if (y > band->height)
1778 ((x < 0 && (uint32_t) abs(x) >
distance[0]) || (x - band->width >= (
int)
distance[0])) ||
1779 ((y < 0 && (uint32_t) abs(y) >
distance[1]) || (y - band->height >= (
int)
distance[1]))
1781 RASTER_DEBUG(4,
"No nearest pixels possible for provided pixel and distances");
1787 if (!band->hasnodata)
1788 exclude_nodata_value =
FALSE;
1790 else if (exclude_nodata_value && band->isnodata) {
1791 RASTER_DEBUG(4,
"No nearest pixels possible as band is NODATA and excluding NODATA values");
1801 b = abs(x - band->width);
1810 b = abs(y - band->height);
1829 max_extent[0] = x - (int)
distance[0];
1830 max_extent[1] = y - (int)
distance[1];
1831 max_extent[2] = x + (int)
distance[0];
1832 max_extent[3] = y + (int)
distance[1];
1834 max_extent[0], max_extent[1], max_extent[2], max_extent[3]);
1842 extent[0] = x - (int)_d[0];
1843 extent[1] = y - (int)_d[1];
1844 extent[2] = x + (int)_d[0];
1845 extent[3] = y + (int)_d[1];
1847 RASTER_DEBUGF(4,
"Processing distances: %d x %d", _d[0], _d[1]);
1849 extent[0], extent[1], extent[2], extent[3]);
1851 for (i = 0; i < 2; i++) {
1855 _max = extent[2] - extent[0] + 1;
1858 _max = extent[3] - extent[1] + 1;
1861 for (j = 0; j < 2; j++) {
1890 for (k = 0; k < (uint32_t) _max; k++) {
1893 _x < max_extent[0] || _x > max_extent[2] ||
1894 _y < max_extent[1] || _y > max_extent[3]
1902 (_x < 0 || _x >= band->width) ||
1903 (_y < 0 || _y >= band->height)
1906 if (!band->hasnodata)
1910 pixval = band->nodataval;
1911 RASTER_DEBUGF(4,
"NODATA pixel outside band extent: (x, y, val) = (%d, %d, %f)", _x, _y,
pixval);
1922 rterror(
"rt_band_get_nearest_pixel: Could not get pixel value");
1931 if (!exclude_nodata_value || (exclude_nodata_value && !isnodata)) {
1933 RASTER_DEBUGF(4,
"Adding pixel to set of nearest pixels: (x, y, val) = (%d, %d, %f)", _x, _y,
pixval);
1936 if (*npixels == NULL)
1940 if (*npixels == NULL) {
1941 rterror(
"rt_band_get_nearest_pixel: Could not allocate memory for nearest pixel(s)");
1945 npixel = &((*npixels)[count - 1]);
1951 if (!inextent && !band->hasnodata)
1965 else if (d0 && count)
1990 rt_band band,
int exclude_nodata_value,
1991 double *searchset,
int searchcount,
2005 assert(NULL != band);
2006 assert(NULL != pixels);
2007 assert(NULL != searchset && searchcount > 0);
2009 if (!band->hasnodata)
2010 exclude_nodata_value =
FALSE;
2012 else if (exclude_nodata_value && band->isnodata) {
2013 RASTER_DEBUG(4,
"Pixels cannot be searched as band is NODATA and excluding NODATA values");
2017 for (x = 0; x < band->width; x++) {
2018 for (y = 0; y < band->height; y++) {
2021 rterror(
"rt_band_get_pixel_of_value: Cannot get band pixel");
2024 else if (exclude_nodata_value && isnodata)
2027 for (i = 0; i < searchcount; i++) {
2037 if (*pixels == NULL)
2041 if (*pixels == NULL) {
2042 rterror(
"rt_band_get_pixel_of_value: Could not allocate memory for pixel(s)");
2046 pixel = &((*pixels)[count - 1]);
2068 assert(NULL != band);
2069 assert(NULL != nodata);
2071 *nodata = band->nodataval;
2073 if (!band->hasnodata) {
2074 rterror(
"rt_band_get_nodata: Band has no NODATA value");
2083 assert(NULL != band);
2094 assert(NULL != band);
2095 band->isnodata =
FALSE;
2098 if (!band->hasnodata) {
2103 pxValue = band->nodataval;
2106 for (i = 0; i < band->width; i++) {
2107 for (j = 0; j < band->height; j++) {
2110 rterror(
"rt_band_check_is_nodata: Cannot get band pixel");
2113 else if (!isnodata) {
2114 band->isnodata =
FALSE;
2120 band->isnodata =
TRUE;
2138 assert(NULL != band);
2141 if (!band->hasnodata)
2145 if (
FLT_EQ(val, band->nodataval))
2151 val, band->nodataval,
2155 return isequal ? 1 : 0;
2174 double *newval,
int *corrected
2178 assert(NULL != band);
2179 assert(NULL != newval);
2181 if (corrected != NULL)
2193 switch (band->pixtype) {
2195 *newval = !band->nodataval;
2247 *newval += FLT_EPSILON;
2249 *newval -= FLT_EPSILON;
2253 *newval += FLT_EPSILON;
2255 *newval -= FLT_EPSILON;
2260 rterror(
"rt_band_corrected_clamped_value: Unknown pixeltype %d", band->pixtype);
2264 if (corrected != NULL)
void rterror(const char *fmt,...) __attribute__((format(printf
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)
float rt_util_clamp_to_16F(double value)
void void void rtwarn(const char *fmt,...) __attribute__((format(printf
int32_t rt_util_clamp_to_32BSI(double value)
uint16_t rt_util_float_to_float16(float value)
float rt_util_float16_to_float(uint16_t 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)
const char * rt_pixtype_name(rt_pixtype pixtype)
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)
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)
void rt_band_init_value(rt_band band, double initval)
Fill in the cells of a band with a starting value frequently used to init with nodata value.
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.
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.
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
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.
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_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.
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::@12 data