PostGIS  2.4.9dev-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 994 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().

995 {
996  xmlNodePtr xa;
997  int lss, last, i;
998  bool found=false;
999  gmlSrs srs;
1000  LWGEOM *geom=NULL;
1001  POINTARRAY *pa=NULL;
1002  POINTARRAY **ppa=NULL;
1003  uint32 npoints=0;
1004  xmlChar *interpolation=NULL;
1005 
1006  if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
1007 
1008  /* Looking for gml:segments */
1009  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1010  {
1011  if (xa->type != XML_ELEMENT_NODE) continue;
1012  if (!is_gml_namespace(xa, false)) continue;
1013  if (!strcmp((char *) xa->name, "segments"))
1014  {
1015  found = true;
1016  break;
1017  }
1018  }
1019  if (!found) gml_lwpgerror("invalid GML representation", 37);
1020 
1021  ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
1022 
1023  /* Processing each gml:LineStringSegment */
1024  for (xa = xa->children, lss=0; xa != NULL ; xa = xa->next)
1025  {
1026  if (xa->type != XML_ELEMENT_NODE) continue;
1027  if (!is_gml_namespace(xa, false)) continue;
1028  if (strcmp((char *) xa->name, "LineStringSegment")) continue;
1029 
1030  /* GML SF is resticted to linear interpolation */
1031  interpolation = gmlGetProp(xa, (xmlChar *) "interpolation");
1032  if (interpolation != NULL)
1033  {
1034  if (strcmp((char *) interpolation, "linear"))
1035  gml_lwpgerror("invalid GML representation", 38);
1036  xmlFree(interpolation);
1037  }
1038 
1039  if (lss > 0) ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa,
1040  sizeof(POINTARRAY*) * (lss + 1));
1041 
1042  ppa[lss] = parse_gml_data(xa->children, hasz, root_srid);
1043  npoints += ppa[lss]->npoints;
1044  if (ppa[lss]->npoints < 2)
1045  gml_lwpgerror("invalid GML representation", 39);
1046  lss++;
1047  }
1048  if (lss == 0) gml_lwpgerror("invalid GML representation", 40);
1049 
1050  /* Most common case, a single segment */
1051  if (lss == 1) pa = ppa[0];
1052 
1053  /*
1054  * "The curve segments are connected to one another, with the end point
1055  * of each segment except the last being the start point of the next
1056  * segment" from ISO 19107:2003 -> 6.3.16.1 (p43)
1057  *
1058  * So we must aggregate all the segments into a single one and avoid
1059  * to copy the redundants points
1060  */
1061  if (lss > 1)
1062  {
1063  pa = ptarray_construct(1, 0, npoints - (lss - 1));
1064  for (last = npoints = i = 0; i < lss ; i++)
1065  {
1066  if (i + 1 == lss) last = 1;
1067  /* Check if segments are not disjoints */
1068  if (i > 0 && memcmp( getPoint_internal(pa, npoints),
1069  getPoint_internal(ppa[i], 0),
1070  *hasz ? sizeof(POINT3D) : sizeof(POINT2D)))
1071  gml_lwpgerror("invalid GML representation", 41);
1072 
1073  /* Aggregate stuff */
1074  memcpy( getPoint_internal(pa, npoints),
1075  getPoint_internal(ppa[i], 0),
1076  ptarray_point_size(ppa[i]) * (ppa[i]->npoints + last));
1077 
1078  npoints += ppa[i]->npoints - 1;
1079  lwfree(ppa[i]);
1080  }
1081  lwfree(ppa);
1082  }
1083 
1084  parse_gml_srs(xnode, &srs);
1085  if (srs.reverse_axis) pa = ptarray_flip_coordinates(pa);
1086  if (srs.srid != *root_srid && *root_srid != SRID_UNKNOWN)
1087  gml_reproject_pa(pa, srs.srid, *root_srid);
1088  geom = (LWGEOM *) lwline_construct(*root_srid, NULL, pa);
1089 
1090  return geom;
1091 }
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:244
int npoints
Definition: liblwgeom.h:371
static void gml_lwpgerror(char *msg, int error_code)
Definition: lwgeom_in_gml.c:81
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:42
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
uint8_t * getPoint_internal(const POINTARRAY *pa, int n)
Definition: ptarray.c:1753
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:237
void * lwalloc(size_t size)
Definition: lwutil.c:229
Here is the call graph for this function:
Here is the caller graph for this function: