215 static const char* default_prefix =
"gml:";
216 const char* prefix = default_prefix;
217 const char* gml_id = NULL;
219 char *gml_id_buf, *prefix_buf;
220 text *prefix_text, *gml_id_text;
224 version = PG_GETARG_INT32(0);
225 if ( version != 2 && version != 3 )
227 elog(ERROR,
"Only GML 2 and GML 3 are supported");
232 if ( PG_ARGISNULL(1) ) PG_RETURN_NULL();
233 geom = PG_GETARG_GSERIALIZED_P(1);
236 if (PG_NARGS() > 2 && !PG_ARGISNULL(2))
247 if (PG_NARGS() > 3 && !PG_ARGISNULL(3)) option = PG_GETARG_INT32(3);
250 if (PG_NARGS() >4 && !PG_ARGISNULL(4))
252 prefix_text = PG_GETARG_TEXT_P(4);
253 if ( VARSIZE(prefix_text) == VARHDRSZ )
259 len = VARSIZE(prefix_text)-VARHDRSZ;
260 prefix_buf = palloc(len + 2);
261 memcpy(prefix_buf, VARDATA(prefix_text), len);
263 prefix_buf[len] =
':';
264 prefix_buf[len+1] =
'\0';
269 if (PG_NARGS() >5 && !PG_ARGISNULL(5))
271 gml_id_text = PG_GETARG_TEXT_P(5);
272 if ( VARSIZE(gml_id_text) == VARHDRSZ )
278 len = VARSIZE(gml_id_text)-VARHDRSZ;
279 gml_id_buf = palloc(len+1);
280 memcpy(gml_id_buf, VARDATA(gml_id_text), len);
281 gml_id_buf[len] =
'\0';
298 "Options %d passed to ST_AsGML(geography) sets "
299 "unsupported value 8",
323 lwgeom, srs,
precision, lwopts, prefix, gml_id);
327 PG_FREE_IF_COPY(geom, 1);
333 result = cstring_to_text(gml);
335 PG_RETURN_TEXT_P(result);
int32_t gserialized_get_srid(const GSERIALIZED *s)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
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)
#define LW_GML_SHORTLINE
For GML3, use <LineString> rather than <Curve> for lines.
#define LW_GML_EXTENT
For GML2 and GML3, output only extent of geometry.
char * lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id)
char * lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix)
#define LW_GML_IS_DIMS
Macros for specifying GML options.
char * lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
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 SRID_UNKNOWN
Unknown SRID value.
char * getSRSbySRID(FunctionCallInfo fcinfo, int srid, bool short_crs)