PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ lwgeom_from_gml()

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

Read GML.

Definition at line 1857 of file lwgeom_in_gml.c.

1858 {
1859  xmlDocPtr xmldoc;
1860  xmlNodePtr xmlroot=NULL;
1861  LWGEOM *lwgeom = NULL;
1862  bool hasz=true;
1863  int root_srid=SRID_UNKNOWN;
1864 
1865  /* Begin to Parse XML doc */
1866  xmlInitParser();
1867 
1868  xmldoc = xmlReadMemory(xml, xml_size, NULL, NULL, XML_PARSE_SAX1);
1869  if (!xmldoc)
1870  {
1871  xmlCleanupParser();
1872  gml_lwpgerror("invalid GML representation", 1);
1873  return NULL;
1874  }
1875 
1876  xmlroot = xmlDocGetRootElement(xmldoc);
1877  if (!xmlroot)
1878  {
1879  xmlFreeDoc(xmldoc);
1880  xmlCleanupParser();
1881  gml_lwpgerror("invalid GML representation", 1);
1882  return NULL;
1883  }
1884 
1885  lwgeom = parse_gml(xmlroot, &hasz, &root_srid);
1886 
1887  xmlFreeDoc(xmldoc);
1888  xmlCleanupParser();
1889  /* shouldn't we be releasing xmldoc too here ? */
1890 
1891  if ( root_srid != SRID_UNKNOWN )
1892  lwgeom->srid = root_srid;
1893 
1894  /* GML geometries could be either 2 or 3D and can be nested mixed.
1895  * Missing Z dimension is even tolerated inside some GML coords
1896  *
1897  * So we deal with 3D in all structures allocation, and flag hasz
1898  * to false if we met once a missing Z dimension
1899  * In this case, we force recursive 2D.
1900  */
1901  if (!hasz)
1902  {
1903  LWGEOM *tmp = lwgeom_force_2d(lwgeom);
1904  lwgeom_free(lwgeom);
1905  lwgeom = tmp;
1906  }
1907 
1908  return lwgeom;
1909 }
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1155
#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: