PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ ptarray_to_kml2_sb()

static int ptarray_to_kml2_sb ( const POINTARRAY pa,
int  precision,
stringbuffer_t sb 
)
static

Definition at line 94 of file lwout_kml.c.

95 {
96  uint32_t i, j;
97  uint32_t dims = FLAGS_GET_Z(pa->flags) ? 3 : 2;
98  POINT4D pt;
99  double *d;
100 
101  for ( i = 0; i < pa->npoints; i++ )
102  {
103  getPoint4d_p(pa, i, &pt);
104  d = (double*)(&pt);
105  if ( i ) stringbuffer_append(sb," ");
106  for (j = 0; j < dims; j++)
107  {
108  if ( j ) stringbuffer_append(sb,",");
109  if( fabs(d[j]) < OUT_MAX_DOUBLE )
110  {
111  if ( stringbuffer_aprintf(sb, "%.*f", precision, d[j]) < 0 ) return LW_FAILURE;
112  }
113  else
114  {
115  if ( stringbuffer_aprintf(sb, "%g", d[j]) < 0 ) return LW_FAILURE;
116  }
118  }
119  }
120  return LW_SUCCESS;
121 }
static uint8_t precision
Definition: cu_in_twkb.c:25
#define LW_FAILURE
Definition: liblwgeom.h:79
#define LW_SUCCESS
Definition: liblwgeom.h:80
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:123
#define OUT_MAX_DOUBLE
int stringbuffer_aprintf(stringbuffer_t *s, const char *fmt,...)
Appends a formatted string to the current string buffer, using the format and argument list provided.
Definition: stringbuffer.c:253
int stringbuffer_trim_trailing_zeroes(stringbuffer_t *s)
Trims zeroes off the end of the last number in the stringbuffer.
Definition: stringbuffer.c:304
void stringbuffer_append(stringbuffer_t *s, const char *a)
Append the specified string to the stringbuffer_t.
Definition: stringbuffer.c:134
uint32_t npoints
Definition: liblwgeom.h:374
uint8_t flags
Definition: liblwgeom.h:372
unsigned int uint32_t
Definition: uthash.h:78

References POINTARRAY::flags, FLAGS_GET_Z, getPoint4d_p(), LW_FAILURE, LW_SUCCESS, POINTARRAY::npoints, OUT_MAX_DOUBLE, precision, stringbuffer_append(), stringbuffer_aprintf(), and stringbuffer_trim_trailing_zeroes().

Referenced by lwline_to_kml2_sb(), lwpoint_to_kml2_sb(), and lwpoly_to_kml2_sb().

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