PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ gbox_to_gml2()

static lwvarlena_t* gbox_to_gml2 ( const GBOX bbox,
const char *  srs,
int  precision,
const char *  prefix 
)
static

Definition at line 109 of file lwout_gml.c.

110 {
111  int size;
112  POINT4D pt;
113  POINTARRAY *pa;
114  char *ptr, *output;
115  size_t prefixlen = strlen(prefix);
116 
117  if ( ! bbox )
118  {
119  size = ( sizeof("<Box>/") + (prefixlen*2) ) * 2;
120  if ( srs ) size += strlen(srs) + sizeof(" srsName=..");
121 
122  lwvarlena_t *v = lwalloc(size + LWVARHDRSZ);
123  ptr = output = v->data;
124 
125  ptr += sprintf(ptr, "<%sBox", prefix);
126 
127  if ( srs ) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
128 
129  ptr += sprintf(ptr, "/>");
130 
131  LWSIZE_SET(v->size, ptr - output + LWVARHDRSZ);
132 
133  return v;
134  }
135 
136  pa = ptarray_construct_empty(FLAGS_GET_Z(bbox->flags), 0, 2);
137 
138  pt.x = bbox->xmin;
139  pt.y = bbox->ymin;
140  if (FLAGS_GET_Z(bbox->flags)) pt.z = bbox->zmin;
141  ptarray_append_point(pa, &pt, LW_TRUE);
142 
143  pt.x = bbox->xmax;
144  pt.y = bbox->ymax;
145  if (FLAGS_GET_Z(bbox->flags)) pt.z = bbox->zmax;
146  ptarray_append_point(pa, &pt, LW_TRUE);
147 
148  size = pointArray_GMLsize(pa, precision);
149  size += ( sizeof("<Box><coordinates>/") + (prefixlen*2) ) * 2;
150  if ( srs ) size += strlen(srs) + sizeof(" srsName=..");
151 
152  lwvarlena_t *v = lwalloc(size + LWVARHDRSZ);
153  ptr = output = v->data;
154 
155  if ( srs ) ptr += sprintf(ptr, "<%sBox srsName=\"%s\">", prefix, srs);
156  else ptr += sprintf(ptr, "<%sBox>", prefix);
157 
158  ptr += sprintf(ptr, "<%scoordinates>", prefix);
159  ptr += pointArray_toGML2(pa, ptr, precision);
160  ptr += sprintf(ptr, "</%scoordinates></%sBox>", prefix, prefix);
161 
162  ptarray_free(pa);
163  LWSIZE_SET(v->size, ptr - output + LWVARHDRSZ);
164 
165  return v;
166 }
static uint8_t precision
Definition: cu_in_twkb.c:25
#define LWVARHDRSZ
Definition: liblwgeom.h:325
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:179
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:59
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:327
#define LWSIZE_SET(varsize, len)
Definition: liblwgeom.h:339
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE,...
Definition: ptarray.c:147
void * lwalloc(size_t size)
Definition: lwutil.c:227
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:107
static size_t pointArray_GMLsize(POINTARRAY *pa, int precision)
Definition: lwout_gml.c:1950
static size_t pointArray_toGML2(POINTARRAY *pa, char *buf, int precision)
Definition: lwout_gml.c:678
double ymax
Definition: liblwgeom.h:371
double zmax
Definition: liblwgeom.h:373
double xmax
Definition: liblwgeom.h:369
double zmin
Definition: liblwgeom.h:372
double ymin
Definition: liblwgeom.h:370
double xmin
Definition: liblwgeom.h:368
lwflags_t flags
Definition: liblwgeom.h:367
double x
Definition: liblwgeom.h:428
double z
Definition: liblwgeom.h:428
double y
Definition: liblwgeom.h:428
uint32_t size
Definition: liblwgeom.h:321
char data[]
Definition: liblwgeom.h:322

References lwvarlena_t::data, GBOX::flags, FLAGS_GET_Z, LW_TRUE, lwalloc(), LWSIZE_SET, LWVARHDRSZ, pointArray_GMLsize(), pointArray_toGML2(), precision, ptarray_append_point(), ptarray_construct_empty(), ptarray_free(), lwvarlena_t::size, POINT4D::x, GBOX::xmax, GBOX::xmin, POINT4D::y, GBOX::ymax, GBOX::ymin, POINT4D::z, GBOX::zmax, and GBOX::zmin.

Referenced by lwgeom_extent_to_gml2().

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