PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ parse_gml_coordinates()

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

Parse gml:coordinates.

Definition at line 522 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().

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