221 static const char* default_prefix =
"gml:";
222 const char* prefix = default_prefix;
223 const char* gml_id = NULL;
225 char *gml_id_buf, *prefix_buf;
226 text *prefix_text, *gml_id_text;
230 version = PG_GETARG_INT32(0);
231 if ( version != 2 && version != 3 )
233 elog(ERROR,
"Only GML 2 and GML 3 are supported");
238 if ( PG_ARGISNULL(1) ) PG_RETURN_NULL();
239 geom = PG_GETARG_GSERIALIZED_P(1);
242 if (PG_NARGS() > 2 && !PG_ARGISNULL(2))
253 if (PG_NARGS() > 3 && !PG_ARGISNULL(3)) option = PG_GETARG_INT32(3);
256 if (PG_NARGS() >4 && !PG_ARGISNULL(4))
258 prefix_text = PG_GETARG_TEXT_P(4);
259 if ( VARSIZE(prefix_text) == VARHDRSZ )
265 len = VARSIZE_ANY_EXHDR(prefix_text);
266 prefix_buf = palloc(len + 2);
267 memcpy(prefix_buf, VARDATA(prefix_text), len);
269 prefix_buf[len] =
':';
270 prefix_buf[len+1] =
'\0';
275 if (PG_NARGS() >5 && !PG_ARGISNULL(5))
277 gml_id_text = PG_GETARG_TEXT_P(5);
278 if ( VARSIZE(gml_id_text) == VARHDRSZ )
284 len = VARSIZE_ANY_EXHDR(gml_id_text);
285 gml_id_buf = palloc(len+1);
286 memcpy(gml_id_buf, VARDATA(gml_id_text), len);
287 gml_id_buf[len] =
'\0';
304 "Options %d passed to ST_AsGML(geography) sets "
305 "unsupported value 8",
329 lwgeom, srs,
precision, lwopts, prefix, gml_id);
333 PG_FREE_IF_COPY(geom, 1);
339 result = cstring_to_text(gml);
341 PG_RETURN_TEXT_P(result);
int32_t gserialized_get_srid(const GSERIALIZED *g)
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, int32_t srid, bool short_crs)