PostGIS  2.3.7dev-r@@SVN_REVISION@@
LWPOINT* lwcompound_get_lwpoint ( const LWCOMPOUND lwcmp,
int  where 
)

Definition at line 213 of file lwcompound.c.

References genraster::count, LWCOMPOUND::geoms, lwerror(), lwgeom_count_vertices(), lwgeom_is_empty(), lwline_get_lwpoint(), and LWCOMPOUND::ngeoms.

Referenced by lwcompound_get_startpoint(), and LWGEOM_pointn_linestring().

214 {
215  int i;
216  int count = 0;
217  int npoints = 0;
218  if ( lwgeom_is_empty((LWGEOM*)lwcmp) )
219  return NULL;
220 
221  npoints = lwgeom_count_vertices((LWGEOM*)lwcmp);
222  if ( where < 0 || where >= npoints )
223  {
224  lwerror("%s: index %d is not in range of number of vertices (%d) in input", __func__, where, npoints);
225  return NULL;
226  }
227 
228  for ( i = 0; i < lwcmp->ngeoms; i++ )
229  {
230  LWGEOM* part = lwcmp->geoms[i];
231  int npoints_part = lwgeom_count_vertices(part);
232  if ( where >= count && where < count + npoints_part )
233  {
234  return lwline_get_lwpoint((LWLINE*)part, where - count);
235  }
236  else
237  {
238  count += npoints_part;
239  }
240  }
241 
242  return NULL;
243 }
LWGEOM ** geoms
Definition: liblwgeom.h:521
int count
Definition: genraster.py:56
int ngeoms
Definition: liblwgeom.h:519
LWPOINT * lwline_get_lwpoint(const LWLINE *line, int where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition: lwline.c:324
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:1310
int lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1153
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:102

Here is the call graph for this function:

Here is the caller graph for this function: