PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ parse_gml_curve()

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

Parse GML Curve (3.1.1)

Definition at line 980 of file lwgeom_in_gml.c.

References get_xlink_node(), getPoint_internal(), gml_lwpgerror(), gml_reproject_pa(), gmlGetProp(), is_gml_namespace(), is_xlink(), lwalloc(), lwfree(), lwline_construct(), lwrealloc(), POINTARRAY::npoints, parse_gml_data(), parse_gml_srs(), ptarray_construct(), ptarray_flip_coordinates(), ptarray_point_size(), struct_gmlSrs::reverse_axis, struct_gmlSrs::srid, and SRID_UNKNOWN.

Referenced by parse_gml().

981 {
982  xmlNodePtr xa;
983  int lss, last, i;
984  bool found=false;
985  gmlSrs srs;
986  LWGEOM *geom=NULL;
987  POINTARRAY *pa=NULL;
988  POINTARRAY **ppa=NULL;
989  uint32 npoints=0;
990  xmlChar *interpolation=NULL;
991 
992  if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
993 
994  /* Looking for gml:segments */
995  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
996  {
997  if (xa->type != XML_ELEMENT_NODE) continue;
998  if (!is_gml_namespace(xa, false)) continue;
999  if (!strcmp((char *) xa->name, "segments"))
1000  {
1001  found = true;
1002  break;
1003  }
1004  }
1005  if (!found) gml_lwpgerror("invalid GML representation", 37);
1006 
1007  ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
1008 
1009  /* Processing each gml:LineStringSegment */
1010  for (xa = xa->children, lss=0; xa != NULL ; xa = xa->next)
1011  {
1012  if (xa->type != XML_ELEMENT_NODE) continue;
1013  if (!is_gml_namespace(xa, false)) continue;
1014  if (strcmp((char *) xa->name, "LineStringSegment")) continue;
1015 
1016  /* GML SF is resticted to linear interpolation */
1017  interpolation = gmlGetProp(xa, (xmlChar *) "interpolation");
1018  if (interpolation != NULL)
1019  {
1020  if (strcmp((char *) interpolation, "linear"))
1021  gml_lwpgerror("invalid GML representation", 38);
1022  xmlFree(interpolation);
1023  }
1024 
1025  if (lss > 0) ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa,
1026  sizeof(POINTARRAY*) * (lss + 1));
1027 
1028  ppa[lss] = parse_gml_data(xa->children, hasz, root_srid);
1029  npoints += ppa[lss]->npoints;
1030  if (ppa[lss]->npoints < 2)
1031  gml_lwpgerror("invalid GML representation", 39);
1032  lss++;
1033  }
1034  if (lss == 0) gml_lwpgerror("invalid GML representation", 40);
1035 
1036  /* Most common case, a single segment */
1037  if (lss == 1) pa = ppa[0];
1038 
1039  /*
1040  * "The curve segments are connected to one another, with the end point
1041  * of each segment except the last being the start point of the next
1042  * segment" from ISO 19107:2003 -> 6.3.16.1 (p43)
1043  *
1044  * So we must aggregate all the segments into a single one and avoid
1045  * to copy the redundants points
1046  */
1047  if (lss > 1)
1048  {
1049  pa = ptarray_construct(1, 0, npoints - (lss - 1));
1050  for (last = npoints = i = 0; i < lss ; i++)
1051  {
1052  if (i + 1 == lss) last = 1;
1053  /* Check if segments are not disjoints */
1054  if (i > 0 && memcmp( getPoint_internal(pa, npoints),
1055  getPoint_internal(ppa[i], 0),
1056  *hasz ? sizeof(POINT3D) : sizeof(POINT2D)))
1057  gml_lwpgerror("invalid GML representation", 41);
1058 
1059  /* Aggregate stuff */
1060  memcpy( getPoint_internal(pa, npoints),
1061  getPoint_internal(ppa[i], 0),
1062  ptarray_point_size(ppa[i]) * (ppa[i]->npoints + last));
1063 
1064  npoints += ppa[i]->npoints - 1;
1065  lwfree(ppa[i]);
1066  }
1067  lwfree(ppa);
1068  }
1069 
1070  parse_gml_srs(xnode, &srs);
1071  if (srs.reverse_axis) pa = ptarray_flip_coordinates(pa);
1072  if (srs.srid != *root_srid && *root_srid != SRID_UNKNOWN)
1073  gml_reproject_pa(pa, srs.srid, *root_srid);
1074  geom = (LWGEOM *) lwline_construct(*root_srid, NULL, pa);
1075 
1076  return geom;
1077 }
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
Definition: ptarray.c:62
void lwfree(void *mem)
Definition: lwutil.c:214
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.
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...
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.
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:29
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:172
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1706
int ptarray_point_size(const POINTARRAY *pa)
Definition: ptarray.c:54
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
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: