PostGIS  2.3.7dev-r@@SVN_REVISION@@
LWLINE* lwline_from_ptarray ( int  srid,
uint32_t  npoints,
LWPOINT **  points 
)

Definition at line 243 of file lwline.c.

References FLAGS_GET_M, FLAGS_GET_Z, LW_FALSE, LW_TRUE, lwerror(), lwline_construct(), lwline_construct_empty(), lwpoint_getPoint4d_p(), lwpoint_is_empty(), lwtype_name(), POINTARRAY::npoints, POINTTYPE, ptarray_append_point(), and ptarray_construct_empty().

Referenced by create_v_line(), lw_dist2d_distanceline(), and lw_dist3d_distanceline().

244 {
245  int i;
246  int hasz = LW_FALSE;
247  int hasm = LW_FALSE;
248  POINTARRAY *pa;
249  LWLINE *line;
250  POINT4D pt;
251 
252  /*
253  * Find output dimensions, check integrity
254  */
255  for (i=0; i<npoints; i++)
256  {
257  if ( points[i]->type != POINTTYPE )
258  {
259  lwerror("lwline_from_ptarray: invalid input type: %s", lwtype_name(points[i]->type));
260  return NULL;
261  }
262  if ( FLAGS_GET_Z(points[i]->flags) ) hasz = LW_TRUE;
263  if ( FLAGS_GET_M(points[i]->flags) ) hasm = LW_TRUE;
264  if ( hasz && hasm ) break; /* Nothing more to learn! */
265  }
266 
267  pa = ptarray_construct_empty(hasz, hasm, npoints);
268 
269  for ( i=0; i < npoints; i++ )
270  {
271  if ( ! lwpoint_is_empty(points[i]) )
272  {
273  lwpoint_getPoint4d_p(points[i], &pt);
274  ptarray_append_point(pa, &pt, LW_TRUE);
275  }
276  }
277 
278  if ( pa->npoints > 0 )
279  line = lwline_construct(srid, NULL, pa);
280  else
281  line = lwline_construct_empty(srid, hasz, hasm);
282 
283  return line;
284 }
int npoints
Definition: liblwgeom.h:370
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
Definition: lwline.c:64
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
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 lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:57
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:139
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
int lwpoint_is_empty(const LWPOINT *point)
Definition: lwpoint.c:273
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:140
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102
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: