PostGIS  2.5.1dev-r@@SVN_REVISION@@

## ◆ lwline_from_lwgeom_array()

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

Definition at line 160 of file lwline.c.

Referenced by LWGEOM_makeline(), and LWGEOM_makeline_garray().

161 {
162  uint32_t i;
163  int hasz = LW_FALSE;
164  int hasm = LW_FALSE;
165  POINTARRAY *pa;
166  LWLINE *line;
167  POINT4D pt;
168  LWPOINTITERATOR* it;
169
170  /*
171  * Find output dimensions, check integrity
172  */
173  for (i=0; i<ngeoms; i++)
174  {
175  if ( FLAGS_GET_Z(geoms[i]->flags) ) hasz = LW_TRUE;
176  if ( FLAGS_GET_M(geoms[i]->flags) ) hasm = LW_TRUE;
177  if ( hasz && hasm ) break; /* Nothing more to learn! */
178  }
179
180  /*
181  * ngeoms should be a guess about how many points we have in input.
182  * It's an underestimate for lines and multipoints */
183  pa = ptarray_construct_empty(hasz, hasm, ngeoms);
184
185  for ( i=0; i < ngeoms; i++ )
186  {
187  LWGEOM *g = geoms[i];
188
189  if ( lwgeom_is_empty(g) ) continue;
190
191  if ( g->type == POINTTYPE )
192  {
193  lwpoint_getPoint4d_p((LWPOINT*)g, &pt);
194  ptarray_append_point(pa, &pt, LW_TRUE);
195  }
196  else if ( g->type == LINETYPE )
197  {
198  /*
199  * Append the new line points, de-duplicating against the previous points.
200  * Duplicated points internal to the linestring are untouched.
201  */
202  ptarray_append_ptarray(pa, ((LWLINE*)g)->points, -1);
203  }
204  else if ( g->type == MULTIPOINTTYPE )
205  {
206  it = lwpointiterator_create(g);
207  while(lwpointiterator_next(it, &pt))
208  {
209  ptarray_append_point(pa, &pt, LW_TRUE);
210  }
212  }
213  else
214  {
215  ptarray_free(pa);
216  lwerror("lwline_from_ptarray: invalid input type: %s", lwtype_name(g->type));
217  return NULL;
218  }
219  }
220
221  if ( pa->npoints > 0 )
222  line = lwline_construct(srid, NULL, pa);
223  else {
224  /* Is this really any different from the above ? */
225  ptarray_free(pa);
226  line = lwline_construct_empty(srid, hasz, hasm);
227  }
228
229  return line;
230 }
#define LINETYPE
Definition: liblwgeom.h:85
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
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:328
#define MULTIPOINTTYPE
Definition: liblwgeom.h:87
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
unsigned int uint32_t
Definition: uthash.h:78
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:76
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
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:139
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
uint8_t type
Definition: liblwgeom.h:398
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:1393
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
uint32_t npoints
Definition: liblwgeom.h:373
Here is the call graph for this function:
Here is the caller graph for this function: