PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ parse_kml_polygon()

static LWGEOM* parse_kml_polygon ( xmlNodePtr  xnode,
bool *  hasz 
)
static

Parse KML Polygon.

Definition at line 416 of file lwgeom_in_kml.c.

417 {
418  int ring;
419  xmlNodePtr xa, xb;
420  POINTARRAY **ppa = NULL;
421  int outer_rings = 0;
422 
423  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
424  {
425 
426  /* Polygon/outerBoundaryIs */
427  if (xa->type != XML_ELEMENT_NODE) continue;
428  if (!is_kml_namespace(xa, false)) continue;
429  if (!is_kml_element(xa, "outerBoundaryIs")) continue;
430 
431  for (xb = xa->children ; xb != NULL ; xb = xb->next)
432  {
433 
434  if (xb->type != XML_ELEMENT_NODE) continue;
435  if (!is_kml_namespace(xb, false)) continue;
436  if (!is_kml_element(xb, "LinearRing")) continue;
437 
438  ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
439  ppa[0] = parse_kml_coordinates(xb->children, hasz);
440 
441  if (ppa[0]->npoints < 4)
442  lwpgerror("invalid KML representation");
443 
444  if ((!*hasz && !ptarray_is_closed_2d(ppa[0])) ||
445  ( *hasz && !ptarray_is_closed_3d(ppa[0])))
446  {
447  POINT4D pt;
448  getPoint4d_p(ppa[0], 0, &pt);
449  ptarray_append_point(ppa[0], &pt, LW_TRUE);
450  lwpgnotice("forced closure on an un-closed KML polygon");
451  }
452  outer_rings++;
453  }
454  }
455 
456  if (outer_rings != 1)
457  lwpgerror("invalid KML representation");
458 
459  for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
460  {
461 
462  /* Polygon/innerBoundaryIs */
463  if (xa->type != XML_ELEMENT_NODE) continue;
464  if (!is_kml_namespace(xa, false)) continue;
465  if (!is_kml_element(xa, "innerBoundaryIs")) continue;
466 
467  for (xb = xa->children ; xb != NULL ; xb = xb->next)
468  {
469 
470  if (xb->type != XML_ELEMENT_NODE) continue;
471  if (!is_kml_namespace(xb, false)) continue;
472  if (!is_kml_element(xb, "LinearRing")) continue;
473 
474  ppa = (POINTARRAY**) lwrealloc(ppa, sizeof(POINTARRAY*) * (ring + 1));
475  ppa[ring] = parse_kml_coordinates(xb->children, hasz);
476 
477  if (ppa[ring]->npoints < 4)
478  lwpgerror("invalid KML representation");
479 
480  if ((!*hasz && !ptarray_is_closed_2d(ppa[ring])) ||
481  ( *hasz && !ptarray_is_closed_3d(ppa[ring])))
482  {
483  POINT4D pt;
484  getPoint4d_p(ppa[ring], 0, &pt);
485  ptarray_append_point(ppa[ring], &pt, LW_TRUE);
486  lwpgnotice("forced closure on an un-closed KML polygon");
487  }
488 
489  ring++;
490  }
491  }
492 
493  /* Exterior Ring is mandatory */
494  if (ppa == NULL || ppa[0] == NULL) lwpgerror("invalid KML representation");
495 
496  return (LWGEOM *) lwpoly_construct(4326, NULL, ring, ppa);
497 }
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:723
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:242
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:125
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,...
Definition: ptarray.c:147
void * lwalloc(size_t size)
Definition: lwutil.c:227
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:710
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
LWPOLY * lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
static POINTARRAY * parse_kml_coordinates(xmlNodePtr xnode, bool *hasz)
Parse kml:coordinates.
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)
Definition: lwgeom_in_kml.c:68

References getPoint4d_p(), is_kml_element(), 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().

Here is the call graph for this function:
Here is the caller graph for this function: