PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ parse_gml_coordinates()

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

Parse gml:coordinates.

Definition at line 653 of file lwgeom_in_gml.c.

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

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: