PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ lwgeom_to_gml2()

lwvarlena_t* lwgeom_to_gml2 ( const LWGEOM geom,
const char *  srs,
int  precision,
const char *  prefix 
)

Definition at line 920 of file lwout_gml.c.

921 {
922  stringbuffer_t sb;
923 
924  /* Initialize options */
925  GML_Options gmlopts;
926  memset(&gmlopts, 0, sizeof(gmlopts));
927  gmlopts.srs = srs;
928  gmlopts.precision = precision;
929  gmlopts.prefix = prefix;
930 
931  /* Return null for empty (#1377) */
932  if (lwgeom_is_empty(geom))
933  return NULL;
934 
936 
937  switch (geom->type)
938  {
939  case POINTTYPE:
940  asgml2_point(&sb, (LWPOINT*)geom, &gmlopts);
941  break;
942 
943  case LINETYPE:
944  asgml2_line(&sb, (LWLINE*)geom, &gmlopts);
945  break;
946 
947  case POLYGONTYPE:
948  asgml2_poly(&sb, (LWPOLY*)geom, &gmlopts);
949  break;
950 
951  case MULTIPOINTTYPE:
952  case MULTILINETYPE:
953  case MULTIPOLYGONTYPE:
954  asgml2_multi(&sb, (LWCOLLECTION*)geom, &gmlopts);
955  break;
956 
957  case COLLECTIONTYPE:
958  asgml2_collection(&sb, (LWCOLLECTION*)geom, &gmlopts);
959  break;
960 
961  case TRIANGLETYPE:
963  case TINTYPE:
964  lwerror("Cannot convert %s to GML2. Try ST_AsGML(3, <geometry>) to generate GML3.", lwtype_name(geom->type));
966  return NULL;
967 
968  default:
969  lwerror("lwgeom_to_gml2: '%s' geometry type not supported", lwtype_name(geom->type));
971  return NULL;
972  }
973 
974  return stringbuffer_getvarlena(&sb);
975 }
static uint8_t precision
Definition: cu_in_twkb.c:25
#define COLLECTIONTYPE
Definition: liblwgeom.h:108
#define MULTILINETYPE
Definition: liblwgeom.h:106
#define LINETYPE
Definition: liblwgeom.h:103
#define MULTIPOINTTYPE
Definition: liblwgeom.h:105
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:102
#define TINTYPE
Definition: liblwgeom.h:116
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:107
#define POLYGONTYPE
Definition: liblwgeom.h:104
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:114
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:216
#define TRIANGLETYPE
Definition: liblwgeom.h:115
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwinline.h:203
static void asgml2_point(stringbuffer_t *sb, const LWPOINT *point, const GML_Options *opts)
Definition: lwout_gml.c:203
static void asgml2_poly(stringbuffer_t *sb, const LWPOLY *poly, const GML_Options *opts)
Definition: lwout_gml.c:240
static void asgml2_collection(stringbuffer_t *sb, const LWCOLLECTION *col, const GML_Options *opts)
Definition: lwout_gml.c:326
static void asgml2_line(stringbuffer_t *sb, const LWLINE *line, const GML_Options *opts)
Definition: lwout_gml.c:221
static void asgml2_multi(stringbuffer_t *sb, const LWCOLLECTION *col, const GML_Options *opts)
Definition: lwout_gml.c:273
void stringbuffer_release(stringbuffer_t *s)
Definition: stringbuffer.c:48
lwvarlena_t * stringbuffer_getvarlena(stringbuffer_t *s)
Definition: stringbuffer.c:143
void stringbuffer_init_varlena(stringbuffer_t *s)
Definition: stringbuffer.c:60
const char * srs
Definition: lwout_gml.c:41
int precision
Definition: lwout_gml.c:42
const char * prefix
Definition: lwout_gml.c:45
uint8_t type
Definition: liblwgeom.h:462

References asgml2_collection(), asgml2_line(), asgml2_multi(), asgml2_point(), asgml2_poly(), COLLECTIONTYPE, LINETYPE, lwerror(), lwgeom_is_empty(), lwtype_name(), MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, POINTTYPE, POLYGONTYPE, POLYHEDRALSURFACETYPE, precision, GML_Options::precision, GML_Options::prefix, GML_Options::srs, stringbuffer_getvarlena(), stringbuffer_init_varlena(), stringbuffer_release(), TINTYPE, TRIANGLETYPE, LWGEOM::type, and LWPOINT::type.

Referenced by do_gml2_test(), do_gml2_test_prefix(), do_gml2_unsupported(), geography_as_gml(), and LWGEOM_asGML().

Here is the call graph for this function:
Here is the caller graph for this function: