PostGIS  2.1.10dev-r@@SVN_REVISION@@
static LWGEOM* parse_kml_polygon ( xmlNodePtr  xnode,
bool *  hasz 
)
static

Parse KML Polygon.

Definition at line 382 of file lwgeom_in_kml.c.

References is_kml_namespace(), lwalloc(), lwerror(), lwpoly_construct(), lwrealloc(), parse_kml_coordinates(), ptarray_is_closed_2d(), and ptarray_is_closed_3d().

Referenced by parse_kml().

383 {
384  int ring;
385  xmlNodePtr xa, xb;
386  POINTARRAY **ppa = NULL;
387  int outer_rings = 0;
388 
389  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
390  {
391 
392  /* Polygon/outerBoundaryIs */
393  if (xa->type != XML_ELEMENT_NODE) continue;
394  if (!is_kml_namespace(xa, false)) continue;
395  if (strcmp((char *) xa->name, "outerBoundaryIs")) continue;
396 
397  for (xb = xa->children ; xb != NULL ; xb = xb->next)
398  {
399 
400  if (xb->type != XML_ELEMENT_NODE) continue;
401  if (!is_kml_namespace(xb, false)) continue;
402  if (strcmp((char *) xb->name, "LinearRing")) continue;
403 
404  ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
405  ppa[0] = parse_kml_coordinates(xb->children, hasz);
406 
407  if (ppa[0]->npoints < 4
408  || (!*hasz && !ptarray_is_closed_2d(ppa[0]))
409  || (*hasz && !ptarray_is_closed_3d(ppa[0])))
410  lwerror("invalid KML representation");
411 
412  outer_rings++;
413  }
414  }
415 
416  if (outer_rings != 1)
417  lwerror("invalid KML representation");
418 
419  for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
420  {
421 
422  /* Polygon/innerBoundaryIs */
423  if (xa->type != XML_ELEMENT_NODE) continue;
424  if (!is_kml_namespace(xa, false)) continue;
425  if (strcmp((char *) xa->name, "innerBoundaryIs")) continue;
426 
427  for (xb = xa->children ; xb != NULL ; xb = xb->next)
428  {
429 
430  if (xb->type != XML_ELEMENT_NODE) continue;
431  if (!is_kml_namespace(xb, false)) continue;
432  if (strcmp((char *) xb->name, "LinearRing")) continue;
433 
434  ppa = (POINTARRAY**) lwrealloc(ppa, sizeof(POINTARRAY*) * (ring + 1));
435  ppa[ring] = parse_kml_coordinates(xb->children, hasz);
436 
437  if (ppa[ring]->npoints < 4
438  || (!*hasz && !ptarray_is_closed_2d(ppa[ring]))
439  || (*hasz && !ptarray_is_closed_3d(ppa[ring])))
440  lwerror("invalid KML representation");
441 
442  ring++;
443  }
444  }
445 
446  /* Exterior Ring is mandatory */
447  if (ppa == NULL || ppa[0] == NULL) lwerror("invalid KML representation");
448 
449  return (LWGEOM *) lwpoly_construct(4326, NULL, ring, ppa);
450 }
static bool is_kml_namespace(xmlNodePtr xnode, bool is_strict)
Return false if current element namespace is not a KML one Return true otherwise. ...
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:678
static POINTARRAY * parse_kml_coordinates(xmlNodePtr xnode, bool *hasz)
Parse kml:coordinates.
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:672
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:29
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:183
void * lwalloc(size_t size)
Definition: lwutil.c:175

Here is the call graph for this function:

Here is the caller graph for this function: