Convert a pixel X/Y position to a position in a coord. reference system. \param col Pixel column. \param row Pixel row. \param[out] output Array of 2 doubles with of the position in a CRS. */
| 448 | \param[out] output Array of 2 doubles with of the position in a CRS. |
| 449 | */ |
| 450 | void Raster::pixelToCoord(int col, int row, std::array<double, 2>& output) const |
| 451 | { |
| 452 | /** |
| 453 | double *xform = const_cast<double *>(m_forwardTransform.data()); |
| 454 | GDALApplyGeoTransform(xform, col, row, &output[0], &output[1]); |
| 455 | **/ |
| 456 | |
| 457 | // from http://gis.stackexchange.com/questions/53617/how-to-find-lat-lon-values-for-every-pixel-in-a-geotiff-file |
| 458 | double c = m_forwardTransform[0]; |
| 459 | double a = m_forwardTransform[1]; |
| 460 | double b = m_forwardTransform[2]; |
| 461 | double f = m_forwardTransform[3]; |
| 462 | double d = m_forwardTransform[4]; |
| 463 | double e = m_forwardTransform[5]; |
| 464 | |
| 465 | //ABELL - Not sure why this is right. You can think of this like: |
| 466 | // output[0] = a * (col + .5) + b * (row + .5) + c; |
| 467 | // output[1] = d * (col + .5) + e * (row + .5) + f; |
| 468 | // Is there some reason why you want to "move" the points in the raster |
| 469 | // to a location between the rows/columns? Seems that you would just |
| 470 | // use 'c' and 'f' to shift everything a half-row and half-column if |
| 471 | // that's what you wanted. |
| 472 | // Also, this isn't what GDALApplyGeoTransform does. And why aren't |
| 473 | // we just calling GDALApplyGeoTransform? |
| 474 | output[0] = a*col + b*row + a*0.5 + b*0.5 + c; |
| 475 | output[1] = d*col + e*row + d*0.5 + e*0.5 + f; |
| 476 | } |
| 477 | |
| 478 | |
| 479 | /** |
no outgoing calls
no test coverage detected