PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ parse_kml_polygon()

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

Parse KML Polygon.

Definition at line 421 of file lwgeom_in_kml.c.

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

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: