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

Read GML.

Definition at line 1785 of file lwgeom_in_gml.c.

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

Referenced by geom_from_gml().

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

Here is the call graph for this function:

Here is the caller graph for this function: