PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ ptarray_calc_areas()

void ptarray_calc_areas ( EFFECTIVE_AREAS ea,
int  avoid_collaps,
int  set_area,
double  trshld 

We calculate the effective area for the first time.

Definition at line 335 of file effectivearea.c.

References areanode::area, area(), POINTARRAY::flags, FLAGS_GET_Z, getPoint_internal(), EFFECTIVE_AREAS::initial_arealist, EFFECTIVE_AREAS::inpts, LWDEBUG, LWDEBUGF, areanode::next, POINTARRAY::npoints, areanode::prev, EFFECTIVE_AREAS::res_arealist, return(), triarea2d(), triarea3d(), and tune_areas().

Referenced by do_test_lwgeom_effectivearea(), and ptarray_set_effective_area().

336 {
337  LWDEBUG(2, "Entered ptarray_calc_areas");
338  int i;
339  int npoints=ea->inpts->npoints;
340  int is3d = FLAGS_GET_Z(ea->inpts->flags);
341  double area;
343  const double *P1;
344  const double *P2;
345  const double *P3;
347  P1 = (double*)getPoint_internal(ea->inpts, 0);
348  P2 = (double*)getPoint_internal(ea->inpts, 1);
350  /*The first and last point shall always have the maximum effective area. We use float max to not make trouble for bbox*/
351  ea->initial_arealist[0].area=ea->initial_arealist[npoints-1].area=FLT_MAX;
352  ea->res_arealist[0]=ea->res_arealist[npoints-1]=FLT_MAX;
354  ea->initial_arealist[0].next=1;
355  ea->initial_arealist[0].prev=0;
357  for (i=1;i<(npoints)-1;i++)
358  {
359  ea->initial_arealist[i].next=i+1;
360  ea->initial_arealist[i].prev=i-1;
361  P3 = (double*)getPoint_internal(ea->inpts, i+1);
363  if(is3d)
364  area=triarea3d(P1, P2, P3);
365  else
366  area=triarea2d(P1, P2, P3);
368  LWDEBUGF(4,"Write area %lf to point %d on address %p",area,i,&(ea->initial_arealist[i].area));
369  ea->initial_arealist[i].area=area;
370  P1=P2;
371  P2=P3;
373  }
374  ea->initial_arealist[npoints-1].next=npoints-1;
375  ea->initial_arealist[npoints-1].prev=npoints-2;
377  for (i=1;i<(npoints)-1;i++)
378  {
379  ea->res_arealist[i]=FLT_MAX;
380  }
382  tune_areas(ea,avoid_collaps,set_area, trshld);
383  return ;
384 }
static double triarea3d(const double *P1, const double *P2, const double *P3)
Calculate the area of a triangle in 3d space.
Definition: effectivearea.c:67
int npoints
Definition: liblwgeom.h:355
double area
Definition: effectivearea.h:26
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
static double triarea2d(const double *P1, const double *P2, const double *P3)
Calculate the area of a triangle in 2d.
Definition: effectivearea.c:58
const POINTARRAY * inpts
Definition: effectivearea.h:52
uint8_t flags
Definition: liblwgeom.h:353
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1706
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:124
double * res_arealist
Definition: effectivearea.h:54
static void tune_areas(EFFECTIVE_AREAS *ea, int avoid_collaps, int set_area, double trshld)
To get the effective area, we have to check what area a point results in when all smaller areas are e...
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
return(const char *)
Definition: dbfopen.c:1609
areanode * initial_arealist
Definition: effectivearea.h:53
Here is the call graph for this function:
Here is the caller graph for this function: