PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ parse_gml_triangle()

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

Parse GML Triangle (3.1.1)

Definition at line 1207 of file lwgeom_in_gml.c.

References get_xlink_node(), gml_lwpgerror(), gml_reproject_pa(), gmlGetProp(), is_gml_namespace(), is_xlink(), lwalloc(), lwtriangle_as_lwgeom(), lwtriangle_construct(), lwtriangle_construct_empty(), POINTARRAY::npoints, 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(), and parse_gml_tin().

1208 {
1209  gmlSrs srs;
1210  LWGEOM *geom;
1211  xmlNodePtr xa, xb;
1212  POINTARRAY *pa = NULL;
1213  xmlChar *interpolation=NULL;
1214 
1215  if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
1216 
1217  if (xnode->children == NULL)
1218  return lwtriangle_as_lwgeom(lwtriangle_construct_empty(*root_srid, 0, 0));
1219 
1220  /* GML SF is resticted to planar interpolation
1221  NOTA: I know Triangle is not part of SF, but
1222  we have to be consistent with other surfaces */
1223  interpolation = gmlGetProp(xnode, (xmlChar *) "interpolation");
1224  if (interpolation != NULL)
1225  {
1226  if (strcmp((char *) interpolation, "planar"))
1227  gml_lwpgerror("invalid GML representation", 45);
1228  xmlFree(interpolation);
1229  }
1230 
1231  parse_gml_srs(xnode, &srs);
1232 
1233  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1234  {
1235  /* Triangle/exterior */
1236  if (xa->type != XML_ELEMENT_NODE) continue;
1237  if (!is_gml_namespace(xa, false)) continue;
1238  if (strcmp((char *) xa->name, "exterior")) continue;
1239 
1240  for (xb = xa->children ; xb != NULL ; xb = xb->next)
1241  {
1242  /* Triangle/exterior/LinearRing */
1243  if (xb->type != XML_ELEMENT_NODE) continue;
1244  if (!is_gml_namespace(xb, false)) continue;
1245  if (strcmp((char *) xb->name, "LinearRing")) continue;
1246 
1247  pa = (POINTARRAY*) lwalloc(sizeof(POINTARRAY));
1248  pa = parse_gml_data(xb->children, hasz, root_srid);
1249 
1250  if (pa->npoints != 4
1251  || (!*hasz && !ptarray_is_closed_2d(pa))
1252  || (*hasz && !ptarray_is_closed_3d(pa)))
1253  gml_lwpgerror("invalid GML representation", 46);
1254 
1255  if (srs.reverse_axis) pa = ptarray_flip_coordinates(pa);
1256  }
1257  }
1258 
1259  /* Exterior Ring is mandatory */
1260  if (pa == NULL) gml_lwpgerror("invalid GML representation", 47);
1261 
1262  if (srs.srid != *root_srid && *root_srid != SRID_UNKNOWN)
1263  gml_reproject_pa(pa, srs.srid, *root_srid);
1264 
1265  geom = (LWGEOM *) lwtriangle_construct(*root_srid, NULL, pa);
1266 
1267  return geom;
1268 }
LWTRIANGLE * lwtriangle_construct_empty(int srid, char hasz, char hasm)
Definition: lwtriangle.c:45
int npoints
Definition: liblwgeom.h:355
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
static xmlNodePtr get_xlink_node(xmlNodePtr xnode)
Return a xmlNodePtr on a node referenced by a XLink or NULL otherwise.
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:172
LWGEOM * lwtriangle_as_lwgeom(const LWTRIANGLE *obj)
Definition: lwgeom.c:244
static bool is_xlink(xmlNodePtr node)
Return true if current node contains a simple XLink Return false otherwise.
LWTRIANGLE * lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwtriangle.c:27
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 * lwalloc(size_t size)
Definition: lwutil.c:199
Here is the call graph for this function:
Here is the caller graph for this function: