PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ point_interpolate()

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

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 316 of file lwlinearreferencing.c.

323{
324 static char *dims = "XYZM";
325 double p1_value = lwpoint_get_ordinate(p1, ordinate);
326 double p2_value = lwpoint_get_ordinate(p2, ordinate);
327 double proportion;
328 int i = 0;
329
330#if PARANOIA_LEVEL > 0
331 if (!(ordinate == 'X' || ordinate == 'Y' || ordinate == 'Z' || ordinate == 'M'))
332 {
333 lwerror("Cannot interpolate over %c ordinate.", ordinate);
334 return LW_FAILURE;
335 }
336
337 if (FP_MIN(p1_value, p2_value) > interpolation_value || FP_MAX(p1_value, p2_value) < interpolation_value)
338 {
339 lwerror("Cannot interpolate to a value (%g) not between the input points (%g, %g).",
340 interpolation_value,
341 p1_value,
342 p2_value);
343 return LW_FAILURE;
344 }
345#endif
346
347 proportion = (interpolation_value - p1_value) / (p2_value - p1_value);
348
349 for (i = 0; i < 4; i++)
350 {
351 if (dims[i] == 'Z' && !hasz)
352 continue;
353 if (dims[i] == 'M' && !hasm)
354 continue;
355 if (dims[i] == ordinate)
356 lwpoint_set_ordinate(p, dims[i], interpolation_value);
357 else
358 {
359 double newordinate = 0.0;
360 p1_value = lwpoint_get_ordinate(p1, dims[i]);
361 p2_value = lwpoint_get_ordinate(p2, dims[i]);
362 newordinate = p1_value + proportion * (p2_value - p1_value);
363 lwpoint_set_ordinate(p, dims[i], newordinate);
364 }
365 }
366
367 return LW_SUCCESS;
368}
#define LW_FAILURE
Definition liblwgeom.h:110
#define LW_SUCCESS
Definition liblwgeom.h:111
#define FP_MAX(A, B)
#define FP_MIN(A, B)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition lwutil.c:190
void lwpoint_set_ordinate(POINT4D *p, char ordinate, double value)
Given a point, ordinate number and value, set that ordinate on the point.
double lwpoint_get_ordinate(const POINT4D *p, char ordinate)
Given a POINT4D and an ordinate number, return the value of the ordinate.

References FP_MAX, FP_MIN, LW_FAILURE, LW_SUCCESS, lwerror(), lwpoint_get_ordinate(), and lwpoint_set_ordinate().

Referenced by lwline_clip_to_ordinate_range(), ptarray_clamp_to_ordinate_range(), and test_point_interpolate().

Here is the call graph for this function:
Here is the caller graph for this function: