PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ point_interpolate()

int point_interpolate ( const POINT4D p1,
const POINT4D p2,
POINT4D p,
int  hasz,
int  hasm,
char  ordinate,
double  interpolation_value 
)

Given two points, a dimensionality, an ordinate, and an interpolation value generate a new point that is proportionally between the input points, using the values in the provided dimension as the scaling factors.

Definition at line 321 of file lwlinearreferencing.c.

References FP_MAX, FP_MIN, LWDEBUGF, lwerror(), lwpoint_get_ordinate(), and lwpoint_set_ordinate().

Referenced by lwline_clip_to_ordinate_range(), and test_point_interpolate().

322 {
323  static char* dims = "XYZM";
324  double p1_value = lwpoint_get_ordinate(p1, ordinate);
325  double p2_value = lwpoint_get_ordinate(p2, ordinate);
326  double proportion;
327  int i = 0;
328 
329  if ( ! ( ordinate == 'X' || ordinate == 'Y' || ordinate == 'Z' || ordinate == 'M' ) )
330  {
331  lwerror("Cannot set %c ordinate.", ordinate);
332  return 0;
333  }
334 
335  if ( FP_MIN(p1_value, p2_value) > interpolation_value ||
336  FP_MAX(p1_value, p2_value) < interpolation_value )
337  {
338  lwerror("Cannot interpolate to a value (%g) not between the input points (%g, %g).", interpolation_value, p1_value, p2_value);
339  return 0;
340  }
341 
342  proportion = fabs((interpolation_value - p1_value) / (p2_value - p1_value));
343 
344  for ( i = 0; i < 4; i++ )
345  {
346  double newordinate = 0.0;
347  if ( dims[i] == 'Z' && ! hasz ) continue;
348  if ( dims[i] == 'M' && ! hasm ) continue;
349  p1_value = lwpoint_get_ordinate(p1, dims[i]);
350  p2_value = lwpoint_get_ordinate(p2, dims[i]);
351  newordinate = p1_value + proportion * (p2_value - p1_value);
352  lwpoint_set_ordinate(p, dims[i], newordinate);
353  LWDEBUGF(4, " clip ordinate(%c) p1_value(%g) p2_value(%g) proportion(%g) newordinate(%g) ", dims[i], p1_value, p2_value, proportion, newordinate );
354  }
355 
356  return 1;
357 }
double lwpoint_get_ordinate(const POINT4D *p, char ordinate)
Given a POINT4D and an ordinate number, return the value of the ordinate.
#define FP_MIN(A, B)
void lwpoint_set_ordinate(POINT4D *p, char ordinate, double value)
Given a point, ordinate number and value, set that ordinate on the point.
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
#define FP_MAX(A, B)
Here is the call graph for this function:
Here is the caller graph for this function: