PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ lwgeom_from_gml()

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

Read GML.

Definition at line 1890 of file lwgeom_in_gml.c.

1891 {
1892  xmlDocPtr xmldoc;
1893  xmlNodePtr xmlroot=NULL;
1894  LWGEOM *lwgeom = NULL;
1895  bool hasz=true;
1896  int root_srid=SRID_UNKNOWN;
1897 
1898  /* Begin to Parse XML doc */
1899  xmlInitParser();
1900 
1901  xmldoc = xmlReadMemory(xml, xml_size, NULL, NULL, 0);
1902  if (!xmldoc)
1903  {
1904  xmlCleanupParser();
1905  gml_lwpgerror("invalid GML representation", 1);
1906  return NULL;
1907  }
1908 
1909  xmlroot = xmlDocGetRootElement(xmldoc);
1910  if (!xmlroot)
1911  {
1912  xmlFreeDoc(xmldoc);
1913  xmlCleanupParser();
1914  gml_lwpgerror("invalid GML representation", 1);
1915  return NULL;
1916  }
1917 
1918  lwgeom = parse_gml(xmlroot, &hasz, &root_srid);
1919 
1920  xmlFreeDoc(xmldoc);
1921  xmlCleanupParser();
1922  /* shouldn't we be releasing xmldoc too here ? */
1923 
1924  if ( root_srid != SRID_UNKNOWN )
1925  lwgeom->srid = root_srid;
1926 
1927  /* GML geometries could be either 2 or 3D and can be nested mixed.
1928  * Missing Z dimension is even tolerated inside some GML coords
1929  *
1930  * So we deal with 3D in all structures allocation, and flag hasz
1931  * to false if we met once a missing Z dimension
1932  * In this case, we force recursive 2D.
1933  */
1934  if (!hasz)
1935  {
1936  LWGEOM *tmp = lwgeom_force_2d(lwgeom);
1937  lwgeom_free(lwgeom);
1938  lwgeom = tmp;
1939  }
1940 
1941  return lwgeom;
1942 }
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:775
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:82
int32_t srid
Definition: liblwgeom.h:446

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: