205{
209 int version;
210 const char *srs;
213 int option = 0;
215 static const char *default_prefix = "gml:";
216 const char *prefix = default_prefix;
217 char *prefix_buf = "";
218 text *prefix_text, *id_text = NULL;
219 const char *id = NULL;
220 char *id_buf;
221
222
223
224
225
226
227
228 Oid first_type = get_fn_expr_argtype(fcinfo->flinfo, 0);
229 int argnum = 0;
230 if (first_type != INT4OID)
231 {
232 version = 2;
233 }
234 else
235 {
236
237 version = PG_GETARG_INT32(argnum++);
238 if (version != 2 && version != 3)
239 {
240 elog(ERROR, "Only GML 2 and GML 3 are supported");
241 PG_RETURN_NULL();
242 }
243 }
244
245
246 g = PG_GETARG_GSERIALIZED_P(argnum++);
248 option = PG_GETARG_INT32(argnum++);
249 prefix_text = PG_GETARG_TEXT_P(argnum++);
250 id_text = PG_GETARG_TEXT_P(argnum++);
251
252
254
255
256 if (VARSIZE_ANY_EXHDR(prefix_text) > 0)
257 {
258
259 prefix_buf = palloc(VARSIZE_ANY_EXHDR(prefix_text)+2);
260 memcpy(prefix_buf, VARDATA_ANY(prefix_text),
261 VARSIZE_ANY_EXHDR(prefix_text));
262
263 prefix_buf[VARSIZE_ANY_EXHDR(prefix_text)] = ':';
264 prefix_buf[VARSIZE_ANY_EXHDR(prefix_text)+1] = '\0';
265 prefix = prefix_buf;
266 }
267 else
268 {
269 prefix = "";
270 }
271
272 if (VARSIZE_ANY_EXHDR(id_text) > 0)
273 {
274 id_buf = palloc(VARSIZE_ANY_EXHDR(id_text)+2);
275 memcpy(id_buf, VARDATA(id_text), VARSIZE_ANY_EXHDR(id_text));
276 id_buf[VARSIZE_ANY_EXHDR(id_text)+1] = '\0';
277 id = id_buf;
278 }
279
280 if (option & 1)
281 srs = GetSRSCacheBySRID(fcinfo, srid, false);
282 else
283 srs = GetSRSCacheBySRID(fcinfo, srid, true);
284 if (!srs)
285 {
286 elog(ERROR,
"SRID %d unknown in spatial_ref_sys table",
SRID_DEFAULT);
287 PG_RETURN_NULL();
288 }
289
290
292 if (option & 2) lwopts &= ~LW_GML_IS_DIMS;
293 if (option & 8)
294 {
295 elog(ERROR,
296 "Options %d passed to ST_AsGML(geography) sets "
297 "unsupported value 8",
298 option);
299 PG_RETURN_NULL();
300 }
301 if ((option & 4) || (option & 16) || (option & 32))
302 {
303 elog(ERROR,
304 "Options %d passed to ST_AsGML(geography) but are only "
305 "applicable to ST_AsGML(geometry)",
306 option);
307 PG_RETURN_NULL();
308 }
309
310 if (version == 2)
312 else
314
315 if (!v)
316 PG_RETURN_NULL();
317 else
318 PG_RETURN_TEXT_P(v);
319}
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
#define LW_GML_IS_DEGREE
For GML3 only, declare that data are lat/lon.
lwvarlena_t * lwgeom_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
#define LW_GML_IS_DIMS
Macros for specifying GML options.
lwvarlena_t * lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id)