PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ lwgeom_from_gml()

static LWGEOM * lwgeom_from_gml ( const char *  wkt,
int  xml_size 
)
static

Read GML.

Definition at line 1973 of file lwgeom_in_gml.c.

1974 {
1975  xmlDocPtr xmldoc;
1976  xmlNodePtr xmlroot=NULL;
1977  LWGEOM *lwgeom = NULL;
1978  bool hasz=true;
1979  int root_srid=SRID_UNKNOWN;
1980 
1981  /* Begin to Parse XML doc */
1982  xmlInitParser();
1983 
1984  xmldoc = xmlReadMemory(xml, xml_size, NULL, NULL, 0);
1985  if (!xmldoc)
1986  {
1987  xmlCleanupParser();
1988  gml_lwpgerror("invalid GML representation", 1);
1989  return NULL;
1990  }
1991 
1992  xmlroot = xmlDocGetRootElement(xmldoc);
1993  if (!xmlroot)
1994  {
1995  xmlFreeDoc(xmldoc);
1996  xmlCleanupParser();
1997  gml_lwpgerror("invalid GML representation", 1);
1998  return NULL;
1999  }
2000 
2001  lwgeom = parse_gml(xmlroot, &hasz, &root_srid);
2002 
2003  xmlFreeDoc(xmldoc);
2004  xmlCleanupParser();
2005  /* shouldn't we be releasing xmldoc too here ? */
2006 
2007  if ( root_srid != SRID_UNKNOWN )
2008  lwgeom->srid = root_srid;
2009 
2010  /* GML geometries could be either 2 or 3D and can be nested mixed.
2011  * Missing Z dimension is even tolerated inside some GML coords
2012  *
2013  * So we deal with 3D in all structures allocation, and flag hasz
2014  * to false if we met once a missing Z dimension
2015  * In this case, we force recursive 2D.
2016  */
2017  if (!hasz)
2018  {
2019  LWGEOM *tmp = lwgeom_force_2d(lwgeom);
2020  lwgeom_free(lwgeom);
2021  lwgeom = tmp;
2022  }
2023 
2024  return lwgeom;
2025 }
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:229
LWGEOM * lwgeom_force_2d(const LWGEOM *geom)
Strip out the Z/M components of an LWGEOM.
Definition: lwgeom.c:776
static LWGEOM * parse_gml(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML.
static void gml_lwpgerror(char *msg, __attribute__((__unused__)) int error_code)
Definition: lwgeom_in_gml.c:81
int32_t srid
Definition: liblwgeom.h:474

References gml_lwpgerror(), lwgeom_force_2d(), lwgeom_free(), parse_gml(), LWGEOM::srid, and SRID_UNKNOWN.

Referenced by geom_from_gml().

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