PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ parse_gml_coordinates()

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

Parse gml:coordinates.

Definition at line 521 of file lwgeom_in_gml.c.

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().

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