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

Definition at line 214 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().

215 {
216  int i;
217  int hasz = LW_FALSE;
218  int hasm = LW_FALSE;
219  POINTARRAY *pa;
220  LWLINE *line;
221  POINT4D pt;
222 
223  /*
224  * Find output dimensions, check integrity
225  */
226  for (i=0; i<npoints; i++)
227  {
228  if ( points[i]->type != POINTTYPE )
229  {
230  lwerror("lwline_from_ptarray: invalid input type: %s", lwtype_name(points[i]->type));
231  return NULL;
232  }
233  if ( FLAGS_GET_Z(points[i]->flags) ) hasz = LW_TRUE;
234  if ( FLAGS_GET_M(points[i]->flags) ) hasm = LW_TRUE;
235  if ( hasz && hasm ) break; /* Nothing more to learn! */
236  }
237 
238  pa = ptarray_construct_empty(hasz, hasm, npoints);
239 
240  for ( i=0; i < npoints; i++ )
241  {
242  if ( ! lwpoint_is_empty(points[i]) )
243  {
244  lwpoint_getPoint4d_p(points[i], &pt);
245  ptarray_append_point(pa, &pt, LW_TRUE);
246  }
247  }
248 
249  if ( pa->npoints > 0 )
250  line = lwline_construct(srid, NULL, pa);
251  else
252  line = lwline_construct_empty(srid, hasz, hasm);
253 
254  return line;
255 }
int npoints
Definition: liblwgeom.h:355
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:51
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:188
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:156
#define LW_FALSE
Definition: liblwgeom.h:62
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:61
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:44
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:124
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
int lwpoint_is_empty(const LWPOINT *point)
Definition: lwpoint.c:260
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:125
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
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: