PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwline_from_lwgeom_array()

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

Definition at line 166 of file lwline.c.

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 LWGEOM_makeline(), and LWGEOM_makeline_garray().

167 {
168  int i;
169  int hasz = LW_FALSE;
170  int hasm = LW_FALSE;
171  POINTARRAY *pa;
172  LWLINE *line;
173  POINT4D pt;
174  LWPOINTITERATOR* it;
175 
176  /*
177  * Find output dimensions, check integrity
178  */
179  for (i=0; i<ngeoms; i++)
180  {
181  if ( FLAGS_GET_Z(geoms[i]->flags) ) hasz = LW_TRUE;
182  if ( FLAGS_GET_M(geoms[i]->flags) ) hasm = LW_TRUE;
183  if ( hasz && hasm ) break; /* Nothing more to learn! */
184  }
185 
186  /*
187  * ngeoms should be a guess about how many points we have in input.
188  * It's an underestimate for lines and multipoints */
189  pa = ptarray_construct_empty(hasz, hasm, ngeoms);
190 
191  for ( i=0; i < ngeoms; i++ )
192  {
193  LWGEOM *g = geoms[i];
194 
195  if ( lwgeom_is_empty(g) ) continue;
196 
197  if ( g->type == POINTTYPE )
198  {
199  lwpoint_getPoint4d_p((LWPOINT*)g, &pt);
200  ptarray_append_point(pa, &pt, LW_TRUE);
201  }
202  else if ( g->type == LINETYPE )
203  {
204  /*
205  * Append the new line points, de-duplicating against the previous points.
206  * Duplicated points internal to the linestring are untouched.
207  */
208  ptarray_append_ptarray(pa, ((LWLINE*)g)->points, -1);
209  }
210  else if ( g->type == MULTIPOINTTYPE )
211  {
212  it = lwpointiterator_create(g);
213  while(lwpointiterator_next(it, &pt))
214  {
215  ptarray_append_point(pa, &pt, LW_TRUE);
216  }
218  }
219  else
220  {
221  ptarray_free(pa);
222  lwerror("lwline_from_ptarray: invalid input type: %s", lwtype_name(g->type));
223  return NULL;
224  }
225  }
226 
227  if ( pa->npoints > 0 )
228  line = lwline_construct(srid, NULL, pa);
229  else {
230  /* Is this really any different from the above ? */
231  ptarray_free(pa);
232  line = lwline_construct_empty(srid, hasz, hasm);
233  }
234 
235  return line;
236 }
#define LINETYPE
Definition: liblwgeom.h:86
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:212
int npoints
Definition: liblwgeom.h:371
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:330
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
Definition: lwline.c:64
LWPOINTITERATOR * lwpointiterator_create(const LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM*.
Definition: lwiterator.c:244
void lwpointiterator_destroy(LWPOINTITERATOR *s)
Free all memory associated with the iterator.
Definition: lwiterator.c:269
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
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, then a duplicate point will not be added.
Definition: ptarray.c:156
#define LW_FALSE
Definition: liblwgeom.h:77
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
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:187
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:57
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:140
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
uint8_t type
Definition: liblwgeom.h:396
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1346
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
Here is the call graph for this function:
Here is the caller graph for this function: