PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ lwmline_measured_from_lwmline()

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 between the supplied start and end values.

Definition at line 56 of file lwmline.c.

57{
58 uint32_t i = 0;
59 int hasm = 0, hasz = 0;
60 double length = 0.0, length_so_far = 0.0;
61 double m_range = m_end - m_start;
62 LWGEOM **geoms = NULL;
63
64 if ( lwmline->type != MULTILINETYPE )
65 {
66 lwerror("lwmline_measured_from_lmwline: only multiline types supported");
67 return NULL;
68 }
69
70 hasz = FLAGS_GET_Z(lwmline->flags);
71 hasm = 1;
72
73 /* Calculate the total length of the mline */
74 for ( i = 0; i < lwmline->ngeoms; i++ )
75 {
76 LWLINE *lwline = (LWLINE*)lwmline->geoms[i];
77 if ( lwline->points && lwline->points->npoints > 1 )
78 {
79 length += ptarray_length_2d(lwline->points);
80 }
81 }
82
83 if ( lwgeom_is_empty((LWGEOM*)lwmline) )
84 {
85 return (LWMLINE*)lwcollection_construct_empty(MULTILINETYPE, lwmline->srid, hasz, hasm);
86 }
87
88 geoms = lwalloc(sizeof(LWGEOM*) * lwmline->ngeoms);
89
90 for ( i = 0; i < lwmline->ngeoms; i++ )
91 {
92 double sub_m_start, sub_m_end;
93 double sub_length = 0.0;
94 LWLINE *lwline = (LWLINE*)lwmline->geoms[i];
95
96 if ( lwline->points && lwline->points->npoints > 1 )
97 {
98 sub_length = ptarray_length_2d(lwline->points);
99 }
100
101 sub_m_start = (m_start + m_range * length_so_far / length);
102 sub_m_end = (m_start + m_range * (length_so_far + sub_length) / length);
103
104 geoms[i] = (LWGEOM*)lwline_measured_from_lwline(lwline, sub_m_start, sub_m_end);
105
106 length_so_far += sub_length;
107 }
108
109 return (LWMLINE*)lwcollection_construct(lwmline->type, lwmline->srid, NULL, lwmline->ngeoms, geoms);
110}
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
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:389
#define MULTILINETYPE
Definition liblwgeom.h:106
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
Definition ptarray.c:1975
#define FLAGS_GET_Z(flags)
Definition liblwgeom.h:165
void * lwalloc(size_t size)
Definition lwutil.c:227
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition lwinline.h:199
uint8_t type
Definition liblwgeom.h:462
int32_t srid
Definition liblwgeom.h:460
lwflags_t flags
Definition liblwgeom.h:549
LWLINE ** geoms
Definition liblwgeom.h:547
uint8_t type
Definition liblwgeom.h:550
uint32_t ngeoms
Definition liblwgeom.h:552

References LWMLINE::flags, FLAGS_GET_Z, LWMLINE::geoms, lwalloc(), lwcollection_construct(), lwcollection_construct_empty(), lwerror(), lwgeom_is_empty(), lwline_measured_from_lwline(), MULTILINETYPE, LWMLINE::ngeoms, POINTARRAY::npoints, LWLINE::points, ptarray_length_2d(), LWMLINE::srid, and LWMLINE::type.

Referenced by ST_AddMeasure().

Here is the call graph for this function:
Here is the caller graph for this function: