PostGIS  2.2.7dev-r@@SVN_REVISION@@
static int is_clockwise ( int  num_points,
double *  x,
double *  y,
double *  z 
)
static

Definition at line 478 of file pgsql2shp-core.c.

References area(), free(), and malloc().

Referenced by create_multipolygon(), and create_polygon().

479 {
480  int i;
481  double x_change,y_change,area;
482  double *x_new, *y_new; /* the points, translated to the origin
483  * for safer accuracy */
484 
485  x_new = (double *)malloc(sizeof(double) * num_points);
486  y_new = (double *)malloc(sizeof(double) * num_points);
487  area=0.0;
488  x_change = x[0];
489  y_change = y[0];
490 
491  for (i=0; i < num_points ; i++)
492  {
493  x_new[i] = x[i] - x_change;
494  y_new[i] = y[i] - y_change;
495  }
496 
497  for (i=0; i < num_points - 1; i++)
498  {
499  /* calculate the area */
500  area += (x[i] * y[i+1]) - (y[i] * x[i+1]);
501  }
502  if (area > 0 )
503  {
504  free(x_new);
505  free(y_new);
506  return 0; /*counter-clockwise */
507  }
508  else
509  {
510  free(x_new);
511  free(y_new);
512  return 1; /*clockwise */
513  }
514 }
Datum area(PG_FUNCTION_ARGS)
tuple x
Definition: pixval.py:53
void free(void *)
void * malloc(YYSIZE_T)
tuple y
Definition: pixval.py:54

Here is the call graph for this function:

Here is the caller graph for this function: