PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ parse_gml_triangle()

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

Parse GML Triangle (3.1.1)

Definition at line 1374 of file lwgeom_in_gml.c.

1375 {
1376  gmlSrs srs;
1377  LWGEOM *geom;
1378  xmlNodePtr xa, xb;
1379  POINTARRAY *pa = NULL;
1380  xmlChar *interpolation=NULL;
1381 
1382  if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
1383  if (xnode == NULL)
1384  gml_lwpgerror("invalid GML representation", 30);
1385 
1386  if (xnode->children == NULL)
1387  return lwtriangle_as_lwgeom(lwtriangle_construct_empty(*root_srid, 0, 0));
1388 
1389  /* GML SF is restricted to planar interpolation
1390  NOTA: I know Triangle is not part of SF, but
1391  we have to be consistent with other surfaces */
1392  interpolation = gmlGetProp(xnode, "interpolation");
1393  if (interpolation != NULL)
1394  {
1395  if (strcmp((char *) interpolation, "planar"))
1396  gml_lwpgerror("invalid GML representation", 45);
1397  xmlFree(interpolation);
1398  }
1399 
1400  parse_gml_srs(xnode, &srs);
1401 
1402  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1403  {
1404  /* Triangle/exterior */
1405  if (xa->type != XML_ELEMENT_NODE) continue;
1406  if (!is_gml_namespace(xa, false)) continue;
1407  if (!is_gml_element(xa, "exterior")) continue;
1408 
1409  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1410  {
1411  /* Triangle/exterior/LinearRing */
1412  if (xb->type != XML_ELEMENT_NODE) continue;
1413  if (!is_gml_namespace(xb, false)) continue;
1414  if (!is_gml_element(xb, "LinearRing")) continue;
1415 
1416  pa = (POINTARRAY*) lwalloc(sizeof(POINTARRAY));
1417  pa = parse_gml_data(xb->children, hasz, root_srid);
1418 
1419  if (pa->npoints != 4
1420  || (!*hasz && !ptarray_is_closed_2d(pa))
1421  || (*hasz && !ptarray_is_closed_3d(pa)))
1422  gml_lwpgerror("invalid GML representation", 46);
1423 
1424  if (srs.reverse_axis) pa = ptarray_flip_coordinates(pa);
1425  }
1426  }
1427 
1428  /* Exterior Ring is mandatory */
1429  if (pa == NULL) gml_lwpgerror("invalid GML representation", 47);
1430 
1431  if (srs.srid != *root_srid && *root_srid != SRID_UNKNOWN)
1432  gml_reproject_pa(pa, srs.srid, *root_srid);
1433 
1434  geom = (LWGEOM *) lwtriangle_construct(*root_srid, NULL, pa);
1435 
1436  return geom;
1437 }
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:714
LWTRIANGLE * lwtriangle_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwtriangle.c:58
void * lwalloc(size_t size)
Definition: lwutil.c:227
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:701
LWGEOM * lwtriangle_as_lwgeom(const LWTRIANGLE *obj)
Definition: lwgeom.c:334
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:230
POINTARRAY * ptarray_flip_coordinates(POINTARRAY *pa)
Reverse X and Y axis on a given POINTARRAY.
Definition: ptarray.c:368
LWTRIANGLE * lwtriangle_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition: lwtriangle.c:40
static xmlNodePtr get_xlink_node(xmlNodePtr xnode)
Return a xmlNodePtr on a node referenced by a XLink or NULL otherwise.
static bool is_xlink(xmlNodePtr node)
Return true if current node contains a simple XLink Return false otherwise.
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)
uint32_t npoints
Definition: liblwgeom.h:442

References get_xlink_node(), gml_lwpgerror(), gml_reproject_pa(), gmlGetProp(), is_gml_element(), is_gml_namespace(), is_xlink(), lwalloc(), lwtriangle_as_lwgeom(), lwtriangle_construct(), lwtriangle_construct_empty(), POINTARRAY::npoints, 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(), and parse_gml_tin().

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