PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwgeom_interpolate_point()

double lwgeom_interpolate_point ( const LWGEOM lwin,
const LWPOINT lwpt 
)

Find the measure value at the location on the line closest to the point.

Definition at line 851 of file lwlinearreferencing.c.

References LINETYPE, lwerror(), lwgeom_as_lwline(), lwgeom_has_m(), lwgeom_is_empty(), lwpoint_getPoint4d_p(), lwpoint_is_empty(), lwtype_name(), POINT4D::m, LWLINE::points, ptarray_locate_point(), and LWGEOM::type.

Referenced by gserialized_distance_nd(), and ST_InterpolatePoint().

852 {
853  POINT4D p, p_proj;
854  double ret = 0.0;
855 
856  if ( ! lwin )
857  lwerror("lwgeom_interpolate_point: null input geometry!");
858 
859  if ( ! lwgeom_has_m(lwin) )
860  lwerror("Input geometry does not have a measure dimension");
861 
862  if ( lwgeom_is_empty(lwin) || lwpoint_is_empty(lwpt) )
863  lwerror("Input geometry is empty");
864 
865  switch ( lwin->type )
866  {
867  case LINETYPE:
868  {
869  LWLINE *lwline = lwgeom_as_lwline(lwin);
870  lwpoint_getPoint4d_p(lwpt, &p);
871  ret = ptarray_locate_point(lwline->points, &p, NULL, &p_proj);
872  ret = p_proj.m;
873  break;
874  }
875  default:
876  lwerror("This function does not accept %s geometries.", lwtype_name(lwin->type));
877  }
878  return ret;
879 }
#define LINETYPE
Definition: liblwgeom.h:86
double m
Definition: liblwgeom.h:352
double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *pt, double *dist, POINT4D *p_located)
Definition: ptarray.c:1306
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:57
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:138
int lwpoint_is_empty(const LWPOINT *point)
Definition: lwpoint.c:291
uint8_t type
Definition: liblwgeom.h:396
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1346
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:892
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
POINTARRAY * points
Definition: liblwgeom.h:422
Here is the call graph for this function:
Here is the caller graph for this function: