PostGIS  2.5.0dev-r@@SVN_REVISION@@
static LWGEOM* parse_gml_patch ( xmlNodePtr  xnode,
bool *  hasz,
int *  root_srid 
)
static

Parse GML PolygonPatch (3.1.1)

Definition at line 1287 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().

1288 {
1289  xmlChar *interpolation=NULL;
1290  POINTARRAY **ppa=NULL;
1291  LWGEOM *geom=NULL;
1292  xmlNodePtr xa, xb;
1293  int i, ring=0;
1294  gmlSrs srs;
1295 
1296  /* PolygonPatch */
1297  if (strcmp((char *) xnode->name, "PolygonPatch"))
1298  gml_lwpgerror("invalid GML representation", 48);
1299 
1300  /* GML SF is resticted to planar interpolation */
1301  interpolation = gmlGetProp(xnode, (xmlChar *) "interpolation");
1302  if (interpolation != NULL)
1303  {
1304  if (strcmp((char *) interpolation, "planar"))
1305  gml_lwpgerror("invalid GML representation", 48);
1306  xmlFree(interpolation);
1307  }
1308 
1309  parse_gml_srs(xnode, &srs);
1310 
1311  /* PolygonPatch/exterior */
1312  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1313  {
1314  if (!is_gml_namespace(xa, false)) continue;
1315  if (strcmp((char *) xa->name, "exterior")) continue;
1316 
1317  /* PolygonPatch/exterior/LinearRing */
1318  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1319  {
1320  if (xb->type != XML_ELEMENT_NODE) continue;
1321  if (!is_gml_namespace(xb, false)) continue;
1322  if (strcmp((char *) xb->name, "LinearRing")) continue;
1323 
1324  ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
1325  ppa[0] = parse_gml_data(xb->children, hasz, root_srid);
1326 
1327  if (ppa[0]->npoints < 4
1328  || (!*hasz && !ptarray_is_closed_2d(ppa[0]))
1329  || (*hasz && !ptarray_is_closed_3d(ppa[0])))
1330  gml_lwpgerror("invalid GML representation", 48);
1331 
1332  if (srs.reverse_axis)
1333  ppa[0] = ptarray_flip_coordinates(ppa[0]);
1334  }
1335  }
1336 
1337  /* Interior but no Exterior ! */
1338  if ( ! ppa )
1339  gml_lwpgerror("invalid GML representation", 48);
1340 
1341  /* PolygonPatch/interior */
1342  for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
1343  {
1344  if (xa->type != XML_ELEMENT_NODE) continue;
1345  if (!is_gml_namespace(xa, false)) continue;
1346  if (strcmp((char *) xa->name, "interior")) continue;
1347 
1348  /* PolygonPatch/interior/LinearRing */
1349  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1350  {
1351  if (xb->type != XML_ELEMENT_NODE) continue;
1352  if (strcmp((char *) xb->name, "LinearRing")) continue;
1353 
1354  ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa,
1355  sizeof(POINTARRAY*) * (ring + 1));
1356  ppa[ring] = parse_gml_data(xb->children, hasz, root_srid);
1357 
1358  if (ppa[ring]->npoints < 4
1359  || (!*hasz && !ptarray_is_closed_2d(ppa[ring]))
1360  || ( *hasz && !ptarray_is_closed_3d(ppa[ring])))
1361  gml_lwpgerror("invalid GML representation", 49);
1362 
1363  if (srs.reverse_axis)
1364  ppa[ring] = ptarray_flip_coordinates(ppa[ring]);
1365 
1366  ring++;
1367  }
1368  }
1369 
1370  /* Exterior Ring is mandatory */
1371  if (ppa == NULL || ppa[0] == NULL) gml_lwpgerror("invalid GML representation", 50);
1372 
1373  if (srs.srid != *root_srid && *root_srid != SRID_UNKNOWN)
1374  {
1375  for (i=0 ; i < ring ; i++)
1376  gml_reproject_pa(ppa[i], srs.srid, *root_srid);
1377  }
1378  geom = (LWGEOM *) lwpoly_construct(*root_srid, NULL, ring, ppa);
1379 
1380  return geom;
1381 }
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:701
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:688
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:368
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:187
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: