Retrieve a point value from the raster using a world coordinate and bilinear interpolation.
1439{
1440 double xcenter, ycenter;
1441 double values[2][2];
1442 double nodatavalue = 0.0;
1443 int nodatas[2][2];
1446 int xcell, ycell;
1447 int xdir, ydir;
1448 int i, j;
1449 uint16_t width, height;
1450
1451
1452 xcell = (int)floor(xr);
1453 ycell = (int)floor(yr);
1454 xcenter = xcell + 0.5;
1455 ycenter = ycell + 0.5;
1456
1457
1460
1461
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);
1465 }
1466
1467
1468 xdir = xr < xcenter ? 1 : 0;
1469 ydir = yr < ycenter ? 1 : 0;
1470
1473 }
1474 else {
1475 nodatavalue = 0.0;
1476 }
1477
1478
1479 for (i = 0; i < 2; i++) {
1480 for (j = 0; j < 2; j++) {
1481 double value = nodatavalue;
1482 int nodata = 0;
1483 int xij = xcell + (i - xdir);
1484 int yij = ycell + (j - ydir);
1485
1486 if(xij < 0 || yij < 0 || xij >= width || yij >= height) {
1487 nodata = 1;
1488 }
1489 else {
1491 band, xij, yij,
1492 &value, &nodata
1493 );
1495 nodata = 1;
1496 }
1499 values[i][j] =
value;
1500 nodatas[i][j] = nodata;
1501 }
1502 }
1503
1504
1505 if (nodatas[xdir][ydir]) {
1506 *r_value = nodatavalue;
1507 *r_nodata = 1;
1509 }
1510
1511
1512
1513 xr = xr - (
x[0][0] + 0.5);
1514 yr = yr - (
y[0][0] + 0.5);
1515
1516
1517
1518
1519 for (i = 0; i < 2; i++) {
1520 for (j = 0; j < 2; j++) {
1521 if (nodatas[i][j])
1522 values[i][j] = values[xdir][ydir];
1523 }
1524 }
1525
1526
1527
1528 *r_nodata = 0;
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;
1533
1535}
void void void rtwarn(const char *fmt,...) __attribute__((format(printf
rt_errorstate
Enum definitions.
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
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.
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
uint16_t rt_band_get_height(rt_band band)
Return height of this band.