PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ parse_gml_polygon()

static LWGEOM* parse_gml_polygon ( xmlNodePtr  xnode,
bool *  hasz,
int *  root_srid 
)
static

Parse GML Polygon (2.1.2, 3.1.1)

Definition at line 1283 of file lwgeom_in_gml.c.

1284 {
1285  gmlSrs srs;
1286  int i, ring;
1287  LWGEOM *geom;
1288  xmlNodePtr xa, xb;
1289  POINTARRAY **ppa = NULL;
1290 
1291  if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
1292  if (xnode == NULL)
1293  gml_lwpgerror("invalid GML representation", 30);
1294 
1295  if (xnode->children == NULL)
1296  return lwpoly_as_lwgeom(lwpoly_construct_empty(*root_srid, 0, 0));
1297 
1298  parse_gml_srs(xnode, &srs);
1299 
1300  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1301  {
1302  /* Polygon/outerBoundaryIs -> GML 2.1.2 */
1303  /* Polygon/exterior -> GML 3.1.1 */
1304  if (xa->type != XML_ELEMENT_NODE) continue;
1305  if (!is_gml_namespace(xa, false)) continue;
1306  if (!(is_gml_element(xa, "outerBoundaryIs") ||
1307  is_gml_element(xa, "exterior")))
1308  continue;
1309 
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 (!is_gml_element(xb, "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_lwpgerror("invalid GML representation", 43);
1323 
1324  if (srs.reverse_axis) ppa[0] = ptarray_flip_coordinates(ppa[0]);
1325  }
1326  }
1327 
1328  /* Found an <exterior> or <outerBoundaryIs> but no rings?!? We're outa here! */
1329  if ( ! ppa )
1330  gml_lwpgerror("invalid GML representation", 43);
1331 
1332  for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
1333  {
1334  /* Polygon/innerBoundaryIs -> GML 2.1.2 */
1335  /* Polygon/interior -> GML 3.1.1 */
1336  if (xa->type != XML_ELEMENT_NODE) continue;
1337  if (!is_gml_namespace(xa, false)) continue;
1338  if (!(is_gml_element(xa, "innerBoundaryIs") ||
1339  is_gml_element(xa, "interior")))
1340  continue;
1341 
1342  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1343  {
1344  if (xb->type != XML_ELEMENT_NODE) continue;
1345  if (!is_gml_namespace(xb, false)) continue;
1346  if (!is_gml_element(xb, "LinearRing")) continue;
1347 
1348  ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa,
1349  sizeof(POINTARRAY*) * (ring + 1));
1350  ppa[ring] = parse_gml_data(xb->children, hasz, root_srid);
1351 
1352  if (ppa[ring]->npoints < 4
1353  || (!*hasz && !ptarray_is_closed_2d(ppa[ring]))
1354  || (*hasz && !ptarray_is_closed_3d(ppa[ring])))
1355  gml_lwpgerror("invalid GML representation", 43);
1356 
1357  if (srs.reverse_axis) ppa[ring] = ptarray_flip_coordinates(ppa[ring]);
1358  ring++;
1359  }
1360  }
1361 
1362  /* Exterior Ring is mandatory */
1363  if (ppa == NULL || ppa[0] == NULL) gml_lwpgerror("invalid GML representation", 44);
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 }
int ptarray_is_closed_3d(const POINTARRAY *pa)
Definition: ptarray.c:714
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:312
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:235
void * lwalloc(size_t size)
Definition: lwutil.c:227
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:701
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:229
LWPOLY * lwpoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwpoly.c:161
LWPOLY * lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
POINTARRAY * ptarray_flip_coordinates(POINTARRAY *pa)
Reverse X and Y axis on a given POINTARRAY.
Definition: ptarray.c:368
static xmlNodePtr get_xlink_node(xmlNodePtr xnode)
Return a xmlNodePtr on a node referenced by a XLink or NULL otherwise.
static bool is_xlink(xmlNodePtr node)
Return true if current node contains a simple XLink Return false otherwise.
static POINTARRAY * gml_reproject_pa(POINTARRAY *pa, int32_t epsg_in, int32_t epsg_out)
Use Proj to reproject a given POINTARRAY.
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:81
static bool is_gml_element(xmlNodePtr xn, const char *gml_name)

References get_xlink_node(), gml_lwpgerror(), gml_reproject_pa(), is_gml_element(), is_gml_namespace(), is_xlink(), lwalloc(), lwpoly_as_lwgeom(), lwpoly_construct(), lwpoly_construct_empty(), 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().

Here is the call graph for this function:
Here is the caller graph for this function: