PostGIS  3.6.1dev-r@@SVN_REVISION@@

◆ lwgeom_to_marc21()

lwvarlena_t * lwgeom_to_marc21 ( const LWGEOM geom,
const char *  format 
)

Definition at line 96 of file lwgeom_out_marc21.c.

96  {
97 
98  stringbuffer_t *sb;
99  GBOX box;
100  lwvarlena_t *v;
101 
102  POSTGIS_DEBUGF(2, "lwgeom_to_marc21 called: %s with format %s ", lwtype_name(lwgeom_get_type(geom)), format);
103 
104  if (lwgeom_is_empty(geom)) return NULL;
105  if (is_format_valid(format)==LW_FALSE) lwerror("invalid output format: \"%s\"", format);
106 
107  POSTGIS_DEBUG(3, "creating stringbuffer");
108  sb = stringbuffer_create();
109 
110  POSTGIS_DEBUGF(3, "opening MARC21/XML record: %s", lwtype_name(lwgeom_get_type(geom)));
111 
112  if (stringbuffer_aprintf(sb, "<record xmlns=\"%s\">", MARC21_NS) < 0) {
113 
115  return NULL;
116 
117  }
118 
119 
120  if (lwgeom_is_collection(geom)) {
121 
122  LWCOLLECTION *coll = (LWCOLLECTION*) geom;
123 
124  POSTGIS_DEBUGF(3, " collection detected: %s", lwtype_name(lwgeom_get_type(geom)));
125 
126  for (uint32_t i = 0; i < coll->ngeoms; i++) {
127 
128  if (lwgeom_calculate_gbox(coll->geoms[i], &box) == LW_FAILURE) {
129 
131  lwpgerror("failed to calculate bbox for a geometry in the collection: %s", lwtype_name(lwgeom_get_type(coll->geoms[i])));
132 
133  }
134 
135  if (gbox_to_marc21_sb(box, format, sb) == LW_FAILURE) {
136 
138  lwpgerror("failed to create MARC21/XML for a geometry in the collection: %s", lwtype_name(lwgeom_get_type(coll->geoms[i])));
139 
140  }
141 
142  }
143 
144  } else {
145 
146  POSTGIS_DEBUGF(3, " calculating gbox: %s", lwtype_name(lwgeom_get_type(geom)));
147 
148  if (lwgeom_calculate_gbox(geom, &box) == LW_FAILURE) {
149 
151  lwpgerror("failed to calculate bbox for %s", lwtype_name(lwgeom_get_type(geom)));
152 
153  }
154 
155  POSTGIS_DEBUGF(3, " creating MARC21/XML datafield: %s", lwtype_name(lwgeom_get_type(geom)));
156 
157  if (gbox_to_marc21_sb(box, format, sb) == LW_FAILURE) {
158 
160  lwpgerror("failed to create MARC21/XML for %s", lwtype_name(lwgeom_get_type(geom)));
161 
162  }
163 
164  }
165 
166  POSTGIS_DEBUG(3, " closing MARC21/XML record");
167 
168  if (stringbuffer_aprintf(sb, "</record>") < 0) {
169 
171  return LW_FAILURE;
172 
173  }
174 
177 
178  return v;
179 }
#define LW_FALSE
Definition: liblwgeom.h:94
#define LW_FAILURE
Definition: liblwgeom.h:96
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM contains sub-geometries or not This basically just checks that the struct ...
Definition: lwgeom.c:1097
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
Definition: lwgeom.c:755
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
static int gbox_to_marc21_sb(const GBOX box, const char *format, stringbuffer_t *sb)
static int is_format_valid(const char *format)
#define MARC21_NS
static uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition: lwinline.h:141
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwinline.h:199
int stringbuffer_aprintf(stringbuffer_t *s, const char *fmt,...)
Appends a formatted string to the current string buffer, using the format and argument list provided.
Definition: stringbuffer.c:254
lwvarlena_t * stringbuffer_getvarlenacopy(stringbuffer_t *s)
Definition: stringbuffer.c:154
stringbuffer_t * stringbuffer_create(void)
Allocate a new stringbuffer_t.
Definition: stringbuffer.c:33
void stringbuffer_destroy(stringbuffer_t *s)
Free the stringbuffer_t and all memory managed within it.
Definition: stringbuffer.c:85
uint32_t ngeoms
Definition: liblwgeom.h:580
LWGEOM ** geoms
Definition: liblwgeom.h:575

References gbox_to_marc21_sb(), LWCOLLECTION::geoms, is_format_valid(), LW_FAILURE, LW_FALSE, lwerror(), lwgeom_calculate_gbox(), lwgeom_get_type(), lwgeom_is_collection(), lwgeom_is_empty(), lwtype_name(), MARC21_NS, LWCOLLECTION::ngeoms, stringbuffer_aprintf(), stringbuffer_create(), stringbuffer_destroy(), and stringbuffer_getvarlenacopy().

Referenced by ST_AsMARC21().

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