210{
213 char *gml;
214 text *result;
215 int version;
216 char *srs;
219 int option = 0;
221 static const char *default_prefix = "gml:";
222 const char *prefix = default_prefix;
223 char *prefix_buf = "";
224 text *prefix_text, *id_text = NULL;
225 const char *id = NULL;
226 char *id_buf;
227
228
229
230
231
232
233
234 Oid first_type = get_fn_expr_argtype(fcinfo->flinfo, 0);
235 int argnum = 0;
236 int argeom = 0;
237 if (first_type != INT4OID)
238 {
239 version = 2;
240 }
241 else
242 {
243
244 version = PG_GETARG_INT32(argnum++);
245 argeom = 1;
246 if (version != 2 && version != 3)
247 {
248 elog(ERROR, "Only GML 2 and GML 3 are supported");
249 PG_RETURN_NULL();
250 }
251 }
252
253
254 g = PG_GETARG_GSERIALIZED_P(argnum++);
256 option = PG_GETARG_INT32(argnum++);
257 prefix_text = PG_GETARG_TEXT_P(argnum++);
258 id_text = PG_GETARG_TEXT_P(argnum++);
259
260
262
263
268
269
270 if (VARSIZE_ANY_EXHDR(prefix_text) > 0)
271 {
272
273 prefix_buf = palloc(VARSIZE_ANY_EXHDR(prefix_text)+2);
274 memcpy(prefix_buf, VARDATA_ANY(prefix_text),
275 VARSIZE_ANY_EXHDR(prefix_text));
276
277 prefix_buf[VARSIZE_ANY_EXHDR(prefix_text)] = ':';
278 prefix_buf[VARSIZE_ANY_EXHDR(prefix_text)+1] = '\0';
279 prefix = prefix_buf;
280 }
281 else
282 {
283 prefix = "";
284 }
285
286 if (VARSIZE_ANY_EXHDR(id_text) > 0)
287 {
288 id_buf = palloc(VARSIZE_ANY_EXHDR(id_text)+2);
289 memcpy(id_buf, VARDATA(id_text), VARSIZE_ANY_EXHDR(id_text));
290 id_buf[VARSIZE_ANY_EXHDR(id_text)+1] = '\0';
291 id = id_buf;
292 }
293
294 if (option & 1)
296 else
298 if (!srs)
299 {
300 elog(ERROR,
"SRID %d unknown in spatial_ref_sys table",
SRID_DEFAULT);
301 PG_RETURN_NULL();
302 }
303
304
306 if (option & 2) lwopts &= ~LW_GML_IS_DIMS;
307 if (option & 8)
308 {
309 elog(ERROR,
310 "Options %d passed to ST_AsGML(geography) sets "
311 "unsupported value 8",
312 option);
313 PG_RETURN_NULL();
314 }
315 if ((option & 4) || (option & 16) || (option & 32))
316 {
317 elog(ERROR,
318 "Options %d passed to ST_AsGML(geography) but are only "
319 "applicable to ST_AsGML(geometry)",
320 option);
321 PG_RETURN_NULL();
322 }
323
324 if (version == 2)
326 else
328
330 PG_FREE_IF_COPY(g, argeom);
331
332
333 if (!gml)
334 PG_RETURN_NULL();
335
336
337 result = cstring_to_text(gml);
339
340 PG_RETURN_TEXT_P(result);
341}
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
#define LW_GML_IS_DEGREE
For GML3 only, declare that datas are lat/lon.
void lwgeom_free(LWGEOM *geom)
char * lwgeom_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
VERSION GML 2 takes a GEOMETRY and returns a GML2 representation.
#define LW_GML_IS_DIMS
Macros for specifying GML options.
char * lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id)
char * getSRSbySRID(FunctionCallInfo fcinfo, int32_t srid, bool short_crs)