95{
98 xmlDocPtr xmldoc;
99 text *xml_input;
100 int xml_size;
101 char *xml;
102 bool hasz=true;
103 xmlNodePtr xmlroot=NULL;
104
105
106 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
107 xml_input = PG_GETARG_TEXT_P(0);
108 xml = text_to_cstring(xml_input);
109 xml_size = VARSIZE_ANY_EXHDR(xml_input);
110
111
112 xmlInitParser();
113 xmldoc = xmlReadMemory(xml, xml_size, NULL, NULL, 0);
114 if (!xmldoc || (xmlroot = xmlDocGetRootElement(xmldoc)) == NULL)
115 {
116 xmlFreeDoc(xmldoc);
117 xmlCleanupParser();
118 lwpgerror("invalid KML representation");
119 }
120
122
123
125 {
128 lwgeom = hlwgeom;
129 }
130
131
132
133
134
135
136
137 if (!hasz)
138 {
141 lwgeom = tmp;
142 }
143
144 geom = geometry_serialize(lwgeom);
146
147 xmlFreeDoc(xmldoc);
148 xmlCleanupParser();
149
150 PG_RETURN_POINTER(geom);
151}
void lwgeom_free(LWGEOM *geom)
LWGEOM * lwgeom_force_2d(const LWGEOM *geom)
Strip out the Z/M components of an LWGEOM.
LWGEOM * lwgeom_homogenize(const LWGEOM *geom)
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
static LWGEOM * parse_kml(xmlNodePtr xnode, bool *hasz)
Parse KML.