MCPcopy Create free account
hub / github.com/OSGeo/gdal / GDALGridDataMetricMinimum

Function GDALGridDataMetricMinimum

alg/gdalgrid.cpp:1059–1170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1057 */
1058
1059CPLErr GDALGridDataMetricMinimum(const void *poOptionsIn, GUInt32 nPoints,
1060 const double *padfX, const double *padfY,
1061 const double *padfZ, double dfXPoint,
1062 double dfYPoint, double *pdfValue,
1063 void *hExtraParamsIn)
1064{
1065 // TODO: For optimization purposes pre-computed parameters should be moved
1066 // out of this routine to the calling function.
1067
1068 const GDALGridDataMetricsOptions *const poOptions =
1069 static_cast<const GDALGridDataMetricsOptions *>(poOptionsIn);
1070
1071 // Pre-compute search ellipse parameters.
1072 const double dfRadius1Square = poOptions->dfRadius1 * poOptions->dfRadius1;
1073 const double dfRadius2Square = poOptions->dfRadius2 * poOptions->dfRadius2;
1074 const double dfSearchRadius =
1075 std::max(poOptions->dfRadius1, poOptions->dfRadius2);
1076 const double dfR12Square = dfRadius1Square * dfRadius2Square;
1077
1078 GDALGridExtraParameters *psExtraParams =
1079 static_cast<GDALGridExtraParameters *>(hExtraParamsIn);
1080 CPLQuadTree *phQuadTree = psExtraParams->hQuadTree;
1081
1082 // Compute coefficients for coordinate system rotation.
1083 const double dfAngle = TO_RADIANS * poOptions->dfAngle;
1084 const bool bRotated = dfAngle != 0.0;
1085 const double dfCoeff1 = bRotated ? cos(dfAngle) : 0.0;
1086 const double dfCoeff2 = bRotated ? sin(dfAngle) : 0.0;
1087
1088 double dfMinimumValue = std::numeric_limits<double>::max();
1089 GUInt32 n = 0;
1090 if (phQuadTree != nullptr)
1091 {
1092 CPLRectObj sAoi;
1093 sAoi.minx = dfXPoint - dfSearchRadius;
1094 sAoi.miny = dfYPoint - dfSearchRadius;
1095 sAoi.maxx = dfXPoint + dfSearchRadius;
1096 sAoi.maxy = dfYPoint + dfSearchRadius;
1097 int nFeatureCount = 0;
1098 GDALGridPoint **papsPoints = reinterpret_cast<GDALGridPoint **>(
1099 CPLQuadTreeSearch(phQuadTree, &sAoi, &nFeatureCount));
1100 if (nFeatureCount != 0)
1101 {
1102 for (int k = 0; k < nFeatureCount; k++)
1103 {
1104 const int i = papsPoints[k]->i;
1105 double dfRX = padfX[i] - dfXPoint;
1106 double dfRY = padfY[i] - dfYPoint;
1107
1108 if (bRotated)
1109 {
1110 const double dfRXRotated =
1111 dfRX * dfCoeff1 + dfRY * dfCoeff2;
1112 const double dfRYRotated =
1113 dfRY * dfCoeff1 - dfRX * dfCoeff2;
1114 dfRX = dfRXRotated;
1115 dfRY = dfRYRotated;
1116 }

Callers

nothing calls this directly

Calls 2

CPLQuadTreeSearchFunction · 0.85
maxFunction · 0.50

Tested by

no test coverage detected