PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lwgeom_from_gml()

static LWGEOM * lwgeom_from_gml ( const char *  wkt)
static

Read GML.

Definition at line 1810 of file lwgeom_in_gml.c.

1811 {
1812  xmlDocPtr xmldoc;
1813  xmlNodePtr xmlroot=NULL;
1814  int xml_size = strlen(xml);
1815  LWGEOM *lwgeom;
1816  bool hasz=true;
1817  int root_srid=SRID_UNKNOWN;
1818 
1819  /* Begin to Parse XML doc */
1820  xmlInitParser();
1821  xmldoc = xmlReadMemory(xml, xml_size, NULL, NULL, XML_PARSE_SAX1);
1822  if (!xmldoc || (xmlroot = xmlDocGetRootElement(xmldoc)) == NULL)
1823  {
1824  xmlFreeDoc(xmldoc);
1825  xmlCleanupParser();
1826  gml_lwpgerror("invalid GML representation", 1);
1827  }
1828 
1829  lwgeom = parse_gml(xmlroot, &hasz, &root_srid);
1830 
1831  xmlFreeDoc(xmldoc);
1832  xmlCleanupParser();
1833  /* shouldn't we be releasing xmldoc too here ? */
1834 
1835 
1836  if ( root_srid != SRID_UNKNOWN )
1837  lwgeom->srid = root_srid;
1838 
1839  /* GML geometries could be either 2 or 3D and can be nested mixed.
1840  * Missing Z dimension is even tolerated inside some GML coords
1841  *
1842  * So we deal with 3D in all structures allocation, and flag hasz
1843  * to false if we met once a missing Z dimension
1844  * In this case, we force recursive 2D.
1845  */
1846  if (!hasz)
1847  {
1848  LWGEOM *tmp = lwgeom_force_2d(lwgeom);
1849  lwgeom_free(lwgeom);
1850  lwgeom = tmp;
1851  }
1852 
1853  return lwgeom;
1854 }
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
LWGEOM * lwgeom_force_2d(const LWGEOM *geom)
Strip out the Z/M components of an LWGEOM.
Definition: lwgeom.c:784
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:402

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: