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");
116 assert(
band != NULL);
117 assert(
band->data.mem != NULL);
119 uint32_t width =
band->width;
120 uint32_t height =
band->height;
121 uint32_t numval = width * height;
122 void *mem =
band->data.mem;
126 int32_t checkvalint = 0;
127 uint32_t checkvaluint = 0;
128 double checkvaldouble = 0;
129 float checkvalfloat = 0;
132 if (
FLT_EQ(initval, 0.0)) {
133 memset(mem, 0, memsize);
142 for (uint32_t i = 0; i < numval; i++)
143 ptr[i] = clamped_initval;
144 checkvalint = ptr[0];
151 for (uint32_t i = 0; i < numval; i++)
152 ptr[i] = clamped_initval;
153 checkvalint = ptr[0];
160 for (uint32_t i = 0; i < numval; i++)
161 ptr[i] = clamped_initval;
162 checkvalint = ptr[0];
169 for (uint32_t i = 0; i < numval; i++)
170 ptr[i] = clamped_initval;
171 checkvalint = ptr[0];
178 for (uint32_t i = 0; i < numval; i++)
179 ptr[i] = clamped_initval;
180 checkvalint = ptr[0];
187 for (uint32_t i = 0; i < numval; i++)
188 ptr[i] = clamped_initval;
189 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++)
206 ptr[i] = clamped_initval;
207 checkvalint = ptr[0];
214 for (uint32_t i = 0; i < numval; i++)
215 ptr[i] = clamped_initval;
216 checkvaluint = ptr[0];
223 for (uint32_t i = 0; i < numval; i++)
224 ptr[i] = clamped_initval;
225 checkvalfloat = ptr[0];
231 for (uint32_t i = 0; i < numval; i++)
233 checkvaldouble = ptr[0];
238 rterror(
"%s: Unknown pixeltype %d", __func__, pixtype);
246 checkvalint, checkvaluint,
247 checkvalfloat, checkvaldouble,
276 uint16_t width, uint16_t height,
278 uint32_t hasnodata,
double nodataval,
279 uint8_t bandNum,
const char* path
284 assert(NULL != path);
288 rterror(
"rt_band_new_offline: Out of memory allocating rt_band");
296 band->pixtype = pixtype;
299 band->height = height;
300 band->hasnodata = hasnodata ? 1 : 0;
308 rterror(
"rt_band_new_offline: Could not set NODATA value");
313 band->data.offline.bandNum = bandNum;
316 pathlen = strlen(path);
317 band->data.offline.path =
rtalloc(
sizeof(
char) * (pathlen + 1));
318 if (
band->data.offline.path == NULL) {
319 rterror(
"rt_band_new_offline: Out of memory allocating offline path");
323 memcpy(
band->data.offline.path, path, pathlen);
324 band->data.offline.path[pathlen] =
'\0';
326 band->data.offline.mem = NULL;
359 GDALDatasetH hdsSrc = NULL;
361 GDALRasterBandH hbandSrc = NULL;
363 GDALDataType gdpixtype;
369 if (hdsSrc == NULL && !force) {
370 rterror(
"rt_band_new_offline_from_path: Cannot open offline raster: %s", path);
374 nband = GDALGetRasterCount(hdsSrc);
375 if (!
nband && !force) {
376 rterror(
"rt_band_new_offline_from_path: No bands found in offline raster: %s", path);
381 else if (bandNum >
nband && !force) {
383 "rt_band_new_offline_from_path: Specified band %d not found in offline raster: %s",
391 hbandSrc = GDALGetRasterBand(hdsSrc, bandNum);
392 if (hbandSrc == NULL && !force) {
394 "rt_band_new_offline_from_path: Cannot get band %d from GDAL dataset",
401 gdpixtype = GDALGetRasterDataType(hbandSrc);
403 if (pt ==
PT_END && !force) {
405 "rt_band_new_offline_from_path: Unsupported pixel type %s of band %d from GDAL dataset",
406 GDALGetDataTypeName(gdpixtype),
415 nodataval = GDALGetRasterNoDataValue(hbandSrc, &hasnodata);
422 hasnodata, nodataval,
441 assert(
band != NULL);
449 band->data.offline.bandNum, (
const char *)
band->data.offline.path
454 uint8_t *
data = NULL;
457 rterror(
"rt_band_duplicate: Out of memory allocating online band data");
472 rterror(
"rt_band_duplicate: Could not copy band");
481 assert(NULL !=
band);
482 return band->offline ? 1 : 0;
500 if (
band->data.offline.mem != NULL)
503 if (
band->data.offline.path != NULL)
507 else if (
band->data.mem != NULL &&
band->ownsdata)
516 assert(NULL !=
band);
519 if (!
band->offline) {
520 RASTER_DEBUG(3,
"rt_band_get_ext_path: Band is not offline");
523 return band->data.offline.path;
528 assert(NULL !=
band);
529 assert(NULL != bandnum);
533 if (!
band->offline) {
534 RASTER_DEBUG(3,
"rt_band_get_ext_band_num: Band is not offline");
538 *bandnum =
band->data.offline.bandNum;
552 assert(NULL !=
band);
555 if (
band->data.offline.mem != NULL)
556 return band->data.offline.mem;
561 return band->data.offline.mem;
564 return band->data.mem;
581 GDALDatasetH hdsSrc = NULL;
583 VRTDatasetH hdsDst = NULL;
584 VRTSourcedRasterBandH hbandDst = NULL;
586 double offset[2] = {0};
593 assert(
band != NULL);
594 assert(
band->raster != NULL);
596 if (!
band->offline) {
597 rterror(
"rt_band_load_offline_data: Band is not offline");
600 else if (!strlen(
band->data.offline.path)) {
601 rterror(
"rt_band_load_offline_data: Offline band does not a have a specified file");
607 rterror(
"rt_band_load_offline_data: Access to offline bands disabled");
613 if (hdsSrc == NULL) {
614 rterror(
"rt_band_load_offline_data: Cannot open offline raster: %s",
band->data.offline.path);
619 nband = GDALGetRasterCount(hdsSrc);
621 rterror(
"rt_band_load_offline_data: No bands found in offline raster: %s",
band->data.offline.path);
626 else if (
band->data.offline.bandNum + 1 >
nband) {
627 rterror(
"rt_band_load_offline_data: Specified band %d not found in offline raster: %s",
band->data.offline.bandNum,
band->data.offline.path);
633 if (GDALGetGeoTransform(hdsSrc, ogt) != CE_None) {
634 RASTER_DEBUG(4,
"Using default geotransform matrix (0, 1, 0, 0, 0, -1)");
642 RASTER_DEBUGF(3,
"Offline geotransform (%f, %f, %f, %f, %f, %f)",
643 ogt[0], ogt[1], ogt[2], ogt[3], ogt[4], ogt[5]);
653 rterror(
"rt_band_load_offline_data: Could not test alignment of in-db representation of out-db raster");
658 rtwarn(
"The in-db representation of the out-db raster is not aligned. Band data may be incorrect");
665 &(offset[0]), &(offset[1]),
672 hdsDst = VRTCreate(
band->width,
band->height);
673 GDALSetGeoTransform(hdsDst, ogt);
680 hbandDst = (VRTSourcedRasterBandH) GDALGetRasterBand(hdsDst, 1);
683 GDALSetRasterNoDataValue(hbandDst,
band->nodataval);
686 hbandDst, GDALGetRasterBand(hdsSrc,
band->data.offline.bandNum + 1),
687 fabs(offset[0]), fabs(offset[1]),
691 "near", VRT_NODATA_UNSET
695 VRTFlushCache(hdsDst);
712 rterror(
"rt_band_load_offline_data: Cannot load data from offline raster: %s",
band->data.offline.path);
718 rterror(
"rt_band_load_offline_data: Cannot load data from offline raster: %s",
band->data.offline.path);
724 if (
band->data.offline.mem != NULL) {
726 band->data.offline.mem = NULL;
740 assert(NULL !=
band);
741 if (!
band->offline) {
742 rterror(
"rt_band_get_file_size: Band is not offline");
747 rterror(
"rt_band_get_file_size: Access to offline bands disabled");
751 if( VSIStatL(
band->data.offline.path, &sStat) != 0 ) {
752 rterror(
"rt_band_get_file_size: Cannot access file");
756 return sStat.st_size;
762 assert(NULL !=
band);
763 if (!
band->offline) {
764 rterror(
"rt_band_get_file_timestamp: Band is not offline");
769 rterror(
"rt_band_get_file_timestamp: Access to offline bands disabled");
773 if( VSIStatL(
band->data.offline.path, &sStat) != 0 ) {
774 rterror(
"rt_band_get_file_timestamp: Cannot access file");
778 return sStat.st_mtime;
784 assert(NULL !=
band);
787 return band->pixtype;
793 assert(NULL !=
band);
802 assert(NULL !=
band);
811 assert(NULL !=
band);
813 return band->ownsdata ? 1 : 0;
819 assert(NULL !=
band);
821 band->ownsdata = flag ? 1 : 0;
826 assert(NULL !=
band);
828 return band->hasnodata ? 1 : 0;
834 assert(NULL !=
band);
836 band->hasnodata = (flag) ? 1 : 0;
839 if (!
band->hasnodata &&
band->isnodata) {
840 RASTER_DEBUG(3,
"Setting isnodata to FALSE as band no longer has NODATA");
847 assert(NULL !=
band);
849 if (!
band->hasnodata) {
854 rterror(
"rt_band_set_isnodata_flag: Cannot set isnodata flag as band has no NODATA");
859 band->isnodata = (flag) ? 1 : 0;
866 assert(NULL !=
band);
869 return band->isnodata ? 1 : 0;
886 int32_t checkvalint = 0;
887 uint32_t checkvaluint = 0;
888 float checkvalfloat = 0;
889 double checkvaldouble = 0;
891 assert(NULL !=
band);
893 if (converted != NULL)
896 pixtype =
band->pixtype;
904 checkvalint =
band->nodataval;
909 checkvalint =
band->nodataval;
914 checkvalint =
band->nodataval;
919 checkvalint =
band->nodataval;
924 checkvalint =
band->nodataval;
929 checkvalint =
band->nodataval;
934 checkvalint =
band->nodataval;
939 checkvalint =
band->nodataval;
944 checkvaluint =
band->nodataval;
949 checkvalfloat =
band->nodataval;
953 band->nodataval = val;
954 checkvaldouble =
band->nodataval;
958 rterror(
"rt_band_set_nodata: Unknown pixeltype %d", pixtype);
974 checkvalint, checkvaluint,
975 checkvalfloat, checkvaldouble,
977 ) && converted != NULL) {
1007 void *vals, uint32_t len
1011 uint8_t *
data = NULL;
1012 uint32_t offset = 0;
1014 assert(NULL !=
band);
1015 assert(vals != NULL && len > 0);
1019 if (
band->offline) {
1020 rterror(
"rt_band_set_pixel_line not implemented yet for OFFDB bands");
1024 pixtype =
band->pixtype;
1028 x < 0 || x >=
band->width ||
1029 y < 0 || y >=
band->height
1031 rterror(
"rt_band_set_pixel_line: Coordinates out of range (%d, %d) vs (%d, %d)",
x,
y,
band->width,
band->height);
1036 offset =
x + (
y *
band->width);
1040 if (len > (
band->width *
band->height) - offset) {
1041 rterror(
"rt_band_set_pixel_line: Could not apply pixels as values length exceeds end of data");
1051 uint8_t *ptr =
data;
1053 memcpy(ptr, vals, (
size_t)size * len);
1057 uint16_t *ptr = (uint16_t *)
data;
1059 memcpy(ptr, vals, (
size_t)size * len);
1063 int16_t *ptr = (int16_t *)
data;
1065 memcpy(ptr, vals, (
size_t)size * len);
1069 uint32_t *ptr = (uint32_t *)
data;
1071 memcpy(ptr, vals, (
size_t)size * len);
1075 int32_t *ptr = (int32_t *)
data;
1077 memcpy(ptr, vals, (
size_t)size * len);
1081 float *ptr = (
float *)
data;
1083 memcpy(ptr, vals, (
size_t)size * len);
1087 double *ptr = (
double *)
data;
1089 memcpy(ptr, vals, (
size_t)size * len);
1093 rterror(
"rt_band_set_pixel_line: Unknown pixeltype %d", pixtype);
1098 #if POSTGIS_DEBUG_LEVEL > 0
1132 uint8_t *
data = NULL;
1133 uint32_t offset = 0;
1135 int32_t checkvalint = 0;
1136 uint32_t checkvaluint = 0;
1137 float checkvalfloat = 0;
1138 double checkvaldouble = 0;
1140 assert(NULL !=
band);
1142 if (converted != NULL)
1145 if (
band->offline) {
1146 rterror(
"rt_band_set_pixel not implemented yet for OFFDB bands");
1150 pixtype =
band->pixtype;
1153 x < 0 || x >=
band->width ||
1154 y < 0 || y >=
band->height
1156 rterror(
"rt_band_set_pixel: Coordinates out of range");
1168 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
1169 rtwarn(
"Value for pixel %d x %d has been corrected as clamped value becomes NODATA",
x,
y);
1173 if (converted != NULL)
1179 offset =
x + (
y *
band->width);
1184 checkvalint =
data[offset];
1189 checkvalint =
data[offset];
1194 checkvalint =
data[offset];
1199 checkvalint = (int8_t)
data[offset];
1204 checkvalint =
data[offset];
1208 int16_t *ptr = (int16_t*)
data;
1210 checkvalint = (int16_t) ptr[offset];
1214 uint16_t *ptr = (uint16_t*)
data;
1216 checkvalint = ptr[offset];
1220 int32_t *ptr = (int32_t*)
data;
1222 checkvalint = (int32_t) ptr[offset];
1226 uint32_t *ptr = (uint32_t*)
data;
1228 checkvaluint = ptr[offset];
1232 float *ptr = (
float*)
data;
1234 checkvalfloat = ptr[offset];
1238 double *ptr = (
double*)
data;
1240 checkvaldouble = ptr[offset];
1244 rterror(
"rt_band_set_pixel: Unknown pixeltype %d", pixtype);
1251 RASTER_DEBUG(3,
"Band has a value that is not NODATA. Setting isnodata to FALSE");
1258 checkvalint, checkvaluint,
1259 checkvalfloat, checkvaldouble,
1261 ) && converted != NULL) {
1292 void **vals, uint16_t *nvals
1294 uint8_t *_vals = NULL;
1296 uint8_t *
data = NULL;
1297 uint32_t offset = 0;
1298 uint16_t _nvals = 0;
1300 uint8_t *ptr = NULL;
1302 assert(NULL !=
band);
1303 assert(vals != NULL && nvals != NULL);
1309 x < 0 || x >=
band->width ||
1310 y < 0 || y >=
band->height
1312 rtwarn(
"Attempting to get pixel values with out of range raster coordinates: (%d, %d)",
x,
y);
1321 rterror(
"rt_band_get_pixel_line: Cannot get band data");
1326 offset =
x + (
y *
band->width);
1334 maxlen =
band->width *
band->height;
1336 if (((
int) (offset + _nvals)) > maxlen) {
1337 _nvals = maxlen - offset;
1338 rtwarn(
"Limiting returning number values to %d", _nvals);
1342 ptr =
data + ((size_t)offset * pixsize);
1344 _vals =
rtalloc((
size_t)_nvals * pixsize);
1345 if (_vals == NULL) {
1346 rterror(
"rt_band_get_pixel_line: Could not allocate memory for pixel values");
1351 memcpy(_vals, ptr, (
size_t)_nvals * pixsize);
1374 double xr,
double yr,
1376 double *r_value,
int *r_nodata
1381 band, xr, yr, r_value, r_nodata
1386 band, floor(xr), floor(yr),
1391 rtwarn(
"Invalid resample type requested %d", resample);
1413 double xr,
double yr,
1414 double *r_value,
int *r_nodata)
1416 double xcenter, ycenter;
1417 double values[2][2];
1418 double nodatavalue = 0.0;
1425 uint16_t width, height;
1428 xcell = (int)floor(xr);
1429 ycell = (int)floor(yr);
1430 xcenter = xcell + 0.5;
1431 ycenter = ycell + 0.5;
1438 if(xcell < 0 || ycell < 0 || xcell >= width || ycell >= height) {
1439 rtwarn(
"Attempting to get pixel value with out of range raster coordinates: (%d, %d)", xcell, ycell);
1444 xdir = xr < xcenter ? 1 : 0;
1445 ydir = yr < ycenter ? 1 : 0;
1455 for (i = 0; i < 2; i++) {
1456 for (j = 0; j < 2; j++) {
1457 double value = nodatavalue;
1459 int xij = xcell + (i - xdir);
1460 int yij = ycell + (j - ydir);
1462 if(xij < 0 || yij < 0 || xij >= width || yij >= height) {
1475 values[i][j] =
value;
1476 nodatas[i][j] = nodata;
1481 if (nodatas[xdir][ydir]) {
1482 *r_value = nodatavalue;
1489 xr = xr - (
x[0][0] + 0.5);
1490 yr = yr - (
y[0][0] + 0.5);
1495 for (i = 0; i < 2; i++) {
1496 for (j = 0; j < 2; j++) {
1498 values[i][j] = values[xdir][ydir];
1505 *r_value = values[0][0] * (1-xr) * (1-yr) +
1506 values[1][0] * (1-yr) * xr +
1507 values[0][1] * (1-xr) * yr +
1508 values[1][1] * xr * yr;
1534 uint8_t*
data = NULL;
1535 uint32_t offset = 0;
1537 assert(NULL !=
band);
1538 assert(NULL !=
value);
1545 x < 0 || x >=
band->width ||
1546 y < 0 || y >=
band->height
1548 rtwarn(
"Attempting to get pixel value with out of range raster coordinates: (%d, %d)",
x,
y);
1553 if (
band->isnodata) {
1554 RASTER_DEBUG(3,
"Band's isnodata flag is TRUE. Returning NODATA value");
1556 if (nodata != NULL) *nodata = 1;
1562 rterror(
"rt_band_get_pixel: Cannot get band data");
1567 offset =
x + (
y *
band->width);
1569 pixtype =
band->pixtype;
1573 #ifdef OPTIMIZE_SPACE
1575 int byteOffset = offset / 8;
1576 int bitOffset = offset % 8;
1580 *
value = getBits(
data, val, 1, bitOffset);
1585 #ifdef OPTIMIZE_SPACE
1587 int byteOffset = offset / 4;
1588 int bitOffset = offset % 4;
1592 *
value = getBits(
data, val, 2, bitOffset);
1597 #ifdef OPTIMIZE_SPACE
1599 int byteOffset = offset / 2;
1600 int bitOffset = offset % 2;
1604 *
value = getBits(
data, val, 2, bitOffset);
1609 int8_t val = (int8_t)
data[offset];
1614 uint8_t val =
data[offset];
1619 int16_t *ptr = (int16_t*)
data;
1620 *
value = ptr[offset];
1624 uint16_t *ptr = (uint16_t*)
data;
1625 *
value = ptr[offset];
1629 int32_t *ptr = (int32_t*)
data;
1630 *
value = ptr[offset];
1634 uint32_t *ptr = (uint32_t*)
data;
1635 *
value = ptr[offset];
1639 float *ptr = (
float*)
data;
1640 *
value = ptr[offset];
1644 double *ptr = (
double*)
data;
1645 *
value = ptr[offset];
1649 rterror(
"rt_band_get_pixel: Unknown pixeltype %d", pixtype);
1655 if (
band->hasnodata && nodata != NULL) {
1683 uint16_t distancex, uint16_t distancey,
1684 int exclude_nodata_value,
1688 int extent[4] = {0};
1689 int max_extent[4] = {0};
1692 uint32_t _d[2] = {0};
1707 assert(NULL !=
band);
1708 assert(NULL != npixels);
1725 exclude_nodata_value && (
1726 (x < 0 || x >
band->width) ||
1727 (y < 0 || y >
band->height)
1734 else if (
x >
band->width)
1739 else if (
y >
band->height)
1752 RASTER_DEBUG(4,
"No nearest pixels possible for provided pixel and distances");
1758 if (!
band->hasnodata)
1759 exclude_nodata_value =
FALSE;
1761 else if (exclude_nodata_value &&
band->isnodata) {
1762 RASTER_DEBUG(4,
"No nearest pixels possible as band is NODATA and excluding NODATA values");
1772 b = abs(
x -
band->width);
1781 b = abs(
y -
band->height);
1805 max_extent[0], max_extent[1], max_extent[2], max_extent[3]);
1813 extent[0] =
x - (int)_d[0];
1814 extent[1] =
y - (int)_d[1];
1815 extent[2] =
x + (int)_d[0];
1816 extent[3] =
y + (int)_d[1];
1818 RASTER_DEBUGF(4,
"Processing distances: %d x %d", _d[0], _d[1]);
1820 extent[0], extent[1], extent[2], extent[3]);
1822 for (i = 0; i < 2; i++) {
1826 _max = extent[2] - extent[0] + 1;
1829 _max = extent[3] - extent[1] + 1;
1832 for (j = 0; j < 2; j++) {
1861 for (k = 0; k < (uint32_t) _max; k++) {
1864 _x < max_extent[0] || _x > max_extent[2] ||
1865 _y < max_extent[1] || _y > max_extent[3]
1873 (_x < 0 || _x >=
band->width) ||
1874 (_y < 0 || _y >=
band->height)
1877 if (!
band->hasnodata)
1882 RASTER_DEBUGF(4,
"NODATA pixel outside band extent: (x, y, val) = (%d, %d, %f)", _x, _y,
pixval);
1893 rterror(
"rt_band_get_nearest_pixel: Could not get pixel value");
1902 if (!exclude_nodata_value || (exclude_nodata_value && !isnodata)) {
1904 RASTER_DEBUGF(4,
"Adding pixel to set of nearest pixels: (x, y, val) = (%d, %d, %f)", _x, _y,
pixval);
1907 if (*npixels == NULL)
1911 if (*npixels == NULL) {
1912 rterror(
"rt_band_get_nearest_pixel: Could not allocate memory for nearest pixel(s)");
1916 npixel = &((*npixels)[
count - 1]);
1922 if (!inextent && !
band->hasnodata)
1936 else if (d0 &&
count)
1962 double *searchset,
int searchcount,
1976 assert(NULL !=
band);
1977 assert(NULL != pixels);
1978 assert(NULL != searchset && searchcount > 0);
1980 if (!
band->hasnodata)
1981 exclude_nodata_value =
FALSE;
1983 else if (exclude_nodata_value &&
band->isnodata) {
1984 RASTER_DEBUG(4,
"Pixels cannot be searched as band is NODATA and excluding NODATA values");
1988 for (
x = 0;
x <
band->width;
x++) {
1989 for (
y = 0;
y <
band->height;
y++) {
1992 rterror(
"rt_band_get_pixel_of_value: Cannot get band pixel");
1995 else if (exclude_nodata_value && isnodata)
1998 for (i = 0; i < searchcount; i++) {
2008 if (*pixels == NULL)
2012 if (*pixels == NULL) {
2013 rterror(
"rt_band_get_pixel_of_value: Could not allocate memory for pixel(s)");
2039 assert(NULL !=
band);
2040 assert(NULL != nodata);
2042 *nodata =
band->nodataval;
2044 if (!
band->hasnodata) {
2045 rterror(
"rt_band_get_nodata: Band has no NODATA value");
2054 assert(NULL !=
band);
2065 assert(NULL !=
band);
2069 if (!
band->hasnodata) {
2074 pxValue =
band->nodataval;
2077 for (i = 0; i <
band->width; i++) {
2078 for (j = 0; j <
band->height; j++) {
2081 rterror(
"rt_band_check_is_nodata: Cannot get band pixel");
2084 else if (!isnodata) {
2109 assert(NULL !=
band);
2112 if (!
band->hasnodata)
2122 val,
band->nodataval,
2126 return isequal ? 1 : 0;
2145 double *newval,
int *corrected
2149 assert(NULL !=
band);
2150 assert(NULL != newval);
2152 if (corrected != NULL)
2164 switch (
band->pixtype) {
2166 *newval = !
band->nodataval;
2218 *newval += FLT_EPSILON;
2220 *newval -= FLT_EPSILON;
2225 rterror(
"rt_band_corrected_clamped_value: Unknown pixeltype %d",
band->pixtype);
2229 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)
void void void rtwarn(const char *fmt,...) __attribute__((format(printf
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)
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)
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.
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::@12 data