PostGIS  2.4.9dev-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 1288 of file lwgeom_in_gml.c.

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().

1289 {
1290  xmlChar *interpolation=NULL;
1291  POINTARRAY **ppa=NULL;
1292  LWGEOM *geom=NULL;
1293  xmlNodePtr xa, xb;
1294  int i, ring=0;
1295  gmlSrs srs;
1296 
1297  /* PolygonPatch */
1298  if (strcmp((char *) xnode->name, "PolygonPatch"))
1299  gml_lwpgerror("invalid GML representation", 48);
1300 
1301  /* GML SF is resticted to planar interpolation */
1302  interpolation = gmlGetProp(xnode, (xmlChar *) "interpolation");
1303  if (interpolation != NULL)
1304  {
1305  if (strcmp((char *) interpolation, "planar"))
1306  gml_lwpgerror("invalid GML representation", 48);
1307  xmlFree(interpolation);
1308  }
1309 
1310  parse_gml_srs(xnode, &srs);
1311 
1312  /* PolygonPatch/exterior */
1313  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1314  {
1315  if (!is_gml_namespace(xa, false)) continue;
1316  if (strcmp((char *) xa->name, "exterior")) continue;
1317 
1318  /* PolygonPatch/exterior/LinearRing */
1319  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1320  {
1321  if (xb->type != XML_ELEMENT_NODE) continue;
1322  if (!is_gml_namespace(xb, false)) continue;
1323  if (strcmp((char *) xb->name, "LinearRing")) continue;
1324 
1325  ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
1326  ppa[0] = parse_gml_data(xb->children, hasz, root_srid);
1327 
1328  if (ppa[0]->npoints < 4
1329  || (!*hasz && !ptarray_is_closed_2d(ppa[0]))
1330  || (*hasz && !ptarray_is_closed_3d(ppa[0])))
1331  gml_lwpgerror("invalid GML representation", 48);
1332 
1333  if (srs.reverse_axis)
1334  ppa[0] = ptarray_flip_coordinates(ppa[0]);
1335  }
1336  }
1337 
1338  /* Interior but no Exterior ! */
1339  if ( ! ppa )
1340  gml_lwpgerror("invalid GML representation", 48);
1341 
1342  /* PolygonPatch/interior */
1343  for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
1344  {
1345  if (xa->type != XML_ELEMENT_NODE) continue;
1346  if (!is_gml_namespace(xa, false)) continue;
1347  if (strcmp((char *) xa->name, "interior")) continue;
1348 
1349  /* PolygonPatch/interior/LinearRing */
1350  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1351  {
1352  if (xb->type != XML_ELEMENT_NODE) continue;
1353  if (strcmp((char *) xb->name, "LinearRing")) continue;
1354 
1355  ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa,
1356  sizeof(POINTARRAY*) * (ring + 1));
1357  ppa[ring] = parse_gml_data(xb->children, hasz, root_srid);
1358 
1359  if (ppa[ring]->npoints < 4
1360  || (!*hasz && !ptarray_is_closed_2d(ppa[ring]))
1361  || ( *hasz && !ptarray_is_closed_3d(ppa[ring])))
1362  gml_lwpgerror("invalid GML representation", 49);
1363 
1364  if (srs.reverse_axis)
1365  ppa[ring] = ptarray_flip_coordinates(ppa[ring]);
1366 
1367  ring++;
1368  }
1369  }
1370 
1371  /* Exterior Ring is mandatory */
1372  if (ppa == NULL || ppa[0] == NULL) gml_lwpgerror("invalid GML representation", 50);
1373 
1374  if (srs.srid != *root_srid && *root_srid != SRID_UNKNOWN)
1375  {
1376  for (i=0 ; i < ring ; i++)
1377  gml_reproject_pa(ppa[i], srs.srid, *root_srid);
1378  }
1379  geom = (LWGEOM *) lwpoly_construct(*root_srid, NULL, ring, ppa);
1380 
1381  return geom;
1382 }
static void gml_lwpgerror(char *msg, int error_code)
Definition: lwgeom_in_gml.c:81
static void parse_gml_srs(xmlNodePtr xnode, gmlSrs *srs)
Parse gml srsName attribute.
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:710
static xmlChar * gmlGetProp(xmlNodePtr xnode, xmlChar *prop)
Retrieve a GML propertie from a node or NULL otherwise Respect namespaces if presents in the node ele...
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:697
static POINTARRAY * gml_reproject_pa(POINTARRAY *pa, int srid_in, int srid_out)
Use Proj4 to reproject a given POINTARRAY.
POINTARRAY * ptarray_flip_coordinates(POINTARRAY *pa)
Reverse X and Y axis on a given POINTARRAY.
Definition: ptarray.c:369
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
static POINTARRAY * parse_gml_data(xmlNodePtr xnode, bool *hasz, int *root_srid)
Parse data coordinates.
static bool is_gml_namespace(xmlNodePtr xnode, bool is_strict)
Return false if current element namespace is not a GML one Return true otherwise. ...
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:237
void * lwalloc(size_t size)
Definition: lwutil.c:229
Here is the call graph for this function:
Here is the caller graph for this function: