PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ lwgeom_to_marc21()

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

Definition at line 112 of file lwgeom_out_marc21.c.

112  {
113 
114  stringbuffer_t *sb;
115  GBOX box;
116  lwvarlena_t *v;
117 
118  POSTGIS_DEBUGF(2, "lwgeom_to_marc21 called: %s with format %s ", lwtype_name(lwgeom_get_type(geom)), format);
119 
120  if (lwgeom_is_empty(geom)) return NULL;
121  if (is_format_valid(format)==LW_FALSE) lwerror("invalid output format: \"%s\"", format);
122 
123  POSTGIS_DEBUG(3, "creating stringbuffer");
124  sb = stringbuffer_create();
125 
126  POSTGIS_DEBUGF(3, "opening MARC21/XML record: %s", lwtype_name(lwgeom_get_type(geom)));
127 
128  if (stringbuffer_aprintf(sb, "<record xmlns=\"%s\">", MARC21_NS) < 0) {
129 
131  return NULL;
132 
133  }
134 
135 
136  if (lwgeom_is_collection(geom)) {
137 
138  LWCOLLECTION *coll = (LWCOLLECTION*) geom;
139 
140  POSTGIS_DEBUGF(3, " collection detected: %s", lwtype_name(lwgeom_get_type(geom)));
141 
142  for (uint32_t i = 0; i < coll->ngeoms; i++) {
143 
144  if (lwgeom_calculate_gbox(coll->geoms[i], &box) == LW_FAILURE) {
145 
147  lwpgerror("failed to calculate bbox for a geometry in the collection: %s", lwtype_name(lwgeom_get_type(coll->geoms[i])));
148 
149  }
150 
151  if (gbox_to_marc21_sb(box, format, sb) == LW_FAILURE) {
152 
154  lwpgerror("failed to create MARC21/XML for a geometry in the collection: %s", lwtype_name(lwgeom_get_type(coll->geoms[i])));
155 
156  }
157 
158  }
159 
160  } else {
161 
162  POSTGIS_DEBUGF(3, " calculating gbox: %s", lwtype_name(lwgeom_get_type(geom)));
163 
164  if (lwgeom_calculate_gbox(geom, &box) == LW_FAILURE) {
165 
167  lwpgerror("failed to calculate bbox for %s", lwtype_name(lwgeom_get_type(geom)));
168 
169  }
170 
171  POSTGIS_DEBUGF(3, " creating MARC21/XML datafield: %s", lwtype_name(lwgeom_get_type(geom)));
172 
173  if (gbox_to_marc21_sb(box, format, sb) == LW_FAILURE) {
174 
176  lwpgerror("failed to create MARC21/XML for %s", lwtype_name(lwgeom_get_type(geom)));
177 
178  }
179 
180  }
181 
182  POSTGIS_DEBUG(3, " closing MARC21/XML record");
183 
184  if (stringbuffer_aprintf(sb, "</record>") < 0) {
185 
187  return LW_FAILURE;
188 
189  }
190 
193 
194  return v;
195 }
#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 can contain sub-geometries or not.
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 lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
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:145
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:203
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:247
lwvarlena_t * stringbuffer_getvarlenacopy(stringbuffer_t *s)
Definition: stringbuffer.c:151
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: