PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ parse_kml_polygon()

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

Parse KML Polygon.

Definition at line 400 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().

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