PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ gbox_to_gml3()

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

Definition at line 169 of file lwout_gml.c.

170 {
171  int size;
172  POINT4D pt;
173  POINTARRAY *pa;
174  char *ptr, *output;
175  size_t prefixlen = strlen(prefix);
176  int dimension = 2;
177 
178  if ( ! bbox )
179  {
180  size = ( sizeof("<Envelope>/") + (prefixlen*2) ) * 2;
181  if ( srs ) size += strlen(srs) + sizeof(" srsName=..");
182 
183  lwvarlena_t *v = lwalloc(size + LWVARHDRSZ);
184  ptr = output = v->data;
185 
186  ptr += sprintf(ptr, "<%sEnvelope", prefix);
187  if ( srs ) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
188 
189  ptr += sprintf(ptr, "/>");
190 
191  LWSIZE_SET(v->size, ptr - output + LWVARHDRSZ);
192  return v;
193  }
194 
195  if (FLAGS_GET_Z(bbox->flags)) dimension = 3;
196 
197  pa = ptarray_construct_empty(FLAGS_GET_Z(bbox->flags), 0, 1);
198 
199  pt.x = bbox->xmin;
200  pt.y = bbox->ymin;
201  if (FLAGS_GET_Z(bbox->flags)) pt.z = bbox->zmin;
202  ptarray_append_point(pa, &pt, LW_TRUE);
203 
204  size = pointArray_GMLsize(pa, precision) * 2;
205  size += ( sizeof("<Envelope><lowerCorner><upperCorner>//") + (prefixlen*3) ) * 2;
206  if ( srs ) size += strlen(srs) + sizeof(" srsName=..");
207  if ( IS_DIMS(opts) ) size += sizeof(" srsDimension=. .");
208 
209  lwvarlena_t *v = lwalloc(size + LWVARHDRSZ);
210  ptr = output = v->data;
211 
212  ptr += sprintf(ptr, "<%sEnvelope", prefix);
213  if ( srs ) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
214  if ( IS_DIMS(opts) ) ptr += sprintf(ptr, " srsDimension=\"%d\"", dimension);
215  ptr += sprintf(ptr, ">");
216 
217  ptr += sprintf(ptr, "<%slowerCorner>", prefix);
218  ptr += pointArray_toGML3(pa, ptr, precision, opts);
219  ptr += sprintf(ptr, "</%slowerCorner>", prefix);
220 
221  ptarray_remove_point(pa, 0);
222  pt.x = bbox->xmax;
223  pt.y = bbox->ymax;
224  if (FLAGS_GET_Z(bbox->flags)) pt.z = bbox->zmax;
225  ptarray_append_point(pa, &pt, LW_TRUE);
226 
227  ptr += sprintf(ptr, "<%supperCorner>", prefix);
228  ptr += pointArray_toGML3(pa, ptr, precision, opts);
229  ptr += sprintf(ptr, "</%supperCorner>", prefix);
230 
231  ptr += sprintf(ptr, "</%sEnvelope>", prefix);
232 
233  ptarray_free(pa);
234 
235  LWSIZE_SET(v->size, ptr - output + LWVARHDRSZ);
236  return v;
237 }
static uint8_t precision
Definition: cu_in_twkb.c:25
int ptarray_remove_point(POINTARRAY *pa, uint32_t where)
Remove a point from an existing POINTARRAY.
Definition: ptarray.c:259
#define IS_DIMS(x)
Definition: liblwgeom.h:1682
#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_toGML3(POINTARRAY *pa, char *buf, int precision, int opts)
Definition: lwout_gml.c:1897
static size_t pointArray_GMLsize(POINTARRAY *pa, int precision)
Definition: lwout_gml.c:1950
opts
Definition: ovdump.py:45
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, IS_DIMS, LW_TRUE, lwalloc(), LWSIZE_SET, LWVARHDRSZ, ovdump::opts, pointArray_GMLsize(), pointArray_toGML3(), precision, ptarray_append_point(), ptarray_construct_empty(), ptarray_free(), ptarray_remove_point(), 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_gml3().

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