200 static const char* default_prefix =
"gml:";
201 const char* prefix = default_prefix;
202 const char* gml_id = NULL;
204 char *gml_id_buf, *prefix_buf;
205 text *prefix_text, *gml_id_text;
209 version = PG_GETARG_INT32(0);
210 if ( version != 2 && version != 3 )
212 elog(ERROR,
"Only GML 2 and GML 3 are supported");
217 if ( PG_ARGISNULL(1) ) PG_RETURN_NULL();
218 geom = PG_GETARG_GSERIALIZED_P(1);
221 if (PG_NARGS() >2 && !PG_ARGISNULL(2))
223 precision = PG_GETARG_INT32(2);
225 if ( precision > DBL_DIG )
227 else if ( precision < 0 ) precision = 0;
231 if (PG_NARGS() >3 && !PG_ARGISNULL(3))
232 option = PG_GETARG_INT32(3);
235 if (PG_NARGS() >4 && !PG_ARGISNULL(4))
237 prefix_text = PG_GETARG_TEXT_P(4);
238 if ( VARSIZE(prefix_text) == VARHDRSZ )
244 len = VARSIZE(prefix_text)-VARHDRSZ;
245 prefix_buf = palloc(len + 2);
246 memcpy(prefix_buf, VARDATA(prefix_text), len);
248 prefix_buf[len] =
':';
249 prefix_buf[len+1] =
'\0';
254 if (PG_NARGS() >5 && !PG_ARGISNULL(5))
256 gml_id_text = PG_GETARG_TEXT_P(5);
257 if ( VARSIZE(gml_id_text) == VARHDRSZ )
263 len = VARSIZE(gml_id_text)-VARHDRSZ;
264 gml_id_buf = palloc(len+1);
265 memcpy(gml_id_buf, VARDATA(gml_id_text), len);
266 gml_id_buf[len] =
'\0';
285 else if (version == 2)
287 else if (version == 3 && lwopts & LW_GML_EXTENT)
289 else if (version == 3)
290 gml =
lwgeom_to_gml3(lwgeom, srs, precision, lwopts, prefix, gml_id);
293 PG_FREE_IF_COPY(geom, 1);
299 result = cstring2text(gml);
301 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.
#define LW_GML_SHORTLINE
For GML3, use <LineString> rather than <Curve> for lines.
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
#define SRID_UNKNOWN
Unknown SRID value.
#define LW_GML_EXTENT
For GML2 and GML3, output only extent of geometry.
char * lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
char * lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix)
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)
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)...
#define LW_GML_IS_DEGREE
For GML3 only, declare that datas are lat/lon.