PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ parse_gml_patch()

static LWGEOM* parse_gml_patch ( xmlNodePtr  xnode,
bool *  hasz,
int *  root_srid 
)
static

Parse GML PolygonPatch (3.1.1)

Definition at line 1448 of file lwgeom_in_gml.c.

1449 {
1450  xmlChar *interpolation=NULL;
1451  POINTARRAY **ppa=NULL;
1452  LWGEOM *geom=NULL;
1453  xmlNodePtr xa, xb;
1454  int i, ring=0;
1455  gmlSrs srs;
1456 
1457  /* PolygonPatch */
1458  if (!is_gml_element(xnode, "PolygonPatch"))
1459  gml_lwpgerror("invalid GML representation", 48);
1460 
1461  /* GML SF is restricted to planar interpolation */
1462  interpolation = gmlGetProp(xnode, "interpolation");
1463  if (interpolation != NULL)
1464  {
1465  if (strcmp((char *) interpolation, "planar"))
1466  gml_lwpgerror("invalid GML representation", 48);
1467  xmlFree(interpolation);
1468  }
1469 
1470  parse_gml_srs(xnode, &srs);
1471 
1472  /* PolygonPatch/exterior */
1473  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1474  {
1475  if (!is_gml_namespace(xa, false)) continue;
1476  if (!is_gml_element(xa, "exterior")) continue;
1477 
1478  /* PolygonPatch/exterior/LinearRing */
1479  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1480  {
1481  if (xb->type != XML_ELEMENT_NODE) continue;
1482  if (!is_gml_namespace(xb, false)) continue;
1483  if (!is_gml_element(xb, "LinearRing")) continue;
1484 
1485  ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
1486  ppa[0] = parse_gml_data(xb->children, hasz, root_srid);
1487 
1488  if (ppa[0]->npoints < 4
1489  || (!*hasz && !ptarray_is_closed_2d(ppa[0]))
1490  || (*hasz && !ptarray_is_closed_3d(ppa[0])))
1491  gml_lwpgerror("invalid GML representation", 48);
1492 
1493  if (srs.reverse_axis)
1494  ppa[0] = ptarray_flip_coordinates(ppa[0]);
1495  }
1496  }
1497 
1498  /* Interior but no Exterior ! */
1499  if ( ! ppa )
1500  gml_lwpgerror("invalid GML representation", 48);
1501 
1502  /* PolygonPatch/interior */
1503  for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
1504  {
1505  if (xa->type != XML_ELEMENT_NODE) continue;
1506  if (!is_gml_namespace(xa, false)) continue;
1507  if (!is_gml_element(xa, "interior")) continue;
1508 
1509  /* PolygonPatch/interior/LinearRing */
1510  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1511  {
1512  if (xb->type != XML_ELEMENT_NODE) continue;
1513  if (!is_gml_element(xb, "LinearRing")) continue;
1514 
1515  ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa,
1516  sizeof(POINTARRAY*) * (ring + 1));
1517  ppa[ring] = parse_gml_data(xb->children, hasz, root_srid);
1518 
1519  if (ppa[ring]->npoints < 4
1520  || (!*hasz && !ptarray_is_closed_2d(ppa[ring]))
1521  || ( *hasz && !ptarray_is_closed_3d(ppa[ring])))
1522  gml_lwpgerror("invalid GML representation", 49);
1523 
1524  if (srs.reverse_axis)
1525  ppa[ring] = ptarray_flip_coordinates(ppa[ring]);
1526 
1527  ring++;
1528  }
1529  }
1530 
1531  /* Exterior Ring is mandatory */
1532  if (ppa == NULL || ppa[0] == NULL) gml_lwpgerror("invalid GML representation", 50);
1533 
1534  if (srs.srid != *root_srid && *root_srid != SRID_UNKNOWN)
1535  {
1536  for (i=0 ; i < ring ; i++)
1537  gml_reproject_pa(ppa[i], srs.srid, *root_srid);
1538  }
1539  geom = (LWGEOM *) lwpoly_construct(*root_srid, NULL, ring, ppa);
1540 
1541  return geom;
1542 }
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:714
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:235
void * lwalloc(size_t size)
Definition: lwutil.c:227
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:701
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:229
LWPOLY * lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
POINTARRAY * ptarray_flip_coordinates(POINTARRAY *pa)
Reverse X and Y axis on a given POINTARRAY.
Definition: ptarray.c:368
static POINTARRAY * gml_reproject_pa(POINTARRAY *pa, int32_t epsg_in, int32_t epsg_out)
Use Proj to reproject a given POINTARRAY.
static xmlChar * gmlGetProp(xmlNodePtr xnode, const char *charProp)
Retrieve a GML property from a node or NULL otherwise Respect namespaces if presents in the node elem...
static bool is_gml_namespace(xmlNodePtr xnode, bool is_strict)
Return false if current element namespace is not a GML one Return true otherwise.
static void parse_gml_srs(xmlNodePtr xnode, gmlSrs *srs)
Parse gml srsName attribute.
static POINTARRAY * parse_gml_data(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse data coordinates.
static void gml_lwpgerror(char *msg, __attribute__((__unused__)) int error_code)
Definition: lwgeom_in_gml.c:81
static bool is_gml_element(xmlNodePtr xn, const char *gml_name)

References gml_lwpgerror(), gml_reproject_pa(), gmlGetProp(), is_gml_element(), is_gml_namespace(), lwalloc(), lwpoly_construct(), lwrealloc(), parse_gml_data(), parse_gml_srs(), ptarray_flip_coordinates(), ptarray_is_closed_2d(), ptarray_is_closed_3d(), struct_gmlSrs::reverse_axis, struct_gmlSrs::srid, and SRID_UNKNOWN.

Referenced by parse_gml_psurface(), and parse_gml_surface().

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