PostGIS  2.5.7dev-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 349 of file effectivearea.c.

350 {
351  LWDEBUG(2, "Entered ptarray_calc_areas");
352  int i;
353  int npoints=ea->inpts->npoints;
354  int is3d = FLAGS_GET_Z(ea->inpts->flags);
355  double area;
356 
357  const double *P1;
358  const double *P2;
359  const double *P3;
360 
361  P1 = (double*)getPoint_internal(ea->inpts, 0);
362  P2 = (double*)getPoint_internal(ea->inpts, 1);
363 
364  /*The first and last point shall always have the maximum effective area. We use float max to not make trouble for bbox*/
365  ea->initial_arealist[0].area=ea->initial_arealist[npoints-1].area=FLT_MAX;
366  ea->res_arealist[0]=ea->res_arealist[npoints-1]=FLT_MAX;
367 
368  ea->initial_arealist[0].next=1;
369  ea->initial_arealist[0].prev=0;
370 
371  for (i=1;i<(npoints)-1;i++)
372  {
373  ea->initial_arealist[i].next=i+1;
374  ea->initial_arealist[i].prev=i-1;
375  P3 = (double*)getPoint_internal(ea->inpts, i+1);
376 
377  if(is3d)
378  area=triarea3d(P1, P2, P3);
379  else
380  area=triarea2d(P1, P2, P3);
381 
382  LWDEBUGF(4,"Write area %lf to point %d on address %p",area,i,&(ea->initial_arealist[i].area));
383  ea->initial_arealist[i].area=area;
384  P1=P2;
385  P2=P3;
386 
387  }
388  ea->initial_arealist[npoints-1].next=npoints-1;
389  ea->initial_arealist[npoints-1].prev=npoints-2;
390 
391  for (i=1;i<(npoints)-1;i++)
392  {
393  ea->res_arealist[i]=FLT_MAX;
394  }
395 
396  tune_areas(ea,avoid_collaps,set_area, trshld);
397  return ;
398 }
return(const char *)
Definition: dbfopen.c:1613
static double triarea2d(const double *P1, const double *P2, const double *P3)
Calculate the area of a triangle in 2d.
Definition: effectivearea.c:72
static double triarea3d(const double *P1, const double *P2, const double *P3)
Calculate the area of a triangle in 3d space.
Definition: effectivearea.c:81
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...
uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition: ptarray.c:1750
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
Datum area(PG_FUNCTION_ARGS)
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
areanode * initial_arealist
Definition: effectivearea.h:67
double * res_arealist
Definition: effectivearea.h:68
const POINTARRAY * inpts
Definition: effectivearea.h:66
uint32_t npoints
Definition: liblwgeom.h:374
uint8_t flags
Definition: liblwgeom.h:372
double area
Definition: effectivearea.h:40

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().

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