PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ parse_kml_polygon()

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

Parse KML Polygon.

Definition at line 394 of file lwgeom_in_kml.c.

395 {
396  int ring;
397  xmlNodePtr xa, xb;
398  POINTARRAY **ppa = NULL;
399  int outer_rings = 0;
400 
401  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
402  {
403 
404  /* Polygon/outerBoundaryIs */
405  if (xa->type != XML_ELEMENT_NODE) continue;
406  if (!is_kml_namespace(xa, false)) continue;
407  if (strcmp((char *) xa->name, "outerBoundaryIs")) continue;
408 
409  for (xb = xa->children ; xb != NULL ; xb = xb->next)
410  {
411 
412  if (xb->type != XML_ELEMENT_NODE) continue;
413  if (!is_kml_namespace(xb, false)) continue;
414  if (strcmp((char *) xb->name, "LinearRing")) continue;
415 
416  ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
417  ppa[0] = parse_kml_coordinates(xb->children, hasz);
418 
419  if (ppa[0]->npoints < 4)
420  lwpgerror("invalid KML representation");
421 
422  if ((!*hasz && !ptarray_is_closed_2d(ppa[0])) ||
423  ( *hasz && !ptarray_is_closed_3d(ppa[0])))
424  {
425  POINT4D pt;
426  getPoint4d_p(ppa[0], 0, &pt);
427  ptarray_append_point(ppa[0], &pt, LW_TRUE);
428  lwpgnotice("forced closure on an un-closed KML polygon");
429  }
430  outer_rings++;
431  }
432  }
433 
434  if (outer_rings != 1)
435  lwpgerror("invalid KML representation");
436 
437  for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
438  {
439 
440  /* Polygon/innerBoundaryIs */
441  if (xa->type != XML_ELEMENT_NODE) continue;
442  if (!is_kml_namespace(xa, false)) continue;
443  if (strcmp((char *) xa->name, "innerBoundaryIs")) continue;
444 
445  for (xb = xa->children ; xb != NULL ; xb = xb->next)
446  {
447 
448  if (xb->type != XML_ELEMENT_NODE) continue;
449  if (!is_kml_namespace(xb, false)) continue;
450  if (strcmp((char *) xb->name, "LinearRing")) continue;
451 
452  ppa = (POINTARRAY**) lwrealloc(ppa, sizeof(POINTARRAY*) * (ring + 1));
453  ppa[ring] = parse_kml_coordinates(xb->children, hasz);
454 
455  if (ppa[ring]->npoints < 4)
456  lwpgerror("invalid KML representation");
457 
458  if ((!*hasz && !ptarray_is_closed_2d(ppa[ring])) ||
459  ( *hasz && !ptarray_is_closed_3d(ppa[ring])))
460  {
461  POINT4D pt;
462  getPoint4d_p(ppa[ring], 0, &pt);
463  ptarray_append_point(ppa[ring], &pt, LW_TRUE);
464  lwpgnotice("forced closure on an un-closed KML polygon");
465  }
466 
467  ring++;
468  }
469  }
470 
471  /* Exterior Ring is mandatory */
472  if (ppa == NULL || ppa[0] == NULL) lwpgerror("invalid KML representation");
473 
474  return (LWGEOM *) lwpoly_construct(4326, NULL, ring, ppa);
475 }
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:727
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:714
#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.

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().

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