PostGIS  2.2.8dev-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 1274 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().

1275 {
1276  xmlChar *interpolation=NULL;
1277  POINTARRAY **ppa=NULL;
1278  LWGEOM *geom=NULL;
1279  xmlNodePtr xa, xb;
1280  int i, ring=0;
1281  gmlSrs srs;
1282 
1283  /* PolygonPatch */
1284  if (strcmp((char *) xnode->name, "PolygonPatch"))
1285  gml_lwpgerror("invalid GML representation", 48);
1286 
1287  /* GML SF is resticted to planar interpolation */
1288  interpolation = gmlGetProp(xnode, (xmlChar *) "interpolation");
1289  if (interpolation != NULL)
1290  {
1291  if (strcmp((char *) interpolation, "planar"))
1292  gml_lwpgerror("invalid GML representation", 48);
1293  xmlFree(interpolation);
1294  }
1295 
1296  parse_gml_srs(xnode, &srs);
1297 
1298  /* PolygonPatch/exterior */
1299  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1300  {
1301  if (!is_gml_namespace(xa, false)) continue;
1302  if (strcmp((char *) xa->name, "exterior")) continue;
1303 
1304  /* PolygonPatch/exterior/LinearRing */
1305  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1306  {
1307  if (xb->type != XML_ELEMENT_NODE) continue;
1308  if (!is_gml_namespace(xb, false)) continue;
1309  if (strcmp((char *) xb->name, "LinearRing")) continue;
1310 
1311  ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
1312  ppa[0] = parse_gml_data(xb->children, hasz, root_srid);
1313 
1314  if (ppa[0]->npoints < 4
1315  || (!*hasz && !ptarray_is_closed_2d(ppa[0]))
1316  || (*hasz && !ptarray_is_closed_3d(ppa[0])))
1317  gml_lwpgerror("invalid GML representation", 48);
1318 
1319  if (srs.reverse_axis)
1320  ppa[0] = ptarray_flip_coordinates(ppa[0]);
1321  }
1322  }
1323 
1324  /* Interior but no Exterior ! */
1325  if ( ! ppa )
1326  gml_lwpgerror("invalid GML representation", 48);
1327 
1328  /* PolygonPatch/interior */
1329  for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
1330  {
1331  if (xa->type != XML_ELEMENT_NODE) continue;
1332  if (!is_gml_namespace(xa, false)) continue;
1333  if (strcmp((char *) xa->name, "interior")) continue;
1334 
1335  /* PolygonPatch/interior/LinearRing */
1336  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1337  {
1338  if (xb->type != XML_ELEMENT_NODE) continue;
1339  if (strcmp((char *) xb->name, "LinearRing")) continue;
1340 
1341  ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa,
1342  sizeof(POINTARRAY*) * (ring + 1));
1343  ppa[ring] = parse_gml_data(xb->children, hasz, root_srid);
1344 
1345  if (ppa[ring]->npoints < 4
1346  || (!*hasz && !ptarray_is_closed_2d(ppa[ring]))
1347  || ( *hasz && !ptarray_is_closed_3d(ppa[ring])))
1348  gml_lwpgerror("invalid GML representation", 49);
1349 
1350  if (srs.reverse_axis)
1351  ppa[ring] = ptarray_flip_coordinates(ppa[ring]);
1352 
1353  ring++;
1354  }
1355  }
1356 
1357  /* Exterior Ring is mandatory */
1358  if (ppa == NULL || ppa[0] == NULL) gml_lwpgerror("invalid GML representation", 50);
1359 
1360  if (srs.srid != *root_srid && *root_srid != SRID_UNKNOWN)
1361  {
1362  for (i=0 ; i < ring ; i++)
1363  gml_reproject_pa(ppa[i], srs.srid, *root_srid);
1364  }
1365  geom = (LWGEOM *) lwpoly_construct(*root_srid, NULL, ring, ppa);
1366 
1367  return geom;
1368 }
static void gml_lwpgerror(char *msg, int error_code)
Definition: lwgeom_in_gml.c:67
static void parse_gml_srs(xmlNodePtr xnode, gmlSrs *srs)
Parse gml srsName attribute.
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:707
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:694
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:29
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:172
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:207
void * lwalloc(size_t size)
Definition: lwutil.c:199
Here is the call graph for this function:
Here is the caller graph for this function: