PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ lwgeom_from_gml()

static LWGEOM * lwgeom_from_gml ( const char *  wkt)
static

Read GML.

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

1781 {
1782  xmlDocPtr xmldoc;
1783  xmlNodePtr xmlroot=NULL;
1784  int xml_size = strlen(xml);
1785  LWGEOM *lwgeom;
1786  bool hasz=true;
1787  int root_srid=SRID_UNKNOWN;
1788 
1789  /* Begin to Parse XML doc */
1790  xmlInitParser();
1791  xmldoc = xmlReadMemory(xml, xml_size, NULL, NULL, XML_PARSE_SAX1);
1792  if (!xmldoc || (xmlroot = xmlDocGetRootElement(xmldoc)) == NULL)
1793  {
1794  xmlFreeDoc(xmldoc);
1795  xmlCleanupParser();
1796  gml_lwpgerror("invalid GML representation", 1);
1797  }
1798 
1799  lwgeom = parse_gml(xmlroot, &hasz, &root_srid);
1800 
1801  xmlFreeDoc(xmldoc);
1802  xmlCleanupParser();
1803  /* shouldn't we be releasing xmldoc too here ? */
1804 
1805 
1806  if ( root_srid != SRID_UNKNOWN )
1807  lwgeom->srid = root_srid;
1808 
1809  /* Should we really do this here ? */
1810  lwgeom_add_bbox(lwgeom);
1811 
1812  /* GML geometries could be either 2 or 3D and can be nested mixed.
1813  * Missing Z dimension is even tolerated inside some GML coords
1814  *
1815  * So we deal with 3D in all structures allocation, and flag hasz
1816  * to false if we met once a missing Z dimension
1817  * In this case, we force recursive 2D.
1818  */
1819  if (!hasz)
1820  {
1821  LWGEOM *tmp = lwgeom_force_2d(lwgeom);
1822  lwgeom_free(lwgeom);
1823  lwgeom = tmp;
1824  }
1825 
1826  return lwgeom;
1827 }
static void gml_lwpgerror(char *msg, int error_code)
Definition: lwgeom_in_gml.c:67
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
static LWGEOM * parse_gml(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse GML.
int32_t srid
Definition: liblwgeom.h:383
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:172
LWGEOM * lwgeom_force_2d(const LWGEOM *geom)
Strip out the Z/M components of an LWGEOM.
Definition: lwgeom.c:690
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:599
Here is the call graph for this function:
Here is the caller graph for this function: