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

◆ lwline_from_lwgeom_array()

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

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 == MULTILINETYPE )
196 {
197 LWMLINE *mline = lwgeom_as_lwmline(g);
198 for ( uint32_t j = 0; j < mline->ngeoms; j++ )
199 {
200 LWLINE *line = mline->geoms[j];
201 if (lwline_is_empty(line)) continue;
202 ptarray_append_ptarray(pa, line->points, -1);
203 }
204 }
205 else if ( g->type == MULTIPOINTTYPE )
206 {
208 while(lwpointiterator_next(it, &pt))
209 {
211 }
213 }
214 else
215 {
216 ptarray_free(pa);
217 lwerror("lwline_from_ptarray: invalid input type: %s", lwtype_name(g->type));
218 return NULL;
219 }
220 }
221
222 if ( pa->npoints > 0 )
223 line = lwline_construct(srid, NULL, pa);
224 else {
225 /* Is this really any different from the above ? */
226 ptarray_free(pa);
227 line = lwline_construct_empty(srid, hasz, hasm);
228 }
229
230 return line;
231}
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
#define MULTILINETYPE
Definition liblwgeom.h:106
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
LWMLINE * lwgeom_as_lwmline(const LWGEOM *lwgeom)
Definition lwgeom.c:279
#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
int lwline_is_empty(const LWLINE *line)
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
POINTARRAY * points
Definition liblwgeom.h:483
LWLINE ** geoms
Definition liblwgeom.h:547
uint32_t ngeoms
Definition liblwgeom.h:552
uint32_t npoints
Definition liblwgeom.h:427

References FLAGS_GET_M, FLAGS_GET_Z, LWMLINE::geoms, LINETYPE, LW_FALSE, LW_TRUE, lwerror(), lwgeom_as_lwmline(), lwgeom_is_empty(), lwline_construct(), lwline_construct_empty(), lwline_is_empty(), lwpoint_getPoint4d_p(), lwpointiterator_create(), lwpointiterator_destroy(), lwpointiterator_next(), lwtype_name(), MULTILINETYPE, MULTIPOINTTYPE, LWMLINE::ngeoms, POINTARRAY::npoints, LWLINE::points, 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: