PostGIS  2.2.7dev-r@@SVN_REVISION@@
static POINTARRAY* parse_gml_coordinates ( xmlNodePtr  xnode,
bool *  hasz 
)
static

Parse gml:coordinates.

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

508 {
509  xmlChar *gml_coord, *gml_ts, *gml_cs, *gml_dec;
510  char cs, ts, dec;
511  POINTARRAY *dpa;
512  int gml_dims;
513  char *p, *q;
514  bool digit;
515  POINT4D pt;
516 
517  /* We begin to retrieve coordinates string */
518  gml_coord = xmlNodeGetContent(xnode);
519  p = (char *) gml_coord;
520 
521  /* Default GML coordinates pattern: x1,y1 x2,y2
522  * x1,y1,z1 x2,y2,z2
523  *
524  * Cf GML 2.1.2 -> 4.3.1 (p18)
525  */
526 
527  /* Retrieve separator between coordinates tuples */
528  gml_ts = gmlGetProp(xnode, (xmlChar *) "ts");
529  if (gml_ts == NULL) ts = ' ';
530  else
531  {
532  if (xmlStrlen(gml_ts) > 1 || isdigit(gml_ts[0]))
533  gml_lwpgerror("invalid GML representation", 15);
534  ts = gml_ts[0];
535  xmlFree(gml_ts);
536  }
537 
538  /* Retrieve separator between each coordinate */
539  gml_cs = gmlGetProp(xnode, (xmlChar *) "cs");
540  if (gml_cs == NULL) cs = ',';
541  else
542  {
543  if (xmlStrlen(gml_cs) > 1 || isdigit(gml_cs[0]))
544  gml_lwpgerror("invalid GML representation", 16);
545  cs = gml_cs[0];
546  xmlFree(gml_cs);
547  }
548 
549  /* Retrieve decimal separator */
550  gml_dec = gmlGetProp(xnode, (xmlChar *) "decimal");
551  if (gml_dec == NULL) dec = '.';
552  else
553  {
554  if (xmlStrlen(gml_dec) > 1 || isdigit(gml_dec[0]))
555  gml_lwpgerror("invalid GML representation", 17);
556  dec = gml_dec[0];
557  xmlFree(gml_dec);
558  }
559 
560  if (cs == ts || cs == dec || ts == dec)
561  gml_lwpgerror("invalid GML representation", 18);
562 
563  /* HasZ, !HasM, 1 Point */
564  dpa = ptarray_construct_empty(1, 0, 1);
565 
566  while (isspace(*p)) p++; /* Eat extra whitespaces if any */
567  for (q = p, gml_dims=0, digit = false ; *p ; p++)
568  {
569 
570  if (isdigit(*p)) digit = true; /* One state parser */
571 
572  /* Coordinate Separator */
573  if (*p == cs)
574  {
575  *p = '\0';
576  gml_dims++;
577 
578  if (*(p+1) == '\0') gml_lwpgerror("invalid GML representation", 19);
579 
580  if (gml_dims == 1) pt.x = parse_gml_double(q, false, true);
581  else if (gml_dims == 2) pt.y = parse_gml_double(q, false, true);
582 
583  q = p+1;
584 
585  /* Tuple Separator (or end string) */
586  }
587  else if (digit && (*p == ts || *(p+1) == '\0'))
588  {
589  if (*p == ts) *p = '\0';
590  gml_dims++;
591 
592  if (gml_dims < 2 || gml_dims > 3)
593  gml_lwpgerror("invalid GML representation", 20);
594 
595  if (gml_dims == 3)
596  pt.z = parse_gml_double(q, false, true);
597  else
598  {
599  pt.y = parse_gml_double(q, false, true);
600  *hasz = false;
601  }
602 
603  ptarray_append_point(dpa, &pt, LW_TRUE);
604  digit = false;
605 
606  q = p+1;
607  gml_dims = 0;
608 
609  /* Need to put standard decimal separator to atof handle */
610  }
611  else if (*p == dec && dec != '.') *p = '.';
612  }
613 
614  xmlFree(gml_coord);
615 
616  return dpa; /* ptarray_clone_deep(dpa); */
617 }
double x
Definition: liblwgeom.h:336
static void gml_lwpgerror(char *msg, int error_code)
Definition: lwgeom_in_gml.c:67
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_TRUE, 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:61
double z
Definition: liblwgeom.h:336
double y
Definition: liblwgeom.h:336

Here is the call graph for this function:

Here is the caller graph for this function: