PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ parse_gml_coordinates()

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

Parse gml:coordinates.

Definition at line 658 of file lwgeom_in_gml.c.

659 {
660  xmlChar *gml_coord, *gml_ts, *gml_cs, *gml_dec;
661  char cs, ts, dec;
662  POINTARRAY *dpa;
663  int gml_dims;
664  char *p, *q;
665  bool digit;
666  POINT4D pt = {0};
667 
668  /* We begin to retrieve coordinates string */
669  gml_coord = xmlNodeGetContent(xnode);
670  p = (char *) gml_coord;
671 
672  /* Default GML coordinates pattern: x1,y1 x2,y2
673  * x1,y1,z1 x2,y2,z2
674  *
675  * Cf GML 2.1.2 -> 4.3.1 (p18)
676  */
677 
678  /* Retrieve separator between coordinates tuples */
679  gml_ts = gmlGetProp(xnode, "ts");
680  if (gml_ts == NULL) ts = ' ';
681  else
682  {
683  if (xmlStrlen(gml_ts) > 1 || isdigit(gml_ts[0]))
684  gml_lwpgerror("invalid GML representation", 15);
685  ts = gml_ts[0];
686  xmlFree(gml_ts);
687  }
688 
689  /* Retrieve separator between each coordinate */
690  gml_cs = gmlGetProp(xnode, "cs");
691  if (gml_cs == NULL) cs = ',';
692  else
693  {
694  if (xmlStrlen(gml_cs) > 1 || isdigit(gml_cs[0]))
695  gml_lwpgerror("invalid GML representation", 16);
696  cs = gml_cs[0];
697  xmlFree(gml_cs);
698  }
699 
700  /* Retrieve decimal separator */
701  gml_dec = gmlGetProp(xnode, "decimal");
702  if (gml_dec == NULL) dec = '.';
703  else
704  {
705  if (xmlStrlen(gml_dec) > 1 || isdigit(gml_dec[0]))
706  gml_lwpgerror("invalid GML representation", 17);
707  dec = gml_dec[0];
708  xmlFree(gml_dec);
709  }
710 
711  if (cs == ts || cs == dec || ts == dec)
712  gml_lwpgerror("invalid GML representation", 18);
713 
714  /* HasZ, !HasM, 1 Point */
715  dpa = ptarray_construct_empty(1, 0, 1);
716 
717  while (isspace(*p)) p++; /* Eat extra whitespaces if any */
718  for (q = p, gml_dims=0, digit = false ; *p ; p++)
719  {
720 
721  if (isdigit(*p)) digit = true; /* One state parser */
722 
723  /* Coordinate Separator */
724  if (*p == cs)
725  {
726  *p = '\0';
727  gml_dims++;
728 
729  if (*(p+1) == '\0') gml_lwpgerror("invalid GML representation", 19);
730 
731  if (gml_dims == 1) pt.x = parse_gml_double(q, false, true);
732  else if (gml_dims == 2) pt.y = parse_gml_double(q, false, true);
733 
734  q = p+1;
735 
736  /* Tuple Separator (or end string) */
737  }
738  else if (digit && (*p == ts || *(p+1) == '\0'))
739  {
740  if (*p == ts) *p = '\0';
741  gml_dims++;
742 
743  if (gml_dims < 2 || gml_dims > 3)
744  gml_lwpgerror("invalid GML representation", 20);
745 
746  if (gml_dims == 3)
747  pt.z = parse_gml_double(q, false, true);
748  else
749  {
750  pt.y = parse_gml_double(q, false, true);
751  *hasz = false;
752  }
753 
754  ptarray_append_point(dpa, &pt, LW_TRUE);
755  digit = false;
756 
757  q = p+1;
758  gml_dims = 0;
759 
760  /* Need to put standard decimal separator to atof handle */
761  }
762  else if (*p == dec && dec != '.') *p = '.';
763  }
764 
765  xmlFree(gml_coord);
766 
767  return dpa; /* ptarray_clone_deep(dpa); */
768 }
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:107
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, const char *charProp)
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:428
double z
Definition: liblwgeom.h:428
double y
Definition: liblwgeom.h:428

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: