222 static const char *default_prefix =
"gml:";
223 const char *prefix = default_prefix;
224 char *prefix_buf =
"";
225 text *prefix_text, *id_text = NULL;
231 version = PG_GETARG_INT32(0);
232 if ( version != 2 && version != 3 )
234 elog(ERROR,
"Only GML 2 and GML 3 are supported");
239 if ( PG_ARGISNULL(1) ) PG_RETURN_NULL();
240 g = PG_GETARG_GSERIALIZED_P(1);
246 if (PG_NARGS() >2 && !PG_ARGISNULL(2))
256 if (PG_NARGS() >3 && !PG_ARGISNULL(3))
257 option = PG_GETARG_INT32(3);
261 if (PG_NARGS() >4 && !PG_ARGISNULL(4))
263 prefix_text = PG_GETARG_TEXT_P(4);
264 if ( VARSIZE(prefix_text)-VARHDRSZ == 0 )
271 prefix_buf = palloc(VARSIZE(prefix_text)-VARHDRSZ+2);
272 memcpy(prefix_buf, VARDATA(prefix_text),
273 VARSIZE(prefix_text)-VARHDRSZ);
275 prefix_buf[VARSIZE(prefix_text)-VARHDRSZ] =
':';
276 prefix_buf[VARSIZE(prefix_text)-VARHDRSZ+1] =
'\0';
282 if (PG_NARGS() >5 && !PG_ARGISNULL(5))
284 id_text = PG_GETARG_TEXT_P(5);
285 if ( VARSIZE(id_text)-VARHDRSZ == 0 )
291 id_buf = palloc(VARSIZE(id_text)-VARHDRSZ+1);
292 memcpy(id_buf, VARDATA(id_text), VARSIZE(id_text)-VARHDRSZ);
293 prefix_buf[VARSIZE(id_text)-VARHDRSZ+1] =
'\0';
304 elog(ERROR,
"SRID %d unknown in spatial_ref_sys table",
SRID_DEFAULT);
314 "Options %d passed to ST_AsGML(geography) sets "
315 "unsupported value 8",
319 if ((option & 4) || (option & 16) || (option & 32))
322 "Options %d passed to ST_AsGML(geography) but are only "
323 "applicable to ST_AsGML(geometry)",
334 PG_FREE_IF_COPY(g, 1);
341 result = cstring_to_text(gml);
344 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, int srid, bool short_crs)