PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ lwgeom_from_gml()

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

Read GML.

Definition at line 1968 of file lwgeom_in_gml.c.

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

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: