PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ lwgeom_from_gml()

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

Read GML.

Definition at line 1925 of file lwgeom_in_gml.c.

1926 {
1927  xmlDocPtr xmldoc;
1928  xmlNodePtr xmlroot=NULL;
1929  LWGEOM *lwgeom = NULL;
1930  bool hasz=true;
1931  int root_srid=SRID_UNKNOWN;
1932 
1933  /* Begin to Parse XML doc */
1934  xmlInitParser();
1935 
1936  xmldoc = xmlReadMemory(xml, xml_size, NULL, NULL, 0);
1937  if (!xmldoc)
1938  {
1939  xmlCleanupParser();
1940  gml_lwpgerror("invalid GML representation", 1);
1941  return NULL;
1942  }
1943 
1944  xmlroot = xmlDocGetRootElement(xmldoc);
1945  if (!xmlroot)
1946  {
1947  xmlFreeDoc(xmldoc);
1948  xmlCleanupParser();
1949  gml_lwpgerror("invalid GML representation", 1);
1950  return NULL;
1951  }
1952 
1953  lwgeom = parse_gml(xmlroot, &hasz, &root_srid);
1954 
1955  xmlFreeDoc(xmldoc);
1956  xmlCleanupParser();
1957  /* shouldn't we be releasing xmldoc too here ? */
1958 
1959  if ( root_srid != SRID_UNKNOWN )
1960  lwgeom->srid = root_srid;
1961 
1962  /* GML geometries could be either 2 or 3D and can be nested mixed.
1963  * Missing Z dimension is even tolerated inside some GML coords
1964  *
1965  * So we deal with 3D in all structures allocation, and flag hasz
1966  * to false if we met once a missing Z dimension
1967  * In this case, we force recursive 2D.
1968  */
1969  if (!hasz)
1970  {
1971  LWGEOM *tmp = lwgeom_force_2d(lwgeom);
1972  lwgeom_free(lwgeom);
1973  lwgeom = tmp;
1974  }
1975 
1976  return lwgeom;
1977 }
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1218
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:215
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:460

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: