PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 1400 of file lwgeom_in_gml.c.

1401{
1402 xmlChar *interpolation=NULL;
1403 POINTARRAY **ppa=NULL;
1404 LWGEOM *geom=NULL;
1405 xmlNodePtr xa, xb;
1406 int i, ring=0;
1407 gmlSrs srs;
1408
1409 /* PolygonPatch */
1410 if (!is_gml_element(xnode, "PolygonPatch"))
1411 gml_lwpgerror("invalid GML representation", 48);
1412
1413 /* GML SF is restricted to planar interpolation */
1414 interpolation = gmlGetProp(xnode, "interpolation");
1415 if (interpolation != NULL)
1416 {
1417 if (strcmp((char *) interpolation, "planar"))
1418 gml_lwpgerror("invalid GML representation", 48);
1419 xmlFree(interpolation);
1420 }
1421
1422 parse_gml_srs(xnode, &srs);
1423
1424 /* PolygonPatch/exterior */
1425 for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1426 {
1427 if (!is_gml_namespace(xa, false)) continue;
1428 if (!is_gml_element(xa, "exterior")) continue;
1429
1430 /* PolygonPatch/exterior/LinearRing */
1431 for (xb = xa->children ; xb != NULL ; xb = xb->next)
1432 {
1433 if (xb->type != XML_ELEMENT_NODE) continue;
1434 if (!is_gml_namespace(xb, false)) continue;
1435 if (!is_gml_element(xb, "LinearRing")) continue;
1436
1437 ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
1438 ppa[0] = parse_gml_data(xb->children, hasz, root_srid);
1439
1440 if (ppa[0]->npoints < 4
1441 || (!*hasz && !ptarray_is_closed_2d(ppa[0]))
1442 || (*hasz && !ptarray_is_closed_3d(ppa[0])))
1443 gml_lwpgerror("invalid GML representation", 48);
1444
1445 if (srs.reverse_axis)
1446 ppa[0] = ptarray_flip_coordinates(ppa[0]);
1447 }
1448 }
1449
1450 /* Interior but no Exterior ! */
1451 if ( ! ppa )
1452 gml_lwpgerror("invalid GML representation", 48);
1453
1454 /* PolygonPatch/interior */
1455 for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
1456 {
1457 if (xa->type != XML_ELEMENT_NODE) continue;
1458 if (!is_gml_namespace(xa, false)) continue;
1459 if (!is_gml_element(xa, "interior")) continue;
1460
1461 /* PolygonPatch/interior/LinearRing */
1462 for (xb = xa->children ; xb != NULL ; xb = xb->next)
1463 {
1464 if (xb->type != XML_ELEMENT_NODE) continue;
1465 if (!is_gml_element(xb, "LinearRing")) continue;
1466
1467 ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa,
1468 sizeof(POINTARRAY*) * (ring + 1));
1469 ppa[ring] = parse_gml_data(xb->children, hasz, root_srid);
1470
1471 if (ppa[ring]->npoints < 4
1472 || (!*hasz && !ptarray_is_closed_2d(ppa[ring]))
1473 || ( *hasz && !ptarray_is_closed_3d(ppa[ring])))
1474 gml_lwpgerror("invalid GML representation", 49);
1475
1476 if (srs.reverse_axis)
1477 ppa[ring] = ptarray_flip_coordinates(ppa[ring]);
1478
1479 ring++;
1480 }
1481 }
1482
1483 /* Exterior Ring is mandatory */
1484 if (ppa == NULL || ppa[0] == NULL) gml_lwpgerror("invalid GML representation", 50);
1485
1486 if (srs.srid != *root_srid && *root_srid != SRID_UNKNOWN)
1487 {
1488 for (i=0 ; i < ring ; i++)
1489 gml_reproject_pa(ppa[i], srs.srid, *root_srid);
1490 }
1491 geom = (LWGEOM *) lwpoly_construct(*root_srid, NULL, ring, ppa);
1492
1493 return geom;
1494}
void * lwrealloc(void *mem, size_t size)
Definition lwutil.c:242
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition ptarray.c:723
void * lwalloc(size_t size)
Definition lwutil.c:227
POINTARRAY * ptarray_flip_coordinates(POINTARRAY *pa)
Reverse X and Y axis on a given POINTARRAY.
Definition ptarray.c:368
LWPOLY * lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition lwpoly.c:43
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition ptarray.c:710
#define SRID_UNKNOWN
Unknown SRID value.
Definition liblwgeom.h:215
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 POINTARRAY * gml_reproject_pa(POINTARRAY *pa, int32_t epsg_in, int32_t epsg_out)
Use Proj to reproject a given POINTARRAY.
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 void gml_lwpgerror(char *msg, __attribute__((__unused__)) int error_code)
static POINTARRAY * parse_gml_data(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse data coordinates.
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: