PostGIS  2.5.0dev-r@@SVN_REVISION@@
static LWGEOM * lwgeom_from_gml ( const char *  wkt)
static

Read GML.

Definition at line 1793 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().

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

Here is the call graph for this function:

Here is the caller graph for this function: