PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ parse_kml_polygon()

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

Parse KML Polygon.

Definition at line 417 of file lwgeom_in_kml.c.

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