PostGIS  2.5.7dev-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 1001 of file lwgeom_in_gml.c.

1002 {
1003  xmlNodePtr xa;
1004  size_t lss;
1005  bool found=false;
1006  gmlSrs srs;
1007  LWGEOM *geom=NULL;
1008  POINTARRAY *pa=NULL;
1009  POINTARRAY **ppa=NULL;
1010  uint32 npoints=0;
1011  xmlChar *interpolation=NULL;
1012 
1013  if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
1014 
1015  /* Looking for gml:segments */
1016  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1017  {
1018  if (xa->type != XML_ELEMENT_NODE) continue;
1019  if (!is_gml_namespace(xa, false)) continue;
1020  if (!strcmp((char *) xa->name, "segments"))
1021  {
1022  found = true;
1023  break;
1024  }
1025  }
1026  if (!found) gml_lwpgerror("invalid GML representation", 37);
1027 
1028  ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
1029 
1030  /* Processing each gml:LineStringSegment */
1031  for (xa = xa->children, lss=0; xa != NULL ; xa = xa->next)
1032  {
1033  if (xa->type != XML_ELEMENT_NODE) continue;
1034  if (!is_gml_namespace(xa, false)) continue;
1035  if (strcmp((char *) xa->name, "LineStringSegment")) continue;
1036 
1037  /* GML SF is restricted to linear interpolation */
1038  interpolation = gmlGetProp(xa, (xmlChar *) "interpolation");
1039  if (interpolation != NULL)
1040  {
1041  if (strcmp((char *) interpolation, "linear"))
1042  gml_lwpgerror("invalid GML representation", 38);
1043  xmlFree(interpolation);
1044  }
1045 
1046  if (lss > 0) ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa,
1047  sizeof(POINTARRAY*) * (lss + 1));
1048 
1049  ppa[lss] = parse_gml_data(xa->children, hasz, root_srid);
1050  npoints += ppa[lss]->npoints;
1051  if (ppa[lss]->npoints < 2)
1052  gml_lwpgerror("invalid GML representation", 39);
1053  lss++;
1054  }
1055  if (lss == 0) gml_lwpgerror("invalid GML representation", 40);
1056 
1057  /* Most common case, a single segment */
1058  if (lss == 1) pa = ppa[0];
1059 
1060  if (lss > 1)
1061  {
1062  /*
1063  * "The curve segments are connected to one another, with the end point
1064  * of each segment except the last being the start point of the next
1065  * segment" from ISO 19107:2003 -> 6.3.16.1 (p43)
1066  *
1067  * So we must aggregate all the segments into a single one and avoid
1068  * to copy the redundant points
1069  */
1070  size_t i;
1071  size_t cp_point_size = sizeof(POINT3D); /* All internals are done with 3D */
1072  size_t final_point_size = *hasz ? sizeof(POINT3D) : sizeof(POINT2D);
1073  pa = ptarray_construct(1, 0, npoints - lss + 1);
1074 
1075  /* Copy the first linestring fully */
1076  memcpy(getPoint_internal(pa, 0), getPoint_internal(ppa[0], 0), cp_point_size * (ppa[0]->npoints));
1077  npoints = ppa[0]->npoints;
1078  lwfree(ppa[0]);
1079 
1080  /* For the rest of linestrings, ensure the first point matches the
1081  * last point of the previous one, and copy all points except the
1082  * first one (since it'd be repeated)
1083  */
1084  for (i = 1; i < lss; i++)
1085  {
1086  if (memcmp(getPoint_internal(pa, npoints - 1), getPoint_internal(ppa[i], 0), final_point_size))
1087  gml_lwpgerror("invalid GML representation", 41);
1088 
1089  memcpy(getPoint_internal(pa, npoints),
1090  getPoint_internal(ppa[i], 1),
1091  cp_point_size * (ppa[i]->npoints - 1));
1092 
1093  npoints += ppa[i]->npoints - 1;
1094  lwfree(ppa[i]);
1095  }
1096  }
1097 
1098  lwfree(ppa);
1099 
1100  parse_gml_srs(xnode, &srs);
1101  if (srs.reverse_axis) pa = ptarray_flip_coordinates(pa);
1102  if (srs.srid != *root_srid && *root_srid != SRID_UNKNOWN)
1103  gml_reproject_pa(pa, srs.srid, *root_srid);
1104  geom = (LWGEOM *) lwline_construct(*root_srid, NULL, pa);
1105 
1106  return geom;
1107 }
uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition: ptarray.c:1750
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 * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:237
void lwfree(void *mem)
Definition: lwutil.c:244
void * lwalloc(size_t size)
Definition: lwutil.c:229
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
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, int srid_in, int srid_out)
Use Proj4 to reproject a given POINTARRAY.
static xmlChar * gmlGetProp(xmlNodePtr xnode, xmlChar *prop)
Retrieve a GML property from a node or NULL otherwise Respect namespaces if presents in the node elem...
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:82
uint32_t npoints
Definition: liblwgeom.h:374

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(), 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: