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

Parse KML Polygon.

Definition at line 399 of file lwgeom_in_kml.c.

References getPoint4d_p(), is_kml_namespace(), LW_TRUE, lwalloc(), lwpoly_construct(), lwrealloc(), parse_kml_coordinates(), ptarray_append_point(), ptarray_is_closed_2d(), and ptarray_is_closed_3d().

Referenced by parse_kml().

400 {
401  int ring;
402  xmlNodePtr xa, xb;
403  POINTARRAY **ppa = NULL;
404  int outer_rings = 0;
405 
406  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
407  {
408 
409  /* Polygon/outerBoundaryIs */
410  if (xa->type != XML_ELEMENT_NODE) continue;
411  if (!is_kml_namespace(xa, false)) continue;
412  if (strcmp((char *) xa->name, "outerBoundaryIs")) continue;
413 
414  for (xb = xa->children ; xb != NULL ; xb = xb->next)
415  {
416 
417  if (xb->type != XML_ELEMENT_NODE) continue;
418  if (!is_kml_namespace(xb, false)) continue;
419  if (strcmp((char *) xb->name, "LinearRing")) continue;
420 
421  ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
422  ppa[0] = parse_kml_coordinates(xb->children, hasz);
423 
424  if (ppa[0]->npoints < 4)
425  lwpgerror("invalid KML representation");
426 
427  if ((!*hasz && !ptarray_is_closed_2d(ppa[0])) ||
428  ( *hasz && !ptarray_is_closed_3d(ppa[0])))
429  {
430  POINT4D pt;
431  getPoint4d_p(ppa[0], 0, &pt);
432  ptarray_append_point(ppa[0], &pt, LW_TRUE);
433  lwpgnotice("forced closure on an un-closed KML polygon");
434  }
435  outer_rings++;
436  }
437  }
438 
439  if (outer_rings != 1)
440  lwpgerror("invalid KML representation");
441 
442  for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
443  {
444 
445  /* Polygon/innerBoundaryIs */
446  if (xa->type != XML_ELEMENT_NODE) continue;
447  if (!is_kml_namespace(xa, false)) continue;
448  if (strcmp((char *) xa->name, "innerBoundaryIs")) continue;
449 
450  for (xb = xa->children ; xb != NULL ; xb = xb->next)
451  {
452 
453  if (xb->type != XML_ELEMENT_NODE) continue;
454  if (!is_kml_namespace(xb, false)) continue;
455  if (strcmp((char *) xb->name, "LinearRing")) continue;
456 
457  ppa = (POINTARRAY**) lwrealloc(ppa, sizeof(POINTARRAY*) * (ring + 1));
458  ppa[ring] = parse_kml_coordinates(xb->children, hasz);
459 
460  if (ppa[ring]->npoints < 4)
461  lwpgerror("invalid KML representation");
462 
463  if ((!*hasz && !ptarray_is_closed_2d(ppa[ring])) ||
464  ( *hasz && !ptarray_is_closed_3d(ppa[ring])))
465  {
466  POINT4D pt;
467  getPoint4d_p(ppa[ring], 0, &pt);
468  ptarray_append_point(ppa[ring], &pt, LW_TRUE);
469  lwpgnotice("forced closure on an un-closed KML polygon");
470  }
471 
472  ring++;
473  }
474  }
475 
476  /* Exterior Ring is mandatory */
477  if (ppa == NULL || ppa[0] == NULL) lwpgerror("invalid KML representation");
478 
479  return (LWGEOM *) lwpoly_construct(4326, NULL, ring, ppa);
480 }
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:707
static POINTARRAY * parse_kml_coordinates(xmlNodePtr xnode, bool *hasz)
Parse kml:coordinates.
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:694
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, then a duplicate point will not be added.
Definition: ptarray.c:156
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:235
void * lwalloc(size_t size)
Definition: lwutil.c:227
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:244

Here is the call graph for this function:

Here is the caller graph for this function: