Parse kml:coordinates.
302{
303 xmlChar *kml_coord;
304 bool found;
306 int seen_kml_dims = 0;
307 int kml_dims;
308 char *p, *q;
310 double d;
311
312 if (xnode == NULL) lwpgerror("invalid KML representation");
313
314 for (found = false ; xnode != NULL ; xnode = xnode->next)
315 {
316 if (xnode->type != XML_ELEMENT_NODE) continue;
319
320 found = true;
321 break;
322 }
323 if (!found) lwpgerror("invalid KML representation");
324
325
326 kml_coord = xmlNodeGetContent(xnode);
327 p = (char *) kml_coord;
328
329
330
331
332
333
334
336
337 while (*p && isspace(*p)) ++p;
338 for (kml_dims=0; *p ; p++)
339 {
340
341 if ( isdigit(*p) || *p == '+' || *p == '-' || *p == '.' ) {
342 kml_dims++;
343 errno = 0; d = strtod(p, &q);
344 if ( errno != 0 ) {
345
346 lwpgerror("invalid KML representation");
347 }
348 if (kml_dims == 1) pt.
x = d;
349 else if (kml_dims == 2) pt.
y = d;
350 else if (kml_dims == 3) pt.
z = d;
351 else {
352 lwpgerror("invalid KML representation");
353
354 }
355
356
357
358 if ( *q && ! isspace(*q) && *q != ',' ) {
359 lwpgerror("invalid KML representation");
360 }
361
362
363 while (*q && isspace(*q)) ++q;
364 if ( isdigit(*q) || *q == '+' || *q == '-' || *q == '.' || ! *q ) {
365 if ( kml_dims < 2 ) lwpgerror("invalid KML representation");
366 else if ( kml_dims < 3 ) *hasz = false;
367 if ( ! seen_kml_dims ) seen_kml_dims = kml_dims;
368 else if ( seen_kml_dims != kml_dims ) {
369 lwpgerror("invalid KML representation: mixed coordinates dimension");
370 }
372 kml_dims = 0;
373 }
374 p = q-1;
375
376 } else if ( *p != ',' && ! isspace(*p) ) {
377 lwpgerror("invalid KML representation");
378 }
379 }
380
381 xmlFree(kml_coord);
382
383
385}
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)