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

Definition at line 97 of file lwgeom_functions_lrs.c.

References geometry_serialize(), gserialized_has_m(), lwgeom_clip_to_ordinate_range(), lwgeom_free(), lwgeom_from_gserialized(), and ST_LocateAlong().

98 {
99  GSERIALIZED *geom_in = PG_GETARG_GSERIALIZED_P(0);
100  double from = PG_GETARG_FLOAT8(1);
101  double to = PG_GETARG_FLOAT8(2);
102  double offset = PG_GETARG_FLOAT8(3);
103  LWCOLLECTION *geom_out = NULL;
104  LWGEOM *line_in = NULL;
105  static char ordinate = 'M'; /* M */
106 
107  if ( ! gserialized_has_m(geom_in) )
108  {
109  elog(ERROR,"This function only accepts geometries that have an M dimension.");
110  PG_RETURN_NULL();
111  }
112 
113  /* This should be a call to ST_LocateAlong! */
114  if ( to == from )
115  {
116  PG_RETURN_DATUM(DirectFunctionCall3(ST_LocateAlong, PG_GETARG_DATUM(0), PG_GETARG_DATUM(1), PG_GETARG_DATUM(3)));
117  }
118 
119  line_in = lwgeom_from_gserialized(geom_in);
120  geom_out = lwgeom_clip_to_ordinate_range(line_in, ordinate, from, to, offset);
121  lwgeom_free(line_in);
122  PG_FREE_IF_COPY(geom_in, 0);
123 
124  if ( ! geom_out )
125  {
126  elog(ERROR,"lwline_clip_to_ordinate_range returned null");
127  PG_RETURN_NULL();
128  }
129 
130  PG_RETURN_POINTER(geometry_serialize((LWGEOM*)geom_out));
131 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_has_m(const GSERIALIZED *gser)
Check if a GSERIALIZED has an M ordinate.
Definition: g_serialized.c:29
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
Datum ST_LocateAlong(PG_FUNCTION_ARGS)
LWCOLLECTION * lwgeom_clip_to_ordinate_range(const LWGEOM *lwin, char ordinate, double from, double to, double offset)
Given a geometry clip based on the from/to range of one of its ordinates (x, y, z, m).
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)

Here is the call graph for this function: