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

Definition at line 57 of file lwout_gml.c.

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

58 {
59  int size;
60  POINT4D pt;
61  POINTARRAY *pa;
62  char *ptr, *output;
63  size_t prefixlen = strlen(prefix);
64 
65  if ( ! bbox ) {
66  size = ( sizeof("<Box>/") + (prefixlen*2) ) * 2;
67  if ( srs ) size += strlen(srs) + sizeof(" srsName=..");
68 
69  ptr = output = lwalloc(size);
70 
71  ptr += sprintf(ptr, "<%sBox", prefix);
72 
73  if ( srs ) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
74 
75  ptr += sprintf(ptr, "/>");
76 
77  return output;
78  }
79 
80  pa = ptarray_construct_empty(FLAGS_GET_Z(bbox->flags), 0, 2);
81 
82  pt.x = bbox->xmin;
83  pt.y = bbox->ymin;
84  if (FLAGS_GET_Z(bbox->flags)) pt.z = bbox->zmin;
85  ptarray_append_point(pa, &pt, LW_TRUE);
86 
87  pt.x = bbox->xmax;
88  pt.y = bbox->ymax;
89  if (FLAGS_GET_Z(bbox->flags)) pt.z = bbox->zmax;
90  ptarray_append_point(pa, &pt, LW_TRUE);
91 
92  size = pointArray_GMLsize(pa, precision);
93  size += ( sizeof("<Box><coordinates>/") + (prefixlen*2) ) * 2;
94  if ( srs ) size += strlen(srs) + sizeof(" srsName=..");
95 
96  ptr = output = lwalloc(size);
97 
98  if ( srs ) ptr += sprintf(ptr, "<%sBox srsName=\"%s\">", prefix, srs);
99  else ptr += sprintf(ptr, "<%sBox>", prefix);
100 
101  ptr += sprintf(ptr, "<%scoordinates>", prefix);
102  ptr += pointArray_toGML2(pa, ptr, precision);
103  ptr += sprintf(ptr, "</%scoordinates></%sBox>", prefix, prefix);
104 
105  ptarray_free(pa);
106 
107  return output;
108 }
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
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
double zmin
Definition: liblwgeom.h:252
static size_t pointArray_toGML2(POINTARRAY *pa, char *buf, int precision)
Definition: lwout_gml.c:637
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: