PostGIS  2.2.8dev-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 1115 of file lwgeom_in_gml.c.

References get_xlink_node(), gml_lwpgerror(), gml_reproject_pa(), 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().

1116 {
1117  gmlSrs srs;
1118  int i, ring;
1119  LWGEOM *geom;
1120  xmlNodePtr xa, xb;
1121  POINTARRAY **ppa = NULL;
1122 
1123  if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
1124 
1125  if (xnode->children == NULL)
1126  return lwpoly_as_lwgeom(lwpoly_construct_empty(*root_srid, 0, 0));
1127 
1128  parse_gml_srs(xnode, &srs);
1129 
1130  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1131  {
1132  /* Polygon/outerBoundaryIs -> GML 2.1.2 */
1133  /* Polygon/exterior -> GML 3.1.1 */
1134  if (xa->type != XML_ELEMENT_NODE) continue;
1135  if (!is_gml_namespace(xa, false)) continue;
1136  if (strcmp((char *) xa->name, "outerBoundaryIs") &&
1137  strcmp((char *) xa->name, "exterior")) continue;
1138 
1139  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1140  {
1141  if (xb->type != XML_ELEMENT_NODE) continue;
1142  if (!is_gml_namespace(xb, false)) continue;
1143  if (strcmp((char *) xb->name, "LinearRing")) continue;
1144 
1145  ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
1146  ppa[0] = parse_gml_data(xb->children, hasz, root_srid);
1147 
1148  if (ppa[0]->npoints < 4
1149  || (!*hasz && !ptarray_is_closed_2d(ppa[0]))
1150  || (*hasz && !ptarray_is_closed_3d(ppa[0])))
1151  gml_lwpgerror("invalid GML representation", 43);
1152 
1153  if (srs.reverse_axis) ppa[0] = ptarray_flip_coordinates(ppa[0]);
1154  }
1155  }
1156 
1157  /* Found an <exterior> or <outerBoundaryIs> but no rings?!? We're outa here! */
1158  if ( ! ppa )
1159  gml_lwpgerror("invalid GML representation", 43);
1160 
1161  for (ring=1, xa = xnode->children ; xa != NULL ; xa = xa->next)
1162  {
1163  /* Polygon/innerBoundaryIs -> GML 2.1.2 */
1164  /* Polygon/interior -> GML 3.1.1 */
1165  if (xa->type != XML_ELEMENT_NODE) continue;
1166  if (!is_gml_namespace(xa, false)) continue;
1167  if (strcmp((char *) xa->name, "innerBoundaryIs") &&
1168  strcmp((char *) xa->name, "interior")) continue;
1169 
1170  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1171  {
1172  if (xb->type != XML_ELEMENT_NODE) continue;
1173  if (!is_gml_namespace(xb, false)) continue;
1174  if (strcmp((char *) xb->name, "LinearRing")) continue;
1175 
1176  ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa,
1177  sizeof(POINTARRAY*) * (ring + 1));
1178  ppa[ring] = parse_gml_data(xb->children, hasz, root_srid);
1179 
1180  if (ppa[ring]->npoints < 4
1181  || (!*hasz && !ptarray_is_closed_2d(ppa[ring]))
1182  || (*hasz && !ptarray_is_closed_3d(ppa[ring])))
1183  gml_lwpgerror("invalid GML representation", 43);
1184 
1185  if (srs.reverse_axis) ppa[ring] = ptarray_flip_coordinates(ppa[ring]);
1186  ring++;
1187  }
1188  }
1189 
1190  /* Exterior Ring is mandatory */
1191  if (ppa == NULL || ppa[0] == NULL) gml_lwpgerror("invalid GML representation", 44);
1192 
1193  if (srs.srid != *root_srid && *root_srid != SRID_UNKNOWN)
1194  {
1195  for (i=0 ; i < ring ; i++)
1196  gml_reproject_pa(ppa[i], srs.srid, *root_srid);
1197  }
1198  geom = (LWGEOM *) lwpoly_construct(*root_srid, NULL, ring, ppa);
1199 
1200  return geom;
1201 }
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
int ptarray_is_closed_2d(const POINTARRAY *pa)
Definition: ptarray.c:694
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:239
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
static xmlNodePtr get_xlink_node(xmlNodePtr xnode)
Return a xmlNodePtr on a node referenced by a XLink or NULL otherwise.
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 bool is_xlink(xmlNodePtr node)
Return true if current node contains a simple XLink Return false otherwise.
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
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:66
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: