PostGIS  2.2.7dev-r@@SVN_REVISION@@
Datum LWGEOM_line_locate_point ( PG_FUNCTION_ARGS  )

Definition at line 206 of file lwgeom_functions_lrs.c.

References error_if_srid_mismatch(), gserialized_get_srid(), gserialized_get_type(), LINETYPE, lwgeom_as_lwline(), lwgeom_as_lwpoint(), lwgeom_from_gserialized(), lwpoint_getPoint4d_p(), LWLINE::points, POINTTYPE, and ptarray_locate_point().

207 {
208  GSERIALIZED *geom1 = PG_GETARG_GSERIALIZED_P(0);
209  GSERIALIZED *geom2 = PG_GETARG_GSERIALIZED_P(1);
210  LWLINE *lwline;
211  LWPOINT *lwpoint;
212  POINTARRAY *pa;
213  POINT4D p, p_proj;
214  double ret;
215 
216  if ( gserialized_get_type(geom1) != LINETYPE )
217  {
218  elog(ERROR,"line_locate_point: 1st arg isn't a line");
219  PG_RETURN_NULL();
220  }
221  if ( gserialized_get_type(geom2) != POINTTYPE )
222  {
223  elog(ERROR,"line_locate_point: 2st arg isn't a point");
224  PG_RETURN_NULL();
225  }
226 
228 
229  lwline = lwgeom_as_lwline(lwgeom_from_gserialized(geom1));
230  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom2));
231 
232  pa = lwline->points;
233  lwpoint_getPoint4d_p(lwpoint, &p);
234 
235  ret = ptarray_locate_point(pa, &p, NULL, &p_proj);
236 
237  PG_RETURN_FLOAT8(ret);
238 }
#define LINETYPE
Definition: liblwgeom.h:71
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
Definition: g_serialized.c:55
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:341
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:80
double ptarray_locate_point(const POINTARRAY *pa, const POINT4D *pt, double *dist, POINT4D *p_located)
Definition: ptarray.c:1303
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:44
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:89
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
Definition: g_serialized.c:69
POINTARRAY * points
Definition: liblwgeom.h:406

Here is the call graph for this function: