PostGIS  3.3.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 1130 of file lwgeom_in_gml.c.

1131 {
1132  xmlNodePtr xa;
1133  size_t lss;
1134  bool found=false;
1135  gmlSrs srs;
1136  LWGEOM *geom=NULL;
1137  POINTARRAY *pa=NULL;
1138  POINTARRAY **ppa=NULL;
1139  uint32 npoints=0;
1140  xmlChar *interpolation=NULL;
1141 
1142  if (is_xlink(xnode)) xnode = get_xlink_node(xnode);
1143  if (xnode == NULL)
1144  gml_lwpgerror("invalid GML representation", 30);
1145 
1146  /* Looking for gml:segments */
1147  for (xa = xnode->children ; xa != NULL ; xa = xa->next)
1148  {
1149  if (xa->type != XML_ELEMENT_NODE) continue;
1150  if (!is_gml_namespace(xa, false)) continue;
1151  if (is_gml_element(xa, "segments"))
1152  {
1153  found = true;
1154  break;
1155  }
1156  }
1157  if (!found) gml_lwpgerror("invalid GML representation", 37);
1158 
1159  ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
1160 
1161  /* Processing each gml:LineStringSegment */
1162  for (xa = xa->children, lss=0; xa != NULL ; xa = xa->next)
1163  {
1164  if (xa->type != XML_ELEMENT_NODE) continue;
1165  if (!is_gml_namespace(xa, false)) continue;
1166 
1167  if (!is_gml_element(xa, "LineStringSegment")) continue;
1168 
1169  /* GML SF is restricted to linear interpolation */
1170  interpolation = gmlGetProp(xa, "interpolation");
1171  if (interpolation != NULL)
1172  {
1173  if (strcmp((char *) interpolation, "linear"))
1174  gml_lwpgerror("invalid GML representation", 38);
1175  xmlFree(interpolation);
1176  }
1177 
1178  if (lss > 0) ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa,
1179  sizeof(POINTARRAY*) * (lss + 1));
1180 
1181  ppa[lss] = parse_gml_data(xa->children, hasz, root_srid);
1182  npoints += ppa[lss]->npoints;
1183  if (ppa[lss]->npoints < 2)
1184  gml_lwpgerror("invalid GML representation", 39);
1185  lss++;
1186  }
1187  if (lss == 0) gml_lwpgerror("invalid GML representation", 40);
1188 
1189  /* Most common case, a single segment */
1190  if (lss == 1) pa = ppa[0];
1191 
1192  if (lss > 1)
1193  {
1194  /*
1195  * "The curve segments are connected to one another, with the end point
1196  * of each segment except the last being the start point of the next
1197  * segment" from ISO 19107:2003 -> 6.3.16.1 (p43)
1198  *
1199  * So we must aggregate all the segments into a single one and avoid
1200  * to copy the redundant points
1201  */
1202  size_t cp_point_size = sizeof(POINT3D); /* All internals are done with 3D */
1203  size_t final_point_size = *hasz ? sizeof(POINT3D) : sizeof(POINT2D);
1204  pa = ptarray_construct(1, 0, npoints - lss + 1);
1205 
1206  /* Copy the first linestring fully */
1207  memcpy(getPoint_internal(pa, 0), getPoint_internal(ppa[0], 0), cp_point_size * (ppa[0]->npoints));
1208  npoints = ppa[0]->npoints;
1209  lwfree(ppa[0]);
1210 
1211  /* For the rest of linestrings, ensure the first point matches the
1212  * last point of the previous one, and copy all points except the
1213  * first one (since it'd be repeated)
1214  */
1215  for (size_t i = 1; i < lss; i++)
1216  {
1217  if (memcmp(getPoint_internal(pa, npoints - 1), getPoint_internal(ppa[i], 0), final_point_size))
1218  gml_lwpgerror("invalid GML representation", 41);
1219 
1220  memcpy(getPoint_internal(pa, npoints),
1221  getPoint_internal(ppa[i], 1),
1222  cp_point_size * (ppa[i]->npoints - 1));
1223 
1224  npoints += ppa[i]->npoints - 1;
1225  lwfree(ppa[i]);
1226  }
1227  }
1228 
1229  lwfree(ppa);
1230 
1231  parse_gml_srs(xnode, &srs);
1232  if (srs.reverse_axis) pa = ptarray_flip_coordinates(pa);
1233  if (srs.srid != *root_srid && *root_srid != SRID_UNKNOWN)
1234  gml_reproject_pa(pa, srs.srid, *root_srid);
1235  geom = (LWGEOM *) lwline_construct(*root_srid, NULL, pa);
1236 
1237  return geom;
1238 }
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:51
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:235
void lwfree(void *mem)
Definition: lwutil.c:242
void * lwalloc(size_t size)
Definition: lwutil.c:227
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:230
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, int32_t epsg_in, int32_t epsg_out)
Use Proj to reproject a given POINTARRAY.
static xmlChar * gmlGetProp(xmlNodePtr xnode, const char *charProp)
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:81
static bool is_gml_element(xmlNodePtr xn, const char *gml_name)
static uint8_t * getPoint_internal(const POINTARRAY *pa, uint32_t n)
Definition: lwinline.h:77
uint32_t npoints
Definition: liblwgeom.h:442

References get_xlink_node(), getPoint_internal(), gml_lwpgerror(), gml_reproject_pa(), gmlGetProp(), is_gml_element(), 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: