PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ parse_kml_polygon()

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

Parse KML Polygon.

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

387 {
388  int ring;
389  xmlNodePtr xa, xb;
390  POINTARRAY **ppa = NULL;
391  int outer_rings = 0;
392 
393  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
394  {
395 
396  /* Polygon/outerBoundaryIs */
397  if (xa->type != XML_ELEMENT_NODE) continue;
398  if (!is_kml_namespace(xa, false)) continue;
399  if (strcmp((char *) xa->name, "outerBoundaryIs")) continue;
400 
401  for (xb = xa->children ; xb != NULL ; xb = xb->next)
402  {
403 
404  if (xb->type != XML_ELEMENT_NODE) continue;
405  if (!is_kml_namespace(xb, false)) continue;
406  if (strcmp((char *) xb->name, "LinearRing")) continue;
407 
408  ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
409  ppa[0] = parse_kml_coordinates(xb->children, hasz);
410 
411  if (ppa[0]->npoints < 4)
412  lwpgerror("invalid KML representation");
413 
414  if ((!*hasz && !ptarray_is_closed_2d(ppa[0])) ||
415  ( *hasz && !ptarray_is_closed_3d(ppa[0])))
416  {
417  POINT4D pt;
418  getPoint4d_p(ppa[0], 0, &pt);
419  ptarray_append_point(ppa[0], &pt, LW_TRUE);
420  lwpgnotice("forced closure on an un-closed KML polygon");
421  }
422  outer_rings++;
423  }
424  }
425 
426  if (outer_rings != 1)
427  lwpgerror("invalid KML representation");
428 
429  for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
430  {
431 
432  /* Polygon/innerBoundaryIs */
433  if (xa->type != XML_ELEMENT_NODE) continue;
434  if (!is_kml_namespace(xa, false)) continue;
435  if (strcmp((char *) xa->name, "innerBoundaryIs")) continue;
436 
437  for (xb = xa->children ; xb != NULL ; xb = xb->next)
438  {
439 
440  if (xb->type != XML_ELEMENT_NODE) continue;
441  if (!is_kml_namespace(xb, false)) continue;
442  if (strcmp((char *) xb->name, "LinearRing")) continue;
443 
444  ppa = (POINTARRAY**) lwrealloc(ppa, sizeof(POINTARRAY*) * (ring + 1));
445  ppa[ring] = parse_kml_coordinates(xb->children, hasz);
446 
447  if (ppa[ring]->npoints < 4)
448  lwpgerror("invalid KML representation");
449 
450  if ((!*hasz && !ptarray_is_closed_2d(ppa[ring])) ||
451  ( *hasz && !ptarray_is_closed_3d(ppa[ring])))
452  {
453  POINT4D pt;
454  getPoint4d_p(ppa[ring], 0, &pt);
455  ptarray_append_point(ppa[ring], &pt, LW_TRUE);
456  lwpgnotice("forced closure on an un-closed KML polygon");
457  }
458 
459  ring++;
460  }
461  }
462 
463  /* Exterior Ring is mandatory */
464  if (ppa == NULL || ppa[0] == NULL) lwpgerror("invalid KML representation");
465 
466  return (LWGEOM *) lwpoly_construct(4326, NULL, ring, ppa);
467 }
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:707
static POINTARRAY * parse_kml_coordinates(xmlNodePtr xnode, bool *hasz)
Parse kml:coordinates.
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:694
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_TRUE, 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:29
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:61
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:207
void * lwalloc(size_t size)
Definition: lwutil.c:199
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:231
Here is the call graph for this function:
Here is the caller graph for this function: