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

Parse gml:pos.

Definition at line 692 of file lwgeom_in_gml.c.

References gml_lwpgerror(), gmlGetProp(), LW_FALSE, parse_gml_double(), ptarray_append_point(), ptarray_construct_empty(), POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by parse_gml_data().

693 {
694  xmlChar *dimension, *gmlpos;
695  int dim, gml_dim;
696  POINTARRAY *dpa;
697  char *pos, *p;
698  bool digit;
699  POINT4D pt;
700 
701  /* HasZ, !HasM, 1 Point */
702  dpa = ptarray_construct_empty(1, 0, 1);
703 
704  dimension = gmlGetProp(xnode, (xmlChar *) "srsDimension");
705  if (dimension == NULL) /* in GML 3.0.0 it was dimension */
706  dimension = gmlGetProp(xnode, (xmlChar *) "dimension");
707  if (dimension == NULL) dim = 2; /* We assume that we are in 2D */
708  else
709  {
710  dim = atoi((char *) dimension);
711  xmlFree(dimension);
712  if (dim < 2 || dim > 3)
713  gml_lwpgerror("invalid GML representation", 25);
714  }
715  if (dim == 2) *hasz = false;
716 
717  /* We retrieve gml:pos string */
718  gmlpos = xmlNodeGetContent(xnode);
719  pos = (char *) gmlpos;
720  while (isspace(*pos)) pos++; /* Eat extra whitespaces if any */
721 
722  /* gml:pos pattern: x1 y1
723  * x1 y1 z1
724  */
725  for (p=pos, gml_dim=0, digit=false ; *pos ; pos++)
726  {
727  if (isdigit(*pos)) digit = true;
728  if (digit && (*pos == ' ' || *(pos+1) == '\0'))
729  {
730  if (*pos == ' ') *pos = '\0';
731  gml_dim++;
732  if (gml_dim == 1)
733  pt.x = parse_gml_double(p, true, true);
734  else if (gml_dim == 2)
735  pt.y = parse_gml_double(p, true, true);
736  else if (gml_dim == 3)
737  pt.z = parse_gml_double(p, true, true);
738 
739  p = pos+1;
740  digit = false;
741  }
742  }
743  xmlFree(gmlpos);
744 
745  /* Test again coherent dimensions on each coord */
746  if (gml_dim == 2) *hasz = false;
747  if (gml_dim < 2 || gml_dim > 3 || gml_dim != dim)
748  gml_lwpgerror("invalid GML representation", 26);
749 
750  ptarray_append_point(dpa, &pt, LW_FALSE);
751 
752  return dpa; /* ptarray_clone_deep(dpa); */
753 }
double x
Definition: liblwgeom.h:351
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_FALSE
Definition: liblwgeom.h:76
double z
Definition: liblwgeom.h:351
double y
Definition: liblwgeom.h:351

Here is the call graph for this function:

Here is the caller graph for this function: