Parse kml:coordinates.
297{
298 xmlChar *kml_coord;
299 bool found;
301 int seen_kml_dims = 0;
302 int kml_dims;
303 char *p, *q;
305 double d;
306
307 if (xnode == NULL) lwpgerror("invalid KML representation");
308
309 for (found = false ; xnode != NULL ; xnode = xnode->next)
310 {
311 if (xnode->type != XML_ELEMENT_NODE) continue;
314
315 found = true;
316 break;
317 }
318 if (!found) lwpgerror("invalid KML representation");
319
320
321 kml_coord = xmlNodeGetContent(xnode);
322 p = (char *) kml_coord;
323
324
325
326
327
328
329
331
332 while (*p && isspace(*p)) ++p;
333 for (kml_dims=0; *p ; p++)
334 {
335
336 if ( isdigit(*p) || *p == '+' || *p == '-' || *p == '.' ) {
337 kml_dims++;
338 errno = 0; d = strtod(p, &q);
339 if ( errno != 0 ) {
340
341 lwpgerror("invalid KML representation");
342 }
343 if (kml_dims == 1) pt.
x = d;
344 else if (kml_dims == 2) pt.
y = d;
345 else if (kml_dims == 3) pt.
z = d;
346 else {
347 lwpgerror("invalid KML representation");
348
349 }
350
351
352
353 if ( *q && ! isspace(*q) && *q != ',' ) {
354 lwpgerror("invalid KML representation");
355 }
356
357
358 while (*q && isspace(*q)) ++q;
359 if ( isdigit(*q) || *q == '+' || *q == '-' || *q == '.' || ! *q ) {
360 if ( kml_dims < 2 ) lwpgerror("invalid KML representation");
361 else if ( kml_dims < 3 ) *hasz = false;
362 if ( ! seen_kml_dims ) seen_kml_dims = kml_dims;
363 else if ( seen_kml_dims != kml_dims ) {
364 lwpgerror("invalid KML representation: mixed coordinates dimension");
365 }
367 kml_dims = 0;
368 }
369 p = q-1;
370
371 } else if ( *p != ',' && ! isspace(*p) ) {
372 lwpgerror("invalid KML representation");
373 }
374 }
375
376 xmlFree(kml_coord);
377
378
380}
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE,...
#define LW_TRUE
Return types for functions with status returns.
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)
static bool is_kml_namespace(xmlNodePtr xnode, bool is_strict)
Return false if current element namespace is not a KML one Return true otherwise.
static bool is_kml_element(xmlNodePtr xn, const char *kml_name)