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

Parse gml:coordinates.

Definition at line 512 of file lwgeom_in_gml.c.

References gml_lwerror(), gmlGetProp(), LW_TRUE, parse_gml_double(), ptarray_append_point(), ptarray_construct_empty(), POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by parse_gml_data().

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

Here is the call graph for this function:

Here is the caller graph for this function: