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

Parse gml:pos.

Definition at line 679 of file lwgeom_in_gml.c.

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

Referenced by parse_gml_data().

680 {
681  xmlChar *dimension, *gmlpos;
682  int dim, gml_dim;
683  POINTARRAY *dpa;
684  char *pos, *p;
685  bool digit;
686  POINT4D pt;
687 
688  /* HasZ, !HasM, 1 Point */
689  dpa = ptarray_construct_empty(1, 0, 1);
690 
691  dimension = gmlGetProp(xnode, (xmlChar *) "srsDimension");
692  if (dimension == NULL) /* in GML 3.0.0 it was dimension */
693  dimension = gmlGetProp(xnode, (xmlChar *) "dimension");
694  if (dimension == NULL) dim = 2; /* We assume that we are in 2D */
695  else
696  {
697  dim = atoi((char *) dimension);
698  xmlFree(dimension);
699  if (dim < 2 || dim > 3)
700  gml_lwpgerror("invalid GML representation", 25);
701  }
702  if (dim == 2) *hasz = false;
703 
704  /* We retrieve gml:pos string */
705  gmlpos = xmlNodeGetContent(xnode);
706  pos = (char *) gmlpos;
707  while (isspace(*pos)) pos++; /* Eat extra whitespaces if any */
708 
709  /* gml:pos pattern: x1 y1
710  * x1 y1 z1
711  */
712  for (p=pos, gml_dim=0, digit=false ; *pos ; pos++)
713  {
714  if (isdigit(*pos)) digit = true;
715  if (digit && (*pos == ' ' || *(pos+1) == '\0'))
716  {
717  if (*pos == ' ') *pos = '\0';
718  gml_dim++;
719  if (gml_dim == 1)
720  pt.x = parse_gml_double(p, true, true);
721  else if (gml_dim == 2)
722  pt.y = parse_gml_double(p, true, true);
723  else if (gml_dim == 3)
724  pt.z = parse_gml_double(p, true, true);
725 
726  p = pos+1;
727  digit = false;
728  }
729  }
730  xmlFree(gmlpos);
731 
732  /* Test again coherent dimensions on each coord */
733  if (gml_dim == 2) *hasz = false;
734  if (gml_dim < 2 || gml_dim > 3 || gml_dim != dim)
735  gml_lwpgerror("invalid GML representation", 26);
736 
737  ptarray_append_point(dpa, &pt, LW_FALSE);
738 
739  return ptarray_clone_deep(dpa);
740 }
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_FALSE
Definition: liblwgeom.h:62
POINTARRAY * ptarray_clone_deep(const POINTARRAY *ptarray)
Deep clone a pointarray (also clones serialized pointlist)
Definition: ptarray.c:634
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: