PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ lwline_from_ptarray()

LWLINE* lwline_from_ptarray ( int32_t  srid,
uint32_t  npoints,
LWPOINT **  points 
)

Definition at line 228 of file lwline.c.

229 {
230  uint32_t i;
231  int hasz = LW_FALSE;
232  int hasm = LW_FALSE;
233  POINTARRAY *pa;
234  LWLINE *line;
235  POINT4D pt;
236 
237  /*
238  * Find output dimensions, check integrity
239  */
240  for (i=0; i<npoints; i++)
241  {
242  if ( points[i]->type != POINTTYPE )
243  {
244  lwerror("lwline_from_ptarray: invalid input type: %s", lwtype_name(points[i]->type));
245  return NULL;
246  }
247  if ( FLAGS_GET_Z(points[i]->flags) ) hasz = LW_TRUE;
248  if ( FLAGS_GET_M(points[i]->flags) ) hasm = LW_TRUE;
249  if ( hasz && hasm ) break; /* Nothing more to learn! */
250  }
251 
252  pa = ptarray_construct_empty(hasz, hasm, npoints);
253 
254  for ( i=0; i < npoints; i++ )
255  {
256  if ( ! lwpoint_is_empty(points[i]) )
257  {
258  lwpoint_getPoint4d_p(points[i], &pt);
259  ptarray_append_point(pa, &pt, LW_TRUE);
260  }
261  }
262 
263  if ( pa->npoints > 0 )
264  line = lwline_construct(srid, NULL, pa);
265  else
266  line = lwline_construct_empty(srid, hasz, hasm);
267 
268  return line;
269 }
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:57
#define LW_FALSE
Definition: liblwgeom.h:108
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:116
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:179
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:59
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:180
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,...
Definition: ptarray.c:147
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:107
int lwpoint_is_empty(const LWPOINT *point)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
LWLINE * lwline_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwline.c:55
type
Definition: ovdump.py:42
uint32_t npoints
Definition: liblwgeom.h:413

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(), ptarray_construct_empty(), and ovdump::type.

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

Here is the call graph for this function:
Here is the caller graph for this function: