PostGIS  3.4.0dev-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 1350 of file lwgeom_in_gml.c.

1351 {
1352  xmlChar *interpolation=NULL;
1353  POINTARRAY **ppa=NULL;
1354  LWGEOM *geom=NULL;
1355  xmlNodePtr xa, xb;
1356  int i, ring=0;
1357  gmlSrs srs;
1358 
1359  /* PolygonPatch */
1360  if (strcmp((char *) xnode->name, "PolygonPatch"))
1361  gml_lwpgerror("invalid GML representation", 48);
1362 
1363  /* GML SF is restricted to planar interpolation */
1364  interpolation = gmlGetProp(xnode, (xmlChar *) "interpolation");
1365  if (interpolation != NULL)
1366  {
1367  if (strcmp((char *) interpolation, "planar"))
1368  gml_lwpgerror("invalid GML representation", 48);
1369  xmlFree(interpolation);
1370  }
1371 
1372  parse_gml_srs(xnode, &srs);
1373 
1374  /* PolygonPatch/exterior */
1375  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1376  {
1377  if (!is_gml_namespace(xa, false)) continue;
1378  if (strcmp((char *) xa->name, "exterior")) continue;
1379 
1380  /* PolygonPatch/exterior/LinearRing */
1381  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1382  {
1383  if (xb->type != XML_ELEMENT_NODE) continue;
1384  if (!is_gml_namespace(xb, false)) continue;
1385  if (strcmp((char *) xb->name, "LinearRing")) continue;
1386 
1387  ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
1388  ppa[0] = parse_gml_data(xb->children, hasz, root_srid);
1389 
1390  if (ppa[0]->npoints < 4
1391  || (!*hasz && !ptarray_is_closed_2d(ppa[0]))
1392  || (*hasz && !ptarray_is_closed_3d(ppa[0])))
1393  gml_lwpgerror("invalid GML representation", 48);
1394 
1395  if (srs.reverse_axis)
1396  ppa[0] = ptarray_flip_coordinates(ppa[0]);
1397  }
1398  }
1399 
1400  /* Interior but no Exterior ! */
1401  if ( ! ppa )
1402  gml_lwpgerror("invalid GML representation", 48);
1403 
1404  /* PolygonPatch/interior */
1405  for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
1406  {
1407  if (xa->type != XML_ELEMENT_NODE) continue;
1408  if (!is_gml_namespace(xa, false)) continue;
1409  if (strcmp((char *) xa->name, "interior")) continue;
1410 
1411  /* PolygonPatch/interior/LinearRing */
1412  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1413  {
1414  if (xb->type != XML_ELEMENT_NODE) continue;
1415  if (strcmp((char *) xb->name, "LinearRing")) continue;
1416 
1417  ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa,
1418  sizeof(POINTARRAY*) * (ring + 1));
1419  ppa[ring] = parse_gml_data(xb->children, hasz, root_srid);
1420 
1421  if (ppa[ring]->npoints < 4
1422  || (!*hasz && !ptarray_is_closed_2d(ppa[ring]))
1423  || ( *hasz && !ptarray_is_closed_3d(ppa[ring])))
1424  gml_lwpgerror("invalid GML representation", 49);
1425 
1426  if (srs.reverse_axis)
1427  ppa[ring] = ptarray_flip_coordinates(ppa[ring]);
1428 
1429  ring++;
1430  }
1431  }
1432 
1433  /* Exterior Ring is mandatory */
1434  if (ppa == NULL || ppa[0] == NULL) gml_lwpgerror("invalid GML representation", 50);
1435 
1436  if (srs.srid != *root_srid && *root_srid != SRID_UNKNOWN)
1437  {
1438  for (i=0 ; i < ring ; i++)
1439  gml_reproject_pa(ppa[i], srs.srid, *root_srid);
1440  }
1441  geom = (LWGEOM *) lwpoly_construct(*root_srid, NULL, ring, ppa);
1442 
1443  return geom;
1444 }
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:727
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:714
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:215
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, xmlChar *prop)
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

References gml_lwpgerror(), gml_reproject_pa(), gmlGetProp(), 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: