PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ parse_gml_coordinates()

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

Parse gml:coordinates.

Definition at line 574 of file lwgeom_in_gml.c.

575 {
576  xmlChar *gml_coord, *gml_ts, *gml_cs, *gml_dec;
577  char cs, ts, dec;
578  POINTARRAY *dpa;
579  int gml_dims;
580  char *p, *q;
581  bool digit;
582  POINT4D pt = {0};
583 
584  /* We begin to retrieve coordinates string */
585  gml_coord = xmlNodeGetContent(xnode);
586  p = (char *) gml_coord;
587 
588  /* Default GML coordinates pattern: x1,y1 x2,y2
589  * x1,y1,z1 x2,y2,z2
590  *
591  * Cf GML 2.1.2 -> 4.3.1 (p18)
592  */
593 
594  /* Retrieve separator between coordinates tuples */
595  gml_ts = gmlGetProp(xnode, (xmlChar *) "ts");
596  if (gml_ts == NULL) ts = ' ';
597  else
598  {
599  if (xmlStrlen(gml_ts) > 1 || isdigit(gml_ts[0]))
600  gml_lwpgerror("invalid GML representation", 15);
601  ts = gml_ts[0];
602  xmlFree(gml_ts);
603  }
604 
605  /* Retrieve separator between each coordinate */
606  gml_cs = gmlGetProp(xnode, (xmlChar *) "cs");
607  if (gml_cs == NULL) cs = ',';
608  else
609  {
610  if (xmlStrlen(gml_cs) > 1 || isdigit(gml_cs[0]))
611  gml_lwpgerror("invalid GML representation", 16);
612  cs = gml_cs[0];
613  xmlFree(gml_cs);
614  }
615 
616  /* Retrieve decimal separator */
617  gml_dec = gmlGetProp(xnode, (xmlChar *) "decimal");
618  if (gml_dec == NULL) dec = '.';
619  else
620  {
621  if (xmlStrlen(gml_dec) > 1 || isdigit(gml_dec[0]))
622  gml_lwpgerror("invalid GML representation", 17);
623  dec = gml_dec[0];
624  xmlFree(gml_dec);
625  }
626 
627  if (cs == ts || cs == dec || ts == dec)
628  gml_lwpgerror("invalid GML representation", 18);
629 
630  /* HasZ, !HasM, 1 Point */
631  dpa = ptarray_construct_empty(1, 0, 1);
632 
633  while (isspace(*p)) p++; /* Eat extra whitespaces if any */
634  for (q = p, gml_dims=0, digit = false ; *p ; p++)
635  {
636 
637  if (isdigit(*p)) digit = true; /* One state parser */
638 
639  /* Coordinate Separator */
640  if (*p == cs)
641  {
642  *p = '\0';
643  gml_dims++;
644 
645  if (*(p+1) == '\0') gml_lwpgerror("invalid GML representation", 19);
646 
647  if (gml_dims == 1) pt.x = parse_gml_double(q, false, true);
648  else if (gml_dims == 2) pt.y = parse_gml_double(q, false, true);
649 
650  q = p+1;
651 
652  /* Tuple Separator (or end string) */
653  }
654  else if (digit && (*p == ts || *(p+1) == '\0'))
655  {
656  if (*p == ts) *p = '\0';
657  gml_dims++;
658 
659  if (gml_dims < 2 || gml_dims > 3)
660  gml_lwpgerror("invalid GML representation", 20);
661 
662  if (gml_dims == 3)
663  pt.z = parse_gml_double(q, false, true);
664  else
665  {
666  pt.y = parse_gml_double(q, false, true);
667  *hasz = false;
668  }
669 
670  ptarray_append_point(dpa, &pt, LW_TRUE);
671  digit = false;
672 
673  q = p+1;
674  gml_dims = 0;
675 
676  /* Need to put standard decimal separator to atof handle */
677  }
678  else if (*p == dec && dec != '.') *p = '.';
679  }
680 
681  xmlFree(gml_coord);
682 
683  return dpa; /* ptarray_clone_deep(dpa); */
684 }
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:59
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:147
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
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:81
double x
Definition: liblwgeom.h:414
double z
Definition: liblwgeom.h:414
double y
Definition: liblwgeom.h:414

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: