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

Definition at line 208 of file lwgeom_functions_lrs.c.

References 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().

209 {
210  GSERIALIZED *geom1 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
211  GSERIALIZED *geom2 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
212  LWLINE *lwline;
213  LWPOINT *lwpoint;
214  POINTARRAY *pa;
215  POINT4D p, p_proj;
216  double ret;
217 
218  if ( gserialized_get_type(geom1) != LINETYPE )
219  {
220  elog(ERROR,"line_locate_point: 1st arg isnt a line");
221  PG_RETURN_NULL();
222  }
223  if ( gserialized_get_type(geom2) != POINTTYPE )
224  {
225  elog(ERROR,"line_locate_point: 2st arg isnt a point");
226  PG_RETURN_NULL();
227  }
228  if ( gserialized_get_srid(geom1) != gserialized_get_srid(geom2) )
229  {
230  elog(ERROR, "Operation on two geometries with different SRIDs");
231  PG_RETURN_NULL();
232  }
233 
234  lwline = lwgeom_as_lwline(lwgeom_from_gserialized(geom1));
235  lwpoint = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom2));
236 
237  pa = lwline->points;
238  lwpoint_getPoint4d_p(lwpoint, &p);
239 
240  ret = ptarray_locate_point(pa, &p, NULL, &p_proj);
241 
242  PG_RETURN_FLOAT8(ret);
243 }
#define LINETYPE
Definition: liblwgeom.h:61
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:56
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
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:1267
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:42
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:89
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
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:70
POINTARRAY * points
Definition: liblwgeom.h:378

Here is the call graph for this function: