PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ gbox_to_gml3()

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

Definition at line 117 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().

118 {
119  int size;
120  POINT4D pt;
121  POINTARRAY *pa;
122  char *ptr, *output;
123  size_t prefixlen = strlen(prefix);
124  int dimension = 2;
125 
126  if ( ! bbox )
127  {
128  size = ( sizeof("<Envelope>/") + (prefixlen*2) ) * 2;
129  if ( srs ) size += strlen(srs) + sizeof(" srsName=..");
130 
131  ptr = output = lwalloc(size);
132 
133  ptr += sprintf(ptr, "<%sEnvelope", prefix);
134  if ( srs ) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
135 
136  ptr += sprintf(ptr, "/>");
137 
138  return output;
139  }
140 
141  if (FLAGS_GET_Z(bbox->flags)) dimension = 3;
142 
143  pa = ptarray_construct_empty(FLAGS_GET_Z(bbox->flags), 0, 1);
144 
145  pt.x = bbox->xmin;
146  pt.y = bbox->ymin;
147  if (FLAGS_GET_Z(bbox->flags)) pt.z = bbox->zmin;
148  ptarray_append_point(pa, &pt, LW_TRUE);
149 
150  size = pointArray_GMLsize(pa, precision) * 2;
151  size += ( sizeof("<Envelope><lowerCorner><upperCorner>//") + (prefixlen*3) ) * 2;
152  if ( srs ) size += strlen(srs) + sizeof(" srsName=..");
153  if ( IS_DIMS(opts) ) size += sizeof(" srsDimension=. .");
154 
155  ptr = output = lwalloc(size);
156 
157  ptr += sprintf(ptr, "<%sEnvelope", prefix);
158  if ( srs ) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
159  if ( IS_DIMS(opts) ) ptr += sprintf(ptr, " srsDimension=\"%d\"", dimension);
160  ptr += sprintf(ptr, ">");
161 
162  ptr += sprintf(ptr, "<%slowerCorner>", prefix);
163  ptr += pointArray_toGML3(pa, ptr, precision, opts);
164  ptr += sprintf(ptr, "</%slowerCorner>", prefix);
165 
166  ptarray_remove_point(pa, 0);
167  pt.x = bbox->xmax;
168  pt.y = bbox->ymax;
169  if (FLAGS_GET_Z(bbox->flags)) pt.z = bbox->zmax;
170  ptarray_append_point(pa, &pt, LW_TRUE);
171 
172  ptr += sprintf(ptr, "<%supperCorner>", prefix);
173  ptr += pointArray_toGML3(pa, ptr, precision, opts);
174  ptr += sprintf(ptr, "</%supperCorner>", prefix);
175 
176  ptr += sprintf(ptr, "</%sEnvelope>", prefix);
177 
178  ptarray_free(pa);
179 
180  return output;
181 }
double x
Definition: liblwgeom.h:336
double xmax
Definition: liblwgeom.h:277
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:330
double zmax
Definition: liblwgeom.h:281
double ymin
Definition: liblwgeom.h:278
double xmin
Definition: liblwgeom.h:276
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:156
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:61
#define IS_DIMS(x)
Definition: liblwgeom.h:1478
uint8_t precision
Definition: cu_in_twkb.c:25
double ymax
Definition: liblwgeom.h:279
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:124
double z
Definition: liblwgeom.h:336
uint8_t flags
Definition: liblwgeom.h:275
static size_t pointArray_GMLsize(POINTARRAY *pa, int precision)
Definition: lwout_gml.c:1974
int ptarray_remove_point(POINTARRAY *pa, int where)
Remove a point from an existing POINTARRAY.
Definition: ptarray.c:261
double zmin
Definition: liblwgeom.h:280
static size_t pointArray_toGML3(POINTARRAY *pa, char *buf, int precision, int opts)
Definition: lwout_gml.c:1896
void * lwalloc(size_t size)
Definition: lwutil.c:199
double y
Definition: liblwgeom.h:336
opts
Definition: ovdump.py:44
Here is the call graph for this function:
Here is the caller graph for this function: