PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ lwcompound_get_lwpoint()

LWPOINT* lwcompound_get_lwpoint ( const LWCOMPOUND lwcmp,
int  where 
)

Definition at line 200 of file lwcompound.c.

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

Referenced by lwcompound_get_startpoint(), and LWGEOM_pointn_linestring().

201 {
202  int i;
203  int count = 0;
204  int npoints = 0;
205  if ( lwgeom_is_empty((LWGEOM*)lwcmp) )
206  return NULL;
207 
208  npoints = lwgeom_count_vertices((LWGEOM*)lwcmp);
209  if ( where < 0 || where >= npoints )
210  {
211  lwerror("%s: index %d is not in range of number of vertices (%d) in input", __func__, where, npoints);
212  return NULL;
213  }
214 
215  for ( i = 0; i < lwcmp->ngeoms; i++ )
216  {
217  LWGEOM* part = lwcmp->geoms[i];
218  int npoints_part = lwgeom_count_vertices(part);
219  if ( where >= count && where < count + npoints_part )
220  {
221  return lwline_get_lwpoint((LWLINE*)part, where - count);
222  }
223  else
224  {
225  count += npoints_part;
226  }
227  }
228 
229  return NULL;
230 }
int count
Definition: genraster.py:56
LWPOINT * lwline_get_lwpoint(const LWLINE *line, int where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition: lwline.c:295
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:1297
int lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
Definition: lwgeom.c:1140
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
Here is the call graph for this function:
Here is the caller graph for this function: