forked from OSGeo/gdal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgdalgeoloc.h
102 lines (87 loc) · 4.72 KB
/
gdalgeoloc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/******************************************************************************
*
* Project: GDAL
* Purpose: Implements Geolocation array based transformer.
* Author: Even Rouault, <even.rouault at spatialys.com>
*
******************************************************************************
* Copyright (c) 2022, Planet Labs
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
****************************************************************************/
#ifndef GDALGEOLOC_H
#define GDALGEOLOC_H
#include "gdal_alg_priv.h"
/************************************************************************/
/* GDALGeoLoc */
/************************************************************************/
/*! @cond Doxygen_Suppress */
template <class Accessors> struct GDALGeoLoc
{
static void LoadGeolocFinish(GDALGeoLocTransformInfo *psTransform);
static bool GenerateBackMap(GDALGeoLocTransformInfo *psTransform);
static bool PixelLineToXY(const GDALGeoLocTransformInfo *psTransform,
const int nGeoLocPixel, const int nGeoLocLine,
double &dfX, double &dfY);
static bool PixelLineToXY(const GDALGeoLocTransformInfo *psTransform,
const double dfGeoLocPixel,
const double dfGeoLocLine, double &dfX,
double &dfY);
static bool ExtractSquare(const GDALGeoLocTransformInfo *psTransform,
int nX, int nY, double &dfX_0_0, double &dfY_0_0,
double &dfX_1_0, double &dfY_1_0, double &dfX_0_1,
double &dfY_0_1, double &dfX_1_1,
double &dfY_1_1);
static int Transform(void *pTransformArg, int bDstToSrc, int nPointCount,
double *padfX, double *padfY, double * /* padfZ */,
int *panSuccess);
};
/*! @endcond */
bool GDALGeoLocExtractSquare(const GDALGeoLocTransformInfo *psTransform, int nX,
int nY, double &dfX_0_0, double &dfY_0_0,
double &dfX_1_0, double &dfY_1_0, double &dfX_0_1,
double &dfY_0_1, double &dfX_1_1, double &dfY_1_1);
void GDALInverseBilinearInterpolation(const double x, const double y,
const double x0, const double y0,
const double x1, const double y1,
const double x2, const double y2,
const double x3, const double y3,
double &i, double &j);
/************************************************************************/
/* ShiftGeoX() */
/************************************************************************/
// Avoid discontinuity at anti-meridian when interpolating longitude
// dfXRef is a "reference" longitude, typically the one of 4 points to
// interpolate), towards which we apply a potential +/- 360 deg shift.
// This may result in a value slightly outside [-180,180]
static double ShiftGeoX(const GDALGeoLocTransformInfo *psTransform,
double dfXRef, double dfX)
{
if (!psTransform->bGeographicSRSWithMinus180Plus180LongRange)
return dfX;
// The threshold at 170 deg is a bit arbitrary. A smarter approach
// would try to guess the "average" longitude step between 2 grid values
// and use 180 - average_step * some_factor as the threshold.
if (dfXRef < -170 && dfX > 170)
return dfX - 360;
if (dfXRef > 170 && dfX < -170)
return dfX + 360;
return dfX;
}
#endif