PostGIS  2.1.10dev-r@@SVN_REVISION@@
static char* gbox_to_gml3 ( const GBOX bbox,
const char *  srs,
int  precision,
int  opts,
const char *  prefix 
)
static

Definition at line 111 of file lwout_gml.c.

References GBOX::flags, FLAGS_GET_Z, IS_DIMS, LW_TRUE, lwalloc(), pointArray_GMLsize(), pointArray_toGML3(), ptarray_append_point(), ptarray_construct_empty(), ptarray_free(), ptarray_remove_point(), 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().

112 {
113  int size;
114  POINT4D pt;
115  POINTARRAY *pa;
116  char *ptr, *output;
117  size_t prefixlen = strlen(prefix);
118  int dimension = 2;
119 
120  if ( ! bbox ) {
121  size = ( sizeof("<Envelope>/") + (prefixlen*2) ) * 2;
122  if ( srs ) size += strlen(srs) + sizeof(" srsName=..");
123 
124  ptr = output = lwalloc(size);
125 
126  ptr += sprintf(ptr, "<%sEnvelope", prefix);
127  if ( srs ) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
128 
129  ptr += sprintf(ptr, "/>");
130 
131  return output;
132  }
133 
134  if (FLAGS_GET_Z(bbox->flags)) dimension = 3;
135 
136  pa = ptarray_construct_empty(FLAGS_GET_Z(bbox->flags), 0, 1);
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  size = pointArray_GMLsize(pa, precision) * 2;
144  size += ( sizeof("<Envelope><lowerCorner><upperCorner>//") + (prefixlen*3) ) * 2;
145  if ( srs ) size += strlen(srs) + sizeof(" srsName=..");
146  if ( IS_DIMS(opts) ) size += sizeof(" srsDimension=. .");
147 
148  ptr = output = lwalloc(size);
149 
150  ptr += sprintf(ptr, "<%sEnvelope", prefix);
151  if ( srs ) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
152  if ( IS_DIMS(opts) ) ptr += sprintf(ptr, " srsDimension=\"%d\"", dimension);
153  ptr += sprintf(ptr, ">");
154 
155  ptr += sprintf(ptr, "<%slowerCorner>", prefix);
156  ptr += pointArray_toGML3(pa, ptr, precision, opts);
157  ptr += sprintf(ptr, "</%slowerCorner>", prefix);
158 
159  ptarray_remove_point(pa, 0);
160  pt.x = bbox->xmax;
161  pt.y = bbox->ymax;
162  if (FLAGS_GET_Z(bbox->flags)) pt.z = bbox->zmax;
163  ptarray_append_point(pa, &pt, LW_TRUE);
164 
165  ptr += sprintf(ptr, "<%supperCorner>", prefix);
166  ptr += pointArray_toGML3(pa, ptr, precision, opts);
167  ptr += sprintf(ptr, "</%supperCorner>", prefix);
168 
169  ptr += sprintf(ptr, "</%sEnvelope>", prefix);
170 
171  ptarray_free(pa);
172 
173  return output;
174 }
double x
Definition: liblwgeom.h:308
double xmax
Definition: liblwgeom.h:249
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:57
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:315
double zmax
Definition: liblwgeom.h:253
double ymin
Definition: liblwgeom.h:250
double xmin
Definition: liblwgeom.h:248
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_TRUE, then a duplicate point will not be added.
Definition: ptarray.c:141
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51
#define IS_DIMS(x)
Definition: liblwgeom.h:1367
double ymax
Definition: liblwgeom.h:251
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:106
double z
Definition: liblwgeom.h:308
uint8_t flags
Definition: liblwgeom.h:247
static size_t pointArray_GMLsize(POINTARRAY *pa, int precision)
Definition: lwout_gml.c:1471
int ptarray_remove_point(POINTARRAY *pa, int where)
Remove a point from an existing POINTARRAY.
Definition: ptarray.c:246
double zmin
Definition: liblwgeom.h:252
static size_t pointArray_toGML3(POINTARRAY *pa, char *buf, int precision, int opts)
Definition: lwout_gml.c:1393
void * lwalloc(size_t size)
Definition: lwutil.c:175
double y
Definition: liblwgeom.h:308

Here is the call graph for this function:

Here is the caller graph for this function: