PostGIS  2.5.0dev-r@@SVN_REVISION@@
static LWGEOM* parse_gml_curve ( xmlNodePtr  xnode,
bool *  hasz,
int *  root_srid 
)
static

Parse GML Curve (3.1.1)

Definition at line 993 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().

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

Here is the call graph for this function:

Here is the caller graph for this function: