PostGIS  3.3.9dev-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 1443 of file lwgeom_in_gml.c.

1444 {
1445  xmlChar *interpolation=NULL;
1446  POINTARRAY **ppa=NULL;
1447  LWGEOM *geom=NULL;
1448  xmlNodePtr xa, xb;
1449  int i, ring=0;
1450  gmlSrs srs;
1451 
1452  /* PolygonPatch */
1453  if (!is_gml_element(xnode, "PolygonPatch"))
1454  gml_lwpgerror("invalid GML representation", 48);
1455 
1456  /* GML SF is restricted to planar interpolation */
1457  interpolation = gmlGetProp(xnode, "interpolation");
1458  if (interpolation != NULL)
1459  {
1460  if (strcmp((char *) interpolation, "planar"))
1461  gml_lwpgerror("invalid GML representation", 48);
1462  xmlFree(interpolation);
1463  }
1464 
1465  parse_gml_srs(xnode, &srs);
1466 
1467  /* PolygonPatch/exterior */
1468  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1469  {
1470  if (!is_gml_namespace(xa, false)) continue;
1471  if (!is_gml_element(xa, "exterior")) continue;
1472 
1473  /* PolygonPatch/exterior/LinearRing */
1474  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1475  {
1476  if (xb->type != XML_ELEMENT_NODE) continue;
1477  if (!is_gml_namespace(xb, false)) continue;
1478  if (!is_gml_element(xb, "LinearRing")) continue;
1479 
1480  ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
1481  ppa[0] = parse_gml_data(xb->children, hasz, root_srid);
1482 
1483  if (ppa[0]->npoints < 4
1484  || (!*hasz && !ptarray_is_closed_2d(ppa[0]))
1485  || (*hasz && !ptarray_is_closed_3d(ppa[0])))
1486  gml_lwpgerror("invalid GML representation", 48);
1487 
1488  if (srs.reverse_axis)
1489  ppa[0] = ptarray_flip_coordinates(ppa[0]);
1490  }
1491  }
1492 
1493  /* Interior but no Exterior ! */
1494  if ( ! ppa )
1495  gml_lwpgerror("invalid GML representation", 48);
1496 
1497  /* PolygonPatch/interior */
1498  for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
1499  {
1500  if (xa->type != XML_ELEMENT_NODE) continue;
1501  if (!is_gml_namespace(xa, false)) continue;
1502  if (!is_gml_element(xa, "interior")) continue;
1503 
1504  /* PolygonPatch/interior/LinearRing */
1505  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1506  {
1507  if (xb->type != XML_ELEMENT_NODE) continue;
1508  if (!is_gml_element(xb, "LinearRing")) continue;
1509 
1510  ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa,
1511  sizeof(POINTARRAY*) * (ring + 1));
1512  ppa[ring] = parse_gml_data(xb->children, hasz, root_srid);
1513 
1514  if (ppa[ring]->npoints < 4
1515  || (!*hasz && !ptarray_is_closed_2d(ppa[ring]))
1516  || ( *hasz && !ptarray_is_closed_3d(ppa[ring])))
1517  gml_lwpgerror("invalid GML representation", 49);
1518 
1519  if (srs.reverse_axis)
1520  ppa[ring] = ptarray_flip_coordinates(ppa[ring]);
1521 
1522  ring++;
1523  }
1524  }
1525 
1526  /* Exterior Ring is mandatory */
1527  if (ppa == NULL || ppa[0] == NULL) gml_lwpgerror("invalid GML representation", 50);
1528 
1529  if (srs.srid != *root_srid && *root_srid != SRID_UNKNOWN)
1530  {
1531  for (i=0 ; i < ring ; i++)
1532  gml_reproject_pa(ppa[i], srs.srid, *root_srid);
1533  }
1534  geom = (LWGEOM *) lwpoly_construct(*root_srid, NULL, ring, ppa);
1535 
1536  return geom;
1537 }
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:230
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: