PostGIS  2.1.10dev-r@@SVN_REVISION@@
LWLINE* lwline_from_lwgeom_array ( int  srid,
uint32_t  ngeoms,
LWGEOM **  geoms 
)

Definition at line 152 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(), lwtype_name(), 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().

153 {
154  int i;
155  int hasz = LW_FALSE;
156  int hasm = LW_FALSE;
157  POINTARRAY *pa;
158  LWLINE *line;
159  POINT4D pt;
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  /* ngeoms should be a guess about how many points we have in input */
172  pa = ptarray_construct_empty(hasz, hasm, ngeoms);
173 
174  for ( i=0; i < ngeoms; i++ )
175  {
176  LWGEOM *g = geoms[i];
177 
178  if ( lwgeom_is_empty(g) ) continue;
179 
180  if ( g->type == POINTTYPE )
181  {
182  lwpoint_getPoint4d_p((LWPOINT*)g, &pt);
183  ptarray_append_point(pa, &pt, LW_TRUE);
184  }
185  else if ( g->type == LINETYPE )
186  {
187  ptarray_append_ptarray(pa, ((LWLINE*)g)->points, -1);
188  }
189  else
190  {
191  ptarray_free(pa);
192  lwerror("lwline_from_ptarray: invalid input type: %s", lwtype_name(g->type));
193  return NULL;
194  }
195  }
196 
197  if ( pa->npoints > 0 )
198  line = lwline_construct(srid, NULL, pa);
199  else {
200  /* Is this really any different from the above ? */
201  ptarray_free(pa);
202  line = lwline_construct_empty(srid, hasz, hasm);
203  }
204 
205  return line;
206 }
#define LINETYPE
Definition: liblwgeom.h:61
int npoints
Definition: liblwgeom.h:327
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:57
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:315
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
Definition: lwline.c:51
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:164
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_TRUE, then a duplicate point will not be added.
Definition: ptarray.c:141
#define LW_FALSE
Definition: liblwgeom.h:52
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51
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:172
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:42
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:106
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:107
uint8_t type
Definition: liblwgeom.h:352
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:1229
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:29

Here is the call graph for this function:

Here is the caller graph for this function: