PostGIS  2.1.10dev-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 1279 of file lwgeom_in_gml.c.

References gml_lwerror(), 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().

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

Here is the call graph for this function:

Here is the caller graph for this function: