Debian Codegraph @

gcore/gdal_geotransform.h

raw symbols SCIP
1 /******************************************************************************
2 *
3 * Name: gdal_geotransform.h
4 * Project: GDAL Core
5 * Purpose: Declaration of GDALGeoTransform class
6 * Author: Even Rouault, <[email protected]>
7 *
8 ******************************************************************************
9 * Copyright (c) 2025, Even Rouault, <[email protected]>
10 *
11 * SPDX-License-Identifier: MIT
12 ****************************************************************************/
13
14 #ifndef GDALGEOTRANSFORM_H_INCLUDED
15 #define GDALGEOTRANSFORM_H_INCLUDEDcxx . . $ `gcore/gdal_geotransform.h:15:9`!
16
17 #include "gdal.h"cxx . . $ `<file>/gcore/gdal.h`/
18
19 #include <utility>
20
21 class GDALRasterWindowcxx . . $ GDALRasterWindow#;
22
23 /* ******************************************************************** */
24 /* GDALGeoTransform */
25 /* ******************************************************************** */
26
27 /** Class that encapsulates a geotransform matrix.
28 *
29 * It contains 6 coefficients expressing an affine transformation from
30 * (column, line) raster space to (X, Y) georeferenced space, such that
31 *
32 * \code{.c}
33 * X = xorig + column * xscale + line * xrot;
34 * Y = yorig + column * yrot + line * yscale;
35 * \endcode
36 *
37 * The default value is the identity transformation.
38 *
39 * @since 3.12
40 */
41 class CPL_DLLcxx . . $ `port/cpl_port.h:295:9`! GDALGeoTransformcxx . . $ GDALGeoTransform#
42 {
43 public:
44 // NOTE to GDAL developers: do not reorder those coefficients!
45
46 /** X value of the origin of the raster */
47 double xorigcxx . . $ GDALGeoTransform#xorig. = 0;
48
49 /** X scale factor */
50 double xscalecxx . . $ GDALGeoTransform#xscale. = 1;
51
52 /** X rotation factor */
53 double xrotcxx . . $ GDALGeoTransform#xrot. = 0;
54
55 /** Y value of the origin of the raster */
56 double yorigcxx . . $ GDALGeoTransform#yorig. = 0;
57
58 /** Y rotation factor */
59 double yrotcxx . . $ GDALGeoTransform#yrot. = 0;
60
61 /** Y scale factor */
62 double yscalecxx . . $ GDALGeoTransform#yscale. = 1;
63
64 /** Default constructor for an identity geotransformation matrix. */
65 inline GDALGeoTransformcxx . . $ GDALGeoTransform#GDALGeoTransform(ced63f7c635d850d).() = default;
66
67 /** Constructor from an array of 6 doubles */
68 inline explicit GDALGeoTransformcxx . . $ GDALGeoTransform#GDALGeoTransform(929f707f64635741).(const double coeffs[6])
69 {
70 static_assert(sizeof(GDALGeoTransformcxx . . $ GDALGeoTransform#) == 6 * sizeof(double),
71 "Wrong size for GDALGeoTransform");
72 xorigcxx . . $ GDALGeoTransform#xorig. = coeffs[0];
73 xscalecxx . . $ GDALGeoTransform#xscale. = coeffs[1];
74 xrotcxx . . $ GDALGeoTransform#xrot. = coeffs[2];
75 yorigcxx . . $ GDALGeoTransform#yorig. = coeffs[3];
76 yrotcxx . . $ GDALGeoTransform#yrot. = coeffs[4];
77 yscalecxx . . $ GDALGeoTransform#yscale. = coeffs[5];
78 }
79
80 /** Constructor from 6 double values */
81 inline GDALGeoTransformcxx . . $ GDALGeoTransform#GDALGeoTransform(56b37c9ef2ead2d3).(double xorigIn, double xscaleIn, double xrotIn,
82 double yorigIn, double yrotIn, double yscaleIn)
83 {
84 xorigcxx . . $ GDALGeoTransform#xorig. = xorigIn;
85 xscalecxx . . $ GDALGeoTransform#xscale. = xscaleIn;
86 xrotcxx . . $ GDALGeoTransform#xrot. = xrotIn;
87 yorigcxx . . $ GDALGeoTransform#yorig. = yorigIn;
88 yrotcxx . . $ GDALGeoTransform#yrot. = yrotIn;
89 yscalecxx . . $ GDALGeoTransform#yscale. = yscaleIn;
90 }
91
92 /** Element accessor. idx must be in [0,5] range */
93 template <typename T> inline double operatorcxx . . $ GDALGeoTransform#`operator[]`(767f60f7c523683d).[](T idx) const
94 {
95 return *(&xorigcxx . . $ GDALGeoTransform#xorig. + idx);
96 }
97
98 /** Element accessor. idx must be in [0,5] range */
99 template <typename T> inline double &operatorcxx . . $ GDALGeoTransform#`operator[]`(96ffe90bdb19100b).[](T idx)
100 {
101 return *(&xorigcxx . . $ GDALGeoTransform#xorig. + idx);
102 }
103
104 /** Equality test operator */
105 inline bool operatorcxx . . $ GDALGeoTransform#`operator==`(a68a2f32e62de930).==(const GDALGeoTransformcxx . . $ GDALGeoTransform# &other) const
106 {
107 return xorigcxx . . $ GDALGeoTransform#xorig. == other.xorigcxx . . $ GDALGeoTransform#xorig. && xscalecxx . . $ GDALGeoTransform#xscale. == other.xscalecxx . . $ GDALGeoTransform#xscale. &&
108 xrotcxx . . $ GDALGeoTransform#xrot. == other.xrotcxx . . $ GDALGeoTransform#xrot. && yorigcxx . . $ GDALGeoTransform#yorig. == other.yorigcxx . . $ GDALGeoTransform#yorig. &&
109 yrotcxx . . $ GDALGeoTransform#yrot. == other.yrotcxx . . $ GDALGeoTransform#yrot. && yscalecxx . . $ GDALGeoTransform#yscale. == other.yscalecxx . . $ GDALGeoTransform#yscale.;
110 }
111
112 /** Inequality test operator */
113 inline bool operatorcxx . . $ GDALGeoTransform#`operator!=`(a68a2f32e62de930).!=(const GDALGeoTransformcxx . . $ GDALGeoTransform# &other) const
114 {
115 return !(operator==(other));
116 }
117
118 /** Cast to const double* */
119 inline const double *datacxx . . $ GDALGeoTransform#data(d06acfa185f8726d).() const
120 {
121 return &xorigcxx . . $ GDALGeoTransform#xorig.;
122 }
123
124 /** Cast to double* */
125 inline double *datacxx . . $ GDALGeoTransform#data(78c35135705b60d1).()
126 {
127 return &xorigcxx . . $ GDALGeoTransform#xorig.;
128 }
129
130 /**
131 * Apply GeoTransform to x/y coordinate.
132 *
133 * Applies the following computation, converting a (pixel, line) coordinate
134 * into a georeferenced (geo_x, geo_y) location.
135 * \code{.c}
136 * *pdfGeoX = padfGeoTransform[0] + dfPixel * padfGeoTransform[1]
137 * + dfLine * padfGeoTransform[2];
138 * *pdfGeoY = padfGeoTransform[3] + dfPixel * padfGeoTransform[4]
139 * + dfLine * padfGeoTransform[5];
140 * \endcode
141 *
142 * @param dfPixel Input pixel position.
143 * @param dfLine Input line position.
144 * @param pdfGeoX output location where geo_x (easting/longitude)
145 * location is placed.
146 * @param pdfGeoY output location where geo_y (northing/latitude)
147 * location is placed.
148 */
149
150 inline void Applycxx . . $ GDALGeoTransform#Apply(f3e57532bb3a943).(double dfPixel, double dfLine, double *pdfGeoX,
151 double *pdfGeoY) const
152 {
153 GDALApplyGeoTransform(datacxx . . $ GDALGeoTransform#data(d06acfa185f8726d).(), dfPixel, dfLine, pdfGeoX, pdfGeoY);
154 }
155
156 /** Apply a (inverse) geotransform to an OGREnvelope in georeferenced coordinates.
157 *
158 * @param env An envelope in georeferenced coordinates
159 * @param[out] window A window in pixel/line coordinates
160 * @return true if the geotransform was successfully applied
161 */
162 bool Applycxx . . $ GDALGeoTransform#Apply(c5bdc055909a1d52).(const OGREnvelope &env, GDALRasterWindowcxx . . $ GDALRasterWindow# &window) const;
163
164 /** Apply a geotransform to a GDALRasterWindow in pixel/line coordinates.
165 *
166 * @param window A window in pixel/line coordinates
167 * @param[out] env An envelope in georeferenced coordinates
168 * @return true if the geotransform was successfully applied
169 */
170 bool Applycxx . . $ GDALGeoTransform#Apply(697af122e64096da).(const GDALRasterWindowcxx . . $ GDALRasterWindow# &window, OGREnvelope &env) const;
171
172 /**
173 * Apply GeoTransform to x/y coordinate.
174 *
175 * Applies the following computation, converting a (pixel, line) coordinate
176 * into a georeferenced (geo_x, geo_y) location.
177 * \code{.c}
178 * out.first = padfGeoTransform[0] + dfPixel * padfGeoTransform[1]
179 * + dfLine * padfGeoTransform[2];
180 * out.second = padfGeoTransform[3] + dfPixel * padfGeoTransform[4]
181 * + dfLine * padfGeoTransform[5];
182 * \endcode
183 *
184 * @param dfPixel Input pixel position.
185 * @param dfLine Input line position.
186 * @return output location as a (geo_x, geo_y) pair
187 */
188
189 inline stdcxx . . $ std/::paircxx . . $ std/pair#<double, double> Applycxx . . $ GDALGeoTransform#Apply(a61b45523af48c4f).(double dfPixel, double dfLine) const
190 {
191 double dfOutX, dfOutY;
192 GDALApplyGeoTransform(datacxx . . $ GDALGeoTransform#data(d06acfa185f8726d).(), dfPixel, dfLine, &dfOutX, &dfOutY);
193 return {cxx . . $ std/pair#pair(14d64bafa7379ebc).dfOutX, dfOutY};
194 }
195
196 /**
197 * Invert Geotransform.
198 *
199 * This function will invert a standard 3x2 set of GeoTransform coefficients.
200 * This converts the equation from being pixel to geo to being geo to pixel.
201 *
202 * @param[out] inverse Output geotransform
203 *
204 * @return true on success or false if the equation is uninvertable.
205 */
206 inline bool GetInversecxx . . $ GDALGeoTransform#GetInverse(fa6cdc34c8b5c307).(GDALGeoTransformcxx . . $ GDALGeoTransform# &inverse) const
207 {
208 return GDALInvGeoTransform(datacxx . . $ GDALGeoTransform#data(d06acfa185f8726d).(), inverse.datacxx . . $ GDALGeoTransform#data(78c35135705b60d1).()) == TRUEcxx . . $ `port/cpl_port.h:1184:9`!;
209 }
210
211 /** Rescale a geotransform by multiplying its scale and rotation terms by
212 * the provided ratios.
213 *
214 * This is typically used to compute the geotransform matrix of an overview
215 * dataset from the full resolution dataset, where the ratios are the size
216 * of the full resolution dataset divided by the size of the overview.
217 */
218 inline void Rescalecxx . . $ GDALGeoTransform#Rescale(bc12c9ec15586e6a).(double dfXRatio, double dfYRatio)
219 {
220 xscalecxx . . $ GDALGeoTransform#xscale. *= dfXRatio;
221 xrotcxx . . $ GDALGeoTransform#xrot. *= dfYRatio;
222 yrotcxx . . $ GDALGeoTransform#yrot. *= dfXRatio;
223 yscalecxx . . $ GDALGeoTransform#yscale. *= dfYRatio;
224 }
225
226 /** Check whether the geotransform has a rotation component.
227 */
228 inline bool IsAxisAlignedcxx . . $ GDALGeoTransform#IsAxisAligned(50ce9a9e25b4a850).() const
229 {
230 return xrotcxx . . $ GDALGeoTransform#xrot. == 0 && yrotcxx . . $ GDALGeoTransform#yrot. == 0;
231 }
232
233 /** Initialize a geotransform from a string.
234 *
235 * @param pszGT the string to parse
236 * @param pszSep string separating the elements of the geotransform
237 * @return true if the initialization was successful
238 * @since 3.13
239 */
240 bool Initcxx . . $ GDALGeoTransform#Init(b7a7aa4a824b7595).(const char *pszGT, const char *pszSep = ",");
241
242 /** Return a string containing the six geotransform values
243 * separated by commas.
244 *
245 * @param pszSep characters to place between elements of the geotransform
246 * @since 3.13
247 */
248 stdcxx . . $ std/::stringcxx . . $ std/string# ToStringcxx . . $ GDALGeoTransform#ToString(950836e9df5867ac).(const char *pszSep = ", ") const;
249 };
250
251 #endif