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

Definition at line 29 of file lwgeom_functions_lrs.c.

References geometry_serialize(), gserialized_get_type(), LINETYPE, lwgeom_free(), lwgeom_from_gserialized(), lwline_measured_from_lwline(), lwmline_measured_from_lwmline(), and MULTILINETYPE.

30 {
31  GSERIALIZED *gin = PG_GETARG_GSERIALIZED_P(0);
32  GSERIALIZED *gout;
33  double start_measure = PG_GETARG_FLOAT8(1);
34  double end_measure = PG_GETARG_FLOAT8(2);
35  LWGEOM *lwin, *lwout;
36  int type = gserialized_get_type(gin);
37 
38  /* Raise an error if input is not a linestring or multilinestring */
39  if ( type != LINETYPE && type != MULTILINETYPE )
40  {
41  lwpgerror("Only LINESTRING and MULTILINESTRING are supported");
42  PG_RETURN_NULL();
43  }
44 
45  lwin = lwgeom_from_gserialized(gin);
46  if ( type == LINETYPE )
47  lwout = (LWGEOM*)lwline_measured_from_lwline((LWLINE*)lwin, start_measure, end_measure);
48  else
49  lwout = (LWGEOM*)lwmline_measured_from_lwmline((LWMLINE*)lwin, start_measure, end_measure);
50 
51  lwgeom_free(lwin);
52 
53  if ( lwout == NULL )
54  PG_RETURN_NULL();
55 
56  gout = geometry_serialize(lwout);
57  lwgeom_free(lwout);
58 
59  PG_RETURN_POINTER(gout);
60 }
#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
LWLINE * lwline_measured_from_lwline(const LWLINE *lwline, double m_start, double m_end)
Add a measure dimension to a line, interpolating linearly from the start to the end value...
Definition: lwline.c:367
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
LWMLINE * lwmline_measured_from_lwmline(const LWMLINE *lwmline, double m_start, double m_end)
Re-write the measure ordinate (or add one, if it isn't already there) interpolating the measure betwe...
Definition: lwmline.c:42
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
#define MULTILINETYPE
Definition: liblwgeom.h:74

Here is the call graph for this function: