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

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

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

Referenced by create_multipolygon(), and create_polygon().

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