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;
234 Oid first_type = get_fn_expr_argtype(fcinfo->flinfo, 0);
237 if (first_type != INT4OID)
244 version = PG_GETARG_INT32(argnum++);
246 if (version != 2 && version != 3)
248 elog(ERROR,
"Only GML 2 and GML 3 are supported");
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++);
270 if (VARSIZE_ANY_EXHDR(prefix_text) > 0)
273 prefix_buf = palloc(VARSIZE_ANY_EXHDR(prefix_text)+2);
274 memcpy(prefix_buf, VARDATA_ANY(prefix_text),
275 VARSIZE_ANY_EXHDR(prefix_text));
277 prefix_buf[VARSIZE_ANY_EXHDR(prefix_text)] =
':';
278 prefix_buf[VARSIZE_ANY_EXHDR(prefix_text)+1] =
'\0';
286 if (VARSIZE_ANY_EXHDR(id_text) > 0)
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';
300 elog(ERROR,
"SRID %d unknown in spatial_ref_sys table",
SRID_DEFAULT);
310 "Options %d passed to ST_AsGML(geography) sets "
311 "unsupported value 8",
315 if ((option & 4) || (option & 16) || (option & 32))
318 "Options %d passed to ST_AsGML(geography) but are only "
319 "applicable to ST_AsGML(geometry)",
330 PG_FREE_IF_COPY(g, argeom);
337 result = cstring_to_text(gml);
340 PG_RETURN_TEXT_P(result);
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_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id)
#define LW_GML_IS_DIMS
Macros for specifying GML options.
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.
char * getSRSbySRID(FunctionCallInfo fcinfo, int32_t srid, bool short_crs)