| 1 | #cxx . . $ `<file>/frmts/pcraster/libcsf/rcoords.c`/include "csf.h"cxx . . $ `<file>/frmts/pcraster/libcsf/csf.h`/ |
| 2 | #include "csfimpl.h"cxx . . $ `<file>/frmts/pcraster/libcsf/csfimpl.h`/ |
| 3 | |
| 4 | /* compute true world co-ordinate of a pixel |
| 5 | * RrowCol2Coords computes the true world co-ordinate from a |
| 6 | * row, column index. |
| 7 | * The row, column co-ordinate |
| 8 | * don't have to be on the map. They are just relative to upper left position. |
| 9 | * For example (row,col) = (-1,0) computes the (x,y) co-ordinate of |
| 10 | * the pixel that is right above upper left pixel. |
| 11 | * |
| 12 | * returns |
| 13 | * 0 if the co-ordinate is outside the map. |
| 14 | * 1 if inside. |
| 15 | * -1 in case of an error. |
| 16 | * |
| 17 | * Merrno |
| 18 | * ILL_CELLSIZE |
| 19 | */ |
| 20 | int RgetCoordscxx . . $ RgetCoords(3c3cc8f9a16cec9).( |
| 21 | const MAPcxx . . $ MAP# *m, /* map handle */ |
| 22 | int inCellPos, /* nonzero if you want the co-ordinate |
| 23 | * at the centre of the cell, 0 if you |
| 24 | * want the upper left co-ordinate of the cell |
| 25 | */ |
| 26 | size_t row, /* Row number (relates to y position). */ |
| 27 | size_t col, /* Column number (relates to x position). */ |
| 28 | double *x, /* write-only. Returns x of true co-ordinate */ |
| 29 | double *y) /* write-only. Returns y of true co-ordinate */ |
| 30 | { |
| 31 | return RrowCol2Coordscxx . . $ RrowCol2Coords(589705154df13899).(m, |
| 32 | (double)row+(inCellPos ? 0.5 : 0.0), |
| 33 | (double)col+(inCellPos ? 0.5 : 0.0), |
| 34 | x,y); |
| 35 | } |
| 36 | |
| 37 | /* compute true world co-ordinate from row, column index |
| 38 | * RrowCol2Coords computes the true world co-ordinate from a |
| 39 | * row, column index. The row,column co-ordinate can be fractions. |
| 40 | * For example (row,col) = (0.5,0.5) computes the (x,y) co-ordinate of |
| 41 | * the centre of the upper left pixel. Secondly, the row and column co-ordinate |
| 42 | * don't have to be on the map. They are just relative to upper left position. |
| 43 | * For example (row,col) = (-0.5,0.5) computes the (x,y) co-ordinate of |
| 44 | * the centre of the pixel that is right above upper left pixel. |
| 45 | */ |
| 46 | void RasterRowCol2Coordscxx . . $ RasterRowCol2Coords(9f417ea192db1942).( |
| 47 | const CSF_RASTER_LOCATION_ATTRIBUTEScxx . . $ CSF_RASTER_LOCATION_ATTRIBUTES# *m, /* raster handle */ |
| 48 | double row, /* Row number (relates to y position). */ |
| 49 | double col, /* Column number (relates to x position). */ |
| 50 | double *x, /* write-only. x co-ordinate */ |
| 51 | double *y) /* write-only. y co-ordinate */ |
| 52 | { |
| 53 | double cs = m->cellSizecxx . . $ CSF_RASTER_HEADER#cellSize.; |
| 54 | double c = m->angleCoscxx . . $ CSF_RASTER_HEADER#angleCos.; |
| 55 | double s = m->angleSincxx . . $ CSF_RASTER_HEADER#angleSin.; |
| 56 | double yRow = cs * row; |
| 57 | double xCol = cs * col; |
| 58 | double xCol_t = xCol * c - yRow * s; |
| 59 | double yRow_t = xCol * s + yRow * c; |
| 60 | |
| 61 | *x = m->xULcxx . . $ CSF_RASTER_HEADER#xUL. + xCol_t; |
| 62 | if (m->projectioncxx . . $ CSF_RASTER_HEADER#projection. == PT_YINCT2Bcxx . . $ PT_YINCT2B.) |
| 63 | *y = m->yULcxx . . $ CSF_RASTER_HEADER#yUL. + yRow_t; |
| 64 | else /* all other projections */ |
| 65 | *y = m->yULcxx . . $ CSF_RASTER_HEADER#yUL. - yRow_t; |
| 66 | } |
| 67 | |
| 68 | /* compute true world co-ordinate from row, column index |
| 69 | * RasterRowCol2Coords computes the true world co-ordinate from a |
| 70 | * row, column index. The row,column co-ordinate can be fractions. |
| 71 | * For example (row,col) = (0.5,0.5) computes the (x,y) co-ordinate of |
| 72 | * the centre of the upper left pixel. Secondly, the row and column co-ordinate |
| 73 | * don't have to be on the map. They are just relative to upper left position. |
| 74 | * For example (row,col) = (-0.5,0.5) computes the (x,y) co-ordinate of |
| 75 | * the centre of the pixel that is right above upper left pixel. |
| 76 | * |
| 77 | * returns |
| 78 | * 0 if the co-ordinate is outside the map. |
| 79 | * 1 if inside. |
| 80 | * -1 in case of an error. |
| 81 | * |
| 82 | * Merrno |
| 83 | * ILL_CELLSIZE |
| 84 | */ |
| 85 | int RrowCol2Coordscxx . . $ RrowCol2Coords(589705154df13899).(const MAPcxx . . $ MAP# *m, /* map handle */ |
| 86 | double row, /* Row number (relates to y position). */ |
| 87 | double col, /* Column number (relates to x position). */ |
| 88 | double *x, /* write-only. x co-ordinate */ |
| 89 | double *y) /* write-only. y co-ordinate */ |
| 90 | { |
| 91 | if (m->rastercxx . . $ MAP#raster..cellSizecxx . . $ CSF_RASTER_HEADER#cellSize. <= 0 |
| 92 | || m->rastercxx . . $ MAP#raster..cellSizecxx . . $ CSF_RASTER_HEADER#cellSize. != m->rastercxx . . $ MAP#raster..cellSizeDuplcxx . . $ CSF_RASTER_HEADER#cellSizeDupl. ) |
| 93 | { |
| 94 | M_ERRORcxx . . $ `frmts/pcraster/libcsf/csfimpl.h:149:9`!(ILL_CELLSIZEcxx . . $ `frmts/pcraster/libcsf/csf.h:174:9`!); |
| 95 | goto error; |
| 96 | } |
| 97 | RasterRowCol2Coordscxx . . $ RasterRowCol2Coords(9f417ea192db1942).(&(m->rastercxx . . $ MAP#raster.),row,col,x,y); |
| 98 | return( (m->rastercxx . . $ MAP#raster..nrRowscxx . . $ CSF_RASTER_HEADER#nrRows. > row) && (m->rastercxx . . $ MAP#raster..nrColscxx . . $ CSF_RASTER_HEADER#nrCols. > col) && |
| 99 | (row >= 0) && (col >= 0)); |
| 100 | error: return(-1); |
| 101 | } |