PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwgeom_from_gml()

static LWGEOM * lwgeom_from_gml ( const char *  wkt)
static

Read GML.

Definition at line 1794 of file lwgeom_in_gml.c.

References gml_lwpgerror(), lwgeom_add_bbox(), lwgeom_force_2d(), lwgeom_free(), parse_gml(), LWGEOM::srid, and SRID_UNKNOWN.

Referenced by geom_from_gml().

1795 {
1796  xmlDocPtr xmldoc;
1797  xmlNodePtr xmlroot=NULL;
1798  int xml_size = strlen(xml);
1799  LWGEOM *lwgeom;
1800  bool hasz=true;
1801  int root_srid=SRID_UNKNOWN;
1802 
1803  /* Begin to Parse XML doc */
1804  xmlInitParser();
1805  xmldoc = xmlReadMemory(xml, xml_size, NULL, NULL, XML_PARSE_SAX1);
1806  if (!xmldoc || (xmlroot = xmlDocGetRootElement(xmldoc)) == NULL)
1807  {
1808  xmlFreeDoc(xmldoc);
1809  xmlCleanupParser();
1810  gml_lwpgerror("invalid GML representation", 1);
1811  }
1812 
1813  lwgeom = parse_gml(xmlroot, &hasz, &root_srid);
1814 
1815  xmlFreeDoc(xmldoc);
1816  xmlCleanupParser();
1817  /* shouldn't we be releasing xmldoc too here ? */
1818 
1819 
1820  if ( root_srid != SRID_UNKNOWN )
1821  lwgeom->srid = root_srid;
1822 
1823  /* Should we really do this here ? */
1824  lwgeom_add_bbox(lwgeom);
1825 
1826  /* GML geometries could be either 2 or 3D and can be nested mixed.
1827  * Missing Z dimension is even tolerated inside some GML coords
1828  *
1829  * So we deal with 3D in all structures allocation, and flag hasz
1830  * to false if we met once a missing Z dimension
1831  * In this case, we force recursive 2D.
1832  */
1833  if (!hasz)
1834  {
1835  LWGEOM *tmp = lwgeom_force_2d(lwgeom);
1836  lwgeom_free(lwgeom);
1837  lwgeom = tmp;
1838  }
1839 
1840  return lwgeom;
1841 }
static void gml_lwpgerror(char *msg, int error_code)
Definition: lwgeom_in_gml.c:81
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
static LWGEOM * parse_gml(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML.
int32_t srid
Definition: liblwgeom.h:399
#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:739
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:648
Here is the call graph for this function:
Here is the caller graph for this function: