PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ parse_gml_coordinates()

static POINTARRAY* parse_gml_coordinates ( xmlNodePtr  xnode,
bool *  hasz 
)
static

Parse gml:coordinates.

Definition at line 528 of file lwgeom_in_gml.c.

529 {
530  xmlChar *gml_coord, *gml_ts, *gml_cs, *gml_dec;
531  char cs, ts, dec;
532  POINTARRAY *dpa;
533  int gml_dims;
534  char *p, *q;
535  bool digit;
536  POINT4D pt;
537 
538  /* We begin to retrieve coordinates string */
539  gml_coord = xmlNodeGetContent(xnode);
540  p = (char *) gml_coord;
541 
542  /* Default GML coordinates pattern: x1,y1 x2,y2
543  * x1,y1,z1 x2,y2,z2
544  *
545  * Cf GML 2.1.2 -> 4.3.1 (p18)
546  */
547 
548  /* Retrieve separator between coordinates tuples */
549  gml_ts = gmlGetProp(xnode, (xmlChar *) "ts");
550  if (gml_ts == NULL) ts = ' ';
551  else
552  {
553  if (xmlStrlen(gml_ts) > 1 || isdigit(gml_ts[0]))
554  gml_lwpgerror("invalid GML representation", 15);
555  ts = gml_ts[0];
556  xmlFree(gml_ts);
557  }
558 
559  /* Retrieve separator between each coordinate */
560  gml_cs = gmlGetProp(xnode, (xmlChar *) "cs");
561  if (gml_cs == NULL) cs = ',';
562  else
563  {
564  if (xmlStrlen(gml_cs) > 1 || isdigit(gml_cs[0]))
565  gml_lwpgerror("invalid GML representation", 16);
566  cs = gml_cs[0];
567  xmlFree(gml_cs);
568  }
569 
570  /* Retrieve decimal separator */
571  gml_dec = gmlGetProp(xnode, (xmlChar *) "decimal");
572  if (gml_dec == NULL) dec = '.';
573  else
574  {
575  if (xmlStrlen(gml_dec) > 1 || isdigit(gml_dec[0]))
576  gml_lwpgerror("invalid GML representation", 17);
577  dec = gml_dec[0];
578  xmlFree(gml_dec);
579  }
580 
581  if (cs == ts || cs == dec || ts == dec)
582  gml_lwpgerror("invalid GML representation", 18);
583 
584  /* HasZ, !HasM, 1 Point */
585  dpa = ptarray_construct_empty(1, 0, 1);
586 
587  while (isspace(*p)) p++; /* Eat extra whitespaces if any */
588  for (q = p, gml_dims=0, digit = false ; *p ; p++)
589  {
590 
591  if (isdigit(*p)) digit = true; /* One state parser */
592 
593  /* Coordinate Separator */
594  if (*p == cs)
595  {
596  *p = '\0';
597  gml_dims++;
598 
599  if (*(p+1) == '\0') gml_lwpgerror("invalid GML representation", 19);
600 
601  if (gml_dims == 1) pt.x = parse_gml_double(q, false, true);
602  else if (gml_dims == 2) pt.y = parse_gml_double(q, false, true);
603 
604  q = p+1;
605 
606  /* Tuple Separator (or end string) */
607  }
608  else if (digit && (*p == ts || *(p+1) == '\0'))
609  {
610  if (*p == ts) *p = '\0';
611  gml_dims++;
612 
613  if (gml_dims < 2 || gml_dims > 3)
614  gml_lwpgerror("invalid GML representation", 20);
615 
616  if (gml_dims == 3)
617  pt.z = parse_gml_double(q, false, true);
618  else
619  {
620  pt.y = parse_gml_double(q, false, true);
621  *hasz = false;
622  }
623 
624  ptarray_append_point(dpa, &pt, LW_TRUE);
625  digit = false;
626 
627  q = p+1;
628  gml_dims = 0;
629 
630  /* Need to put standard decimal separator to atof handle */
631  }
632  else if (*p == dec && dec != '.') *p = '.';
633  }
634 
635  xmlFree(gml_coord);
636 
637  return dpa; /* ptarray_clone_deep(dpa); */
638 }
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int allow_duplicates)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE,...
Definition: ptarray.c:156
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
static double parse_gml_double(char *d, bool space_before, bool space_after)
Parse a string supposed to be a double.
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 void gml_lwpgerror(char *msg, __attribute__((__unused__)) int error_code)
Definition: lwgeom_in_gml.c:82
double x
Definition: liblwgeom.h:355
double z
Definition: liblwgeom.h:355
double y
Definition: liblwgeom.h:355

References gml_lwpgerror(), gmlGetProp(), LW_TRUE, parse_gml_double(), ptarray_append_point(), ptarray_construct_empty(), POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by parse_gml_data().

Here is the call graph for this function:
Here is the caller graph for this function: