PostGIS  2.1.10dev-r@@SVN_REVISION@@
static size_t pointArray_svg_rel ( POINTARRAY pa,
char *  output,
int  close_ring,
int  precision 
)
static

Definition at line 547 of file lwout_svg.c.

References getPoint2d_cp(), POINTARRAY::npoints, OUT_MAX_DIGS_DOUBLE, OUT_MAX_DOUBLE, OUT_MAX_DOUBLE_PRECISION, trim_trailing_zeros(), pixval::x, POINT2D::x, pixval::y, and POINT2D::y.

Referenced by assvg_line_buf(), and assvg_polygon_buf().

548 {
549  int i, end;
550  char *ptr;
553  const POINT2D *pt;
554 
555  double f = 1.0;
556  double dx, dy, x, y, accum_x, accum_y;
557 
558  ptr = output;
559 
560  if (precision >= 0)
561  {
562  f = pow(10, precision);
563  }
564 
565  if (close_ring) end = pa->npoints;
566  else end = pa->npoints - 1;
567 
568  /* Starting point */
569  pt = getPoint2d_cp(pa, 0);
570 
571  x = round(pt->x*f)/f;
572  y = round(pt->y*f)/f;
573 
574  if (fabs(x) < OUT_MAX_DOUBLE)
575  sprintf(sx, "%.*f", precision, x);
576  else
577  sprintf(sx, "%g", x);
579 
580  if (fabs(y) < OUT_MAX_DOUBLE)
581  sprintf(sy, "%.*f", precision, fabs(y) ? y * -1 : y);
582  else
583  sprintf(sy, "%g", fabs(y) ? y * -1 : y);
585 
586  ptr += sprintf(ptr,"%s %s l", sx, sy);
587 
588  /* accum */
589  accum_x = x;
590  accum_y = y;
591 
592  /* All the following ones */
593  for (i=1 ; i < end ; i++)
594  {
595  // lpt = pt;
596 
597  pt = getPoint2d_cp(pa, i);
598 
599  x = round(pt->x*f)/f;
600  y = round(pt->y*f)/f;
601  dx = x - accum_x;
602  dy = y - accum_y;
603 
604  if (fabs(dx) < OUT_MAX_DOUBLE)
605  sprintf(sx, "%.*f", precision, dx);
606  else
607  sprintf(sx, "%g", dx);
609 
610  /* SVG Y axis is reversed, an no need to transform 0 into -0 */
611  if (fabs(dy) < OUT_MAX_DOUBLE)
612  sprintf(sy, "%.*f", precision,
613  fabs(dy) ? dy * -1: dy);
614  else
615  sprintf(sy, "%g",
616  fabs(dy) ? dy * -1: dy);
618 
619  accum_x += dx;
620  accum_y += dy;
621 
622  ptr += sprintf(ptr," %s %s", sx, sy);
623  }
624 
625  return (ptr-output);
626 }
int npoints
Definition: liblwgeom.h:327
#define OUT_MAX_DOUBLE_PRECISION
void trim_trailing_zeros(char *num)
Definition: lwutil.c:200
double x
Definition: liblwgeom.h:284
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:458
double y
Definition: liblwgeom.h:284
tuple x
Definition: pixval.py:53
#define OUT_MAX_DOUBLE
#define OUT_MAX_DIGS_DOUBLE
tuple y
Definition: pixval.py:54

Here is the call graph for this function:

Here is the caller graph for this function: