PostGIS  2.5.7dev-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 1304 of file lwgeom_in_gml.c.

1305 {
1306  xmlChar *interpolation=NULL;
1307  POINTARRAY **ppa=NULL;
1308  LWGEOM *geom=NULL;
1309  xmlNodePtr xa, xb;
1310  int i, ring=0;
1311  gmlSrs srs;
1312 
1313  /* PolygonPatch */
1314  if (strcmp((char *) xnode->name, "PolygonPatch"))
1315  gml_lwpgerror("invalid GML representation", 48);
1316 
1317  /* GML SF is restricted to planar interpolation */
1318  interpolation = gmlGetProp(xnode, (xmlChar *) "interpolation");
1319  if (interpolation != NULL)
1320  {
1321  if (strcmp((char *) interpolation, "planar"))
1322  gml_lwpgerror("invalid GML representation", 48);
1323  xmlFree(interpolation);
1324  }
1325 
1326  parse_gml_srs(xnode, &srs);
1327 
1328  /* PolygonPatch/exterior */
1329  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1330  {
1331  if (!is_gml_namespace(xa, false)) continue;
1332  if (strcmp((char *) xa->name, "exterior")) continue;
1333 
1334  /* PolygonPatch/exterior/LinearRing */
1335  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1336  {
1337  if (xb->type != XML_ELEMENT_NODE) continue;
1338  if (!is_gml_namespace(xb, false)) continue;
1339  if (strcmp((char *) xb->name, "LinearRing")) continue;
1340 
1341  ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
1342  ppa[0] = parse_gml_data(xb->children, hasz, root_srid);
1343 
1344  if (ppa[0]->npoints < 4
1345  || (!*hasz && !ptarray_is_closed_2d(ppa[0]))
1346  || (*hasz && !ptarray_is_closed_3d(ppa[0])))
1347  gml_lwpgerror("invalid GML representation", 48);
1348 
1349  if (srs.reverse_axis)
1350  ppa[0] = ptarray_flip_coordinates(ppa[0]);
1351  }
1352  }
1353 
1354  /* Interior but no Exterior ! */
1355  if ( ! ppa )
1356  gml_lwpgerror("invalid GML representation", 48);
1357 
1358  /* PolygonPatch/interior */
1359  for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
1360  {
1361  if (xa->type != XML_ELEMENT_NODE) continue;
1362  if (!is_gml_namespace(xa, false)) continue;
1363  if (strcmp((char *) xa->name, "interior")) continue;
1364 
1365  /* PolygonPatch/interior/LinearRing */
1366  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1367  {
1368  if (xb->type != XML_ELEMENT_NODE) continue;
1369  if (strcmp((char *) xb->name, "LinearRing")) continue;
1370 
1371  ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa,
1372  sizeof(POINTARRAY*) * (ring + 1));
1373  ppa[ring] = parse_gml_data(xb->children, hasz, root_srid);
1374 
1375  if (ppa[ring]->npoints < 4
1376  || (!*hasz && !ptarray_is_closed_2d(ppa[ring]))
1377  || ( *hasz && !ptarray_is_closed_3d(ppa[ring])))
1378  gml_lwpgerror("invalid GML representation", 49);
1379 
1380  if (srs.reverse_axis)
1381  ppa[ring] = ptarray_flip_coordinates(ppa[ring]);
1382 
1383  ring++;
1384  }
1385  }
1386 
1387  /* Exterior Ring is mandatory */
1388  if (ppa == NULL || ppa[0] == NULL) gml_lwpgerror("invalid GML representation", 50);
1389 
1390  if (srs.srid != *root_srid && *root_srid != SRID_UNKNOWN)
1391  {
1392  for (i=0 ; i < ring ; i++)
1393  gml_reproject_pa(ppa[i], srs.srid, *root_srid);
1394  }
1395  geom = (LWGEOM *) lwpoly_construct(*root_srid, NULL, ring, ppa);
1396 
1397  return geom;
1398 }
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:708
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:237
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
void * lwalloc(size_t size)
Definition: lwutil.c:229
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:695
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
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, int srid_in, int srid_out)
Use Proj4 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:82

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: