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

◆ lwline_from_lwgeom_array()

LWLINE * lwline_from_lwgeom_array ( int32_t  srid,
uint32_t  ngeoms,
LWGEOM **  geoms 
)
extern

Definition at line 151 of file lwline.c.

152{
153 uint32_t i;
154 int hasz = LW_FALSE;
155 int hasm = LW_FALSE;
156 POINTARRAY *pa;
157 LWLINE *line;
158 POINT4D pt;
159 LWPOINTITERATOR* it;
160
161 /*
162 * Find output dimensions, check integrity
163 */
164 for (i=0; i<ngeoms; i++)
165 {
166 if ( FLAGS_GET_Z(geoms[i]->flags) ) hasz = LW_TRUE;
167 if ( FLAGS_GET_M(geoms[i]->flags) ) hasm = LW_TRUE;
168 if ( hasz && hasm ) break; /* Nothing more to learn! */
169 }
170
171 /*
172 * ngeoms should be a guess about how many points we have in input.
173 * It's an underestimate for lines and multipoints */
174 pa = ptarray_construct_empty(hasz, hasm, ngeoms);
175
176 for ( i=0; i < ngeoms; i++ )
177 {
178 LWGEOM *g = geoms[i];
179
180 if ( lwgeom_is_empty(g) ) continue;
181
182 if ( g->type == POINTTYPE )
183 {
186 }
187 else if ( g->type == LINETYPE )
188 {
189 /*
190 * Append the new line points, de-duplicating against the previous points.
191 * Duplicated points internal to the linestring are untouched.
192 */
193 ptarray_append_ptarray(pa, ((LWLINE*)g)->points, -1);
194 }
195 else if ( g->type == MULTIPOINTTYPE )
196 {
198 while(lwpointiterator_next(it, &pt))
199 {
201 }
203 }
204 else
205 {
206 ptarray_free(pa);
207 lwerror("lwline_from_ptarray: invalid input type: %s", lwtype_name(g->type));
208 return NULL;
209 }
210 }
211
212 if ( pa->npoints > 0 )
213 line = lwline_construct(srid, NULL, pa);
214 else {
215 /* Is this really any different from the above ? */
216 ptarray_free(pa);
217 line = lwline_construct_empty(srid, hasz, hasm);
218 }
219
220 return line;
221}
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition lwutil.c:216
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition lwpoint.c:57
#define LW_FALSE
Definition liblwgeom.h:94
int ptarray_append_ptarray(POINTARRAY *pa1, POINTARRAY *pa2, double gap_tolerance)
Append a POINTARRAY, pa2 to the end of an existing POINTARRAY, pa1.
Definition ptarray.c:177
LWPOINTITERATOR * lwpointiterator_create(const LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM*.
Definition lwiterator.c:243
int lwpointiterator_next(LWPOINTITERATOR *s, POINT4D *p)
Attempts to assign the next point in the iterator to p, and advances the iterator to the next point.
Definition lwiterator.c:210
#define LINETYPE
Definition liblwgeom.h:103
#define MULTIPOINTTYPE
Definition liblwgeom.h:105
void lwpointiterator_destroy(LWPOINTITERATOR *s)
Free all memory associated with the iterator.
Definition lwiterator.c:268
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition ptarray.c:59
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition liblwgeom.h:102
#define FLAGS_GET_Z(flags)
Definition liblwgeom.h:165
#define FLAGS_GET_M(flags)
Definition liblwgeom.h:166
void ptarray_free(POINTARRAY *pa)
Definition ptarray.c:327
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE,...
Definition ptarray.c:147
#define LW_TRUE
Return types for functions with status returns.
Definition liblwgeom.h:93
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
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition lwline.c:42
LWLINE * lwline_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwline.c:55
uint8_t type
Definition liblwgeom.h:462
uint32_t npoints
Definition liblwgeom.h:427

References FLAGS_GET_M, FLAGS_GET_Z, LINETYPE, LW_FALSE, LW_TRUE, lwerror(), lwgeom_is_empty(), lwline_construct(), lwline_construct_empty(), lwpoint_getPoint4d_p(), lwpointiterator_create(), lwpointiterator_destroy(), lwpointiterator_next(), lwtype_name(), MULTIPOINTTYPE, POINTARRAY::npoints, POINTTYPE, ptarray_append_point(), ptarray_append_ptarray(), ptarray_construct_empty(), ptarray_free(), and LWGEOM::type.

Referenced by geography_tree_shortestline(), LWGEOM_makeline(), and LWGEOM_makeline_garray().

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