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

Definition at line 213 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 lw_dist2d_distanceline(), and lw_dist3d_distanceline().

214 {
215  int i;
216  int hasz = LW_FALSE;
217  int hasm = LW_FALSE;
218  POINTARRAY *pa;
219  LWLINE *line;
220  POINT4D pt;
221 
222  /*
223  * Find output dimensions, check integrity
224  */
225  for (i=0; i<npoints; i++)
226  {
227  if ( points[i]->type != POINTTYPE )
228  {
229  lwerror("lwline_from_ptarray: invalid input type: %s", lwtype_name(points[i]->type));
230  return NULL;
231  }
232  if ( FLAGS_GET_Z(points[i]->flags) ) hasz = LW_TRUE;
233  if ( FLAGS_GET_M(points[i]->flags) ) hasm = LW_TRUE;
234  if ( hasz && hasm ) break; /* Nothing more to learn! */
235  }
236 
237  pa = ptarray_construct_empty(hasz, hasm, npoints);
238 
239  for ( i=0; i < npoints; i++ )
240  {
241  if ( ! lwpoint_is_empty(points[i]) )
242  {
243  lwpoint_getPoint4d_p(points[i], &pt);
244  ptarray_append_point(pa, &pt, LW_TRUE);
245  }
246  }
247 
248  if ( pa->npoints > 0 )
249  line = lwline_construct(srid, NULL, pa);
250  else
251  line = lwline_construct_empty(srid, hasz, hasm);
252 
253  return line;
254 }
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
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 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
int lwpoint_is_empty(const LWPOINT *point)
Definition: lwpoint.c:258
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:107
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: