215
207
/************************************************************************/
216
/* ParseAlgorithmAndOptions() */
218
/* Translates mnemonic gridding algorithm names into */
219
/* GDALGridAlgorithm code, parse control parameters and assign */
221
/************************************************************************/
223
static CPLErr ParseAlgorithmAndOptions( const char *pszAlgoritm,
224
GDALGridAlgorithm *peAlgorithm,
227
char **papszParms = CSLTokenizeString2( pszAlgoritm, ":", FALSE );
229
if ( CSLCount(papszParms) < 1 )
232
if ( EQUAL(papszParms[0], szAlgNameInvDist) )
233
*peAlgorithm = GGA_InverseDistanceToAPower;
234
else if ( EQUAL(papszParms[0], szAlgNameAverage) )
235
*peAlgorithm = GGA_MovingAverage;
236
else if ( EQUAL(papszParms[0], szAlgNameNearest) )
237
*peAlgorithm = GGA_NearestNeighbor;
238
else if ( EQUAL(papszParms[0], szAlgNameMinimum) )
239
*peAlgorithm = GGA_MetricMinimum;
240
else if ( EQUAL(papszParms[0], szAlgNameMaximum) )
241
*peAlgorithm = GGA_MetricMaximum;
242
else if ( EQUAL(papszParms[0], szAlgNameRange) )
243
*peAlgorithm = GGA_MetricRange;
244
else if ( EQUAL(papszParms[0], szAlgNameCount) )
245
*peAlgorithm = GGA_MetricCount;
246
else if ( EQUAL(papszParms[0], szAlgNameAverageDistance) )
247
*peAlgorithm = GGA_MetricAverageDistance;
248
else if ( EQUAL(papszParms[0], szAlgNameAverageDistancePts) )
249
*peAlgorithm = GGA_MetricAverageDistancePts;
252
fprintf( stderr, "Unsupported gridding method \"%s\".\n",
254
CSLDestroy( papszParms );
258
/* -------------------------------------------------------------------- */
259
/* Parse algorithm parameters and assign defaults. */
260
/* -------------------------------------------------------------------- */
261
const char *pszValue;
263
switch ( *peAlgorithm )
265
case GGA_InverseDistanceToAPower:
268
CPLMalloc( sizeof(GDALGridInverseDistanceToAPowerOptions) );
270
pszValue = CSLFetchNameValue( papszParms, "power" );
271
((GDALGridInverseDistanceToAPowerOptions *)*ppOptions)->
272
dfPower = (pszValue) ? atof(pszValue) : 2.0;
274
pszValue = CSLFetchNameValue( papszParms, "smoothing" );
275
((GDALGridInverseDistanceToAPowerOptions *)*ppOptions)->
276
dfSmoothing = (pszValue) ? atof(pszValue) : 0.0;
278
pszValue = CSLFetchNameValue( papszParms, "radius1" );
279
((GDALGridInverseDistanceToAPowerOptions *)*ppOptions)->
280
dfRadius1 = (pszValue) ? atof(pszValue) : 0.0;
282
pszValue = CSLFetchNameValue( papszParms, "radius2" );
283
((GDALGridInverseDistanceToAPowerOptions *)*ppOptions)->
284
dfRadius2 = (pszValue) ? atof(pszValue) : 0.0;
286
pszValue = CSLFetchNameValue( papszParms, "angle" );
287
((GDALGridInverseDistanceToAPowerOptions *)*ppOptions)->
288
dfAngle = (pszValue) ? atof(pszValue) : 0.0;
290
pszValue = CSLFetchNameValue( papszParms, "max_points" );
291
((GDALGridInverseDistanceToAPowerOptions *)*ppOptions)->
292
nMaxPoints = (pszValue) ? atol(pszValue) : 0;
294
pszValue = CSLFetchNameValue( papszParms, "min_points" );
295
((GDALGridInverseDistanceToAPowerOptions *)*ppOptions)->
296
nMinPoints = (pszValue) ? atol(pszValue) : 0;
298
pszValue = CSLFetchNameValue( papszParms, "nodata" );
299
((GDALGridInverseDistanceToAPowerOptions *)*ppOptions)->
300
dfNoDataValue = (pszValue) ? atof(pszValue) : 0.0;
303
case GGA_MovingAverage:
305
CPLMalloc( sizeof(GDALGridMovingAverageOptions) );
307
pszValue = CSLFetchNameValue( papszParms, "radius1" );
308
((GDALGridMovingAverageOptions *)*ppOptions)->
309
dfRadius1 = (pszValue) ? atof(pszValue) : 0.0;
311
pszValue = CSLFetchNameValue( papszParms, "radius2" );
312
((GDALGridMovingAverageOptions *)*ppOptions)->
313
dfRadius2 = (pszValue) ? atof(pszValue) : 0.0;
315
pszValue = CSLFetchNameValue( papszParms, "angle" );
316
((GDALGridMovingAverageOptions *)*ppOptions)->
317
dfAngle = (pszValue) ? atof(pszValue) : 0.0;
319
pszValue = CSLFetchNameValue( papszParms, "min_points" );
320
((GDALGridMovingAverageOptions *)*ppOptions)->
321
nMinPoints = (pszValue) ? atol(pszValue) : 0;
323
pszValue = CSLFetchNameValue( papszParms, "nodata" );
324
((GDALGridMovingAverageOptions *)*ppOptions)->
325
dfNoDataValue = (pszValue) ? atof(pszValue) : 0.0;
328
case GGA_NearestNeighbor:
330
CPLMalloc( sizeof(GDALGridNearestNeighborOptions) );
332
pszValue = CSLFetchNameValue( papszParms, "radius1" );
333
((GDALGridNearestNeighborOptions *)*ppOptions)->
334
dfRadius1 = (pszValue) ? atof(pszValue) : 0.0;
336
pszValue = CSLFetchNameValue( papszParms, "radius2" );
337
((GDALGridNearestNeighborOptions *)*ppOptions)->
338
dfRadius2 = (pszValue) ? atof(pszValue) : 0.0;
340
pszValue = CSLFetchNameValue( papszParms, "angle" );
341
((GDALGridNearestNeighborOptions *)*ppOptions)->
342
dfAngle = (pszValue) ? atof(pszValue) : 0.0;
344
pszValue = CSLFetchNameValue( papszParms, "nodata" );
345
((GDALGridNearestNeighborOptions *)*ppOptions)->
346
dfNoDataValue = (pszValue) ? atof(pszValue) : 0.0;
349
case GGA_MetricMinimum:
350
case GGA_MetricMaximum:
351
case GGA_MetricRange:
352
case GGA_MetricCount:
353
case GGA_MetricAverageDistance:
354
case GGA_MetricAverageDistancePts:
356
CPLMalloc( sizeof(GDALGridDataMetricsOptions) );
358
pszValue = CSLFetchNameValue( papszParms, "radius1" );
359
((GDALGridDataMetricsOptions *)*ppOptions)->
360
dfRadius1 = (pszValue) ? atof(pszValue) : 0.0;
362
pszValue = CSLFetchNameValue( papszParms, "radius2" );
363
((GDALGridDataMetricsOptions *)*ppOptions)->
364
dfRadius2 = (pszValue) ? atof(pszValue) : 0.0;
366
pszValue = CSLFetchNameValue( papszParms, "angle" );
367
((GDALGridDataMetricsOptions *)*ppOptions)->
368
dfAngle = (pszValue) ? atof(pszValue) : 0.0;
370
pszValue = CSLFetchNameValue( papszParms, "min_points" );
371
((GDALGridDataMetricsOptions *)*ppOptions)->
372
nMinPoints = (pszValue) ? atol(pszValue) : 0;
374
pszValue = CSLFetchNameValue( papszParms, "nodata" );
375
((GDALGridDataMetricsOptions *)*ppOptions)->
376
dfNoDataValue = (pszValue) ? atof(pszValue) : 0.0;
381
CSLDestroy( papszParms );
385
/************************************************************************/
386
208
/* ProcessGeometry() */
388
210
/* Extract point coordinates from the geometry reference and set the */