PostGIS  3.0.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 1383 of file lwgeom_in_gml.c.

1384 {
1385  xmlChar *interpolation=NULL;
1386  POINTARRAY **ppa=NULL;
1387  LWGEOM *geom=NULL;
1388  xmlNodePtr xa, xb;
1389  int i, ring=0;
1390  gmlSrs srs;
1391 
1392  /* PolygonPatch */
1393  if (!is_gml_element(xnode, "PolygonPatch"))
1394  gml_lwpgerror("invalid GML representation", 48);
1395 
1396  /* GML SF is restricted to planar interpolation */
1397  interpolation = gmlGetProp(xnode, "interpolation");
1398  if (interpolation != NULL)
1399  {
1400  if (strcmp((char *) interpolation, "planar"))
1401  gml_lwpgerror("invalid GML representation", 48);
1402  xmlFree(interpolation);
1403  }
1404 
1405  parse_gml_srs(xnode, &srs);
1406 
1407  /* PolygonPatch/exterior */
1408  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1409  {
1410  if (!is_gml_namespace(xa, false)) continue;
1411  if (!is_gml_element(xa, "exterior")) continue;
1412 
1413  /* PolygonPatch/exterior/LinearRing */
1414  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1415  {
1416  if (xb->type != XML_ELEMENT_NODE) continue;
1417  if (!is_gml_namespace(xb, false)) continue;
1418  if (!is_gml_element(xb, "LinearRing")) continue;
1419 
1420  ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
1421  ppa[0] = parse_gml_data(xb->children, hasz, root_srid);
1422 
1423  if (ppa[0]->npoints < 4
1424  || (!*hasz && !ptarray_is_closed_2d(ppa[0]))
1425  || (*hasz && !ptarray_is_closed_3d(ppa[0])))
1426  gml_lwpgerror("invalid GML representation", 48);
1427 
1428  if (srs.reverse_axis)
1429  ppa[0] = ptarray_flip_coordinates(ppa[0]);
1430  }
1431  }
1432 
1433  /* Interior but no Exterior ! */
1434  if ( ! ppa )
1435  gml_lwpgerror("invalid GML representation", 48);
1436 
1437  /* PolygonPatch/interior */
1438  for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
1439  {
1440  if (xa->type != XML_ELEMENT_NODE) continue;
1441  if (!is_gml_namespace(xa, false)) continue;
1442  if (!is_gml_element(xa, "interior")) continue;
1443 
1444  /* PolygonPatch/interior/LinearRing */
1445  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1446  {
1447  if (xb->type != XML_ELEMENT_NODE) continue;
1448  if (!is_gml_element(xb, "LinearRing")) continue;
1449 
1450  ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa,
1451  sizeof(POINTARRAY*) * (ring + 1));
1452  ppa[ring] = parse_gml_data(xb->children, hasz, root_srid);
1453 
1454  if (ppa[ring]->npoints < 4
1455  || (!*hasz && !ptarray_is_closed_2d(ppa[ring]))
1456  || ( *hasz && !ptarray_is_closed_3d(ppa[ring])))
1457  gml_lwpgerror("invalid GML representation", 49);
1458 
1459  if (srs.reverse_axis)
1460  ppa[ring] = ptarray_flip_coordinates(ppa[ring]);
1461 
1462  ring++;
1463  }
1464  }
1465 
1466  /* Exterior Ring is mandatory */
1467  if (ppa == NULL || ppa[0] == NULL) gml_lwpgerror("invalid GML representation", 50);
1468 
1469  if (srs.srid != *root_srid && *root_srid != SRID_UNKNOWN)
1470  {
1471  for (i=0 ; i < ring ; i++)
1472  gml_reproject_pa(ppa[i], srs.srid, *root_srid);
1473  }
1474  geom = (LWGEOM *) lwpoly_construct(*root_srid, NULL, ring, ppa);
1475 
1476  return geom;
1477 }
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:706
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:693
#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:360
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:82
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: