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))
248 precision = PG_GETARG_INT32(2);
250 if ( precision > DBL_DIG )
252 else if ( precision < 0 ) precision = 0;
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';
302 elog(ERROR,
"SRID %d unknown in spatial_ref_sys table",
SRID_DEFAULT);
316 PG_FREE_IF_COPY(g, 1);
323 result = cstring2text(gml);
326 PG_RETURN_TEXT_P(result);
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.
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
char * getSRSbySRID(int srid, bool short_crs)
#define LW_GML_IS_DIMS
Macros for specifying GML options.
char * lwgeom_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix, const char *id)
#define LW_GML_IS_DEGREE
For GML3 only, declare that datas are lat/lon.